Updated on 2023-09-06 GMT+08:00

Data Augmentation (Data Amplification)

Overview of Data Amplification Operators

Data amplification is mainly used in scenarios where the training dataset is insufficient or simulation is required. You can transform the labeled dataset to increase the number of images trained and generate corresponding labels. In the deep learning field, augmentation is of great significance. It can improve model generalization and enhance anti-disturbance. Original data is not changed during data amplification. The newly amplified image or XML file is saved in the specified output path.

ModelArts provides the following data amplification operators:

Table 1 Description of data amplification operators

Operator

Description

Advanced

AddNoise

Adds noises to simulate the noises that may be generated when common capture devices capture images.

  • noise_type: noise distribution type. Gauss indicates Gaussian noise. Laplace indicates Laplace noise. Poisson indicates Poisson noise. Impulse indicates impulse noise. SaltAndPepper indicates salt and pepper noise. The default value is Gauss.
  • loc: average noise distribution. This parameter is valid only in Gauss and Laplace. The default value is 0.
  • scale: standard deviation of noise distribution. This parameter is valid only in Gauss and Laplace. The default value is 1.
  • lam: lambda coefficient of Poisson distribution. This parameter is valid only for Poisson. The default value is 2.
  • p: probability of pulse noise or salt-and-pepper noise for each pixel. This parameter is valid only for Impulse and SaltAndPepper. The default value is 0.01.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Blur

Uses filters to filter images and sometimes to simulate imaging of imaging devices.

  • blur_type: The value can be Gauss or Average, which indicates Gaussian filtering and average filtering, respectively. The default value is Gauss.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Crop

Randomly crops a part of an image as a new image.

  • crop_percent_min: minimum value in the value range of the cropping ratio of each edge. The default value is 0.0.
  • crop_percent_max: maximum value in the value range of the cropping ratio of each edge. The default value is 0.2.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

CutOut

Random erase, which is a common method used in deep learning to simulate an object that is blocked by an obstacle.

do_validation: indicates whether to validate data before data amplification. The default value is True.

Flip

Flips along the horizontal or vertical axis of an image, which is a very common enhancement method.

  • lr_ud: flipping direction. lr indicates horizontal flipping, and ud indicates vertical flipping. The default value is lr.
  • flip_p: flipping probability. The default value is 1.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Grayscale

Changes a three-channel color image to a three-channel grayscale image.

do_validation: indicates whether to validate data before data amplification. The default value is True.

HistogramEqual

Indicates the histogram equalization, which is mainly used to improve the visual effect of images. It is used in some scenarios.

do_validation: indicates whether to validate data before data amplification. The default value is True.

LightArithmetic

Implements linear enhancement on luminance space.

do_validation: indicates whether to validate data before data amplification. The default value is True.

LightContrast

Enhances luminance contrast. A certain non-linear function is used to change the luminance value of the luminance space.

func: The default value is gamma.

  • gamma: Gamma correction. Its formula is 255*((v/255)**gamma)').
  • sigmoid: S-shaped curve function. Its formula is 255*1/(1+exp(gain*(cutoff-I_ij/255)))').
  • log: logarithmic function. Its formula is 255*gain*log_2(1+v/255).
  • linear: linear function. Its formula is 127 + alpha*(v-127)').

do_validation: indicates whether to validate data before data amplification. The default value is True.

MotionBlur

Indicates the motion blur generated when an object moves.

do_validation: indicates whether to validate data before data amplification. The default value is True.

Padding

Pads an image with black edges.

  • px_top: number of pixel lines added at the top of the image. The default value is 1.
  • px_right: number of pixel lines added at the right of the image. The default value is 1.
  • px_left: number of pixel lines added at the left of the image. The default value is 1.
  • px_bottom: number of pixel lines added at the bottom of the image. The default value is 1.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Resize

Resizes an image.

  • height: height of the image after conversion. The default value is 224.
  • width: width of the image after conversion. The default value is 224.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Rotate

Rotates an image around the center point. After the operation is complete, the original shape of the image remains unchanged, and the blank part is filled with black.

  • angle_min: minimum value in the range of rotation angles. Each image randomly obtains a value from the range. The default value is 90°.
  • angle_max: maximum value in the range of rotation angles. Each image randomly obtains a value from the range. The default value is -90°.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Saturation

Enhances chrominance and saturation. The H and S spaces in the HSV of an image are changed linearly to change the chrominance and saturation of the image.

do_validation: indicates whether to validate data before data amplification. The default value is True.

Scale

Zooms in or out an image. The length or width of an image is randomly zoomed in or out.

  • scaleXY: scaling direction. X indicates horizontal, and Y indicates vertical. The default value is X.
  • scale_min: lower limit of the random scaling ratio range. The default value is 0.5.
  • scale_min: upper limit of the random scaling ratio range. The default value is 1.5.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Sharpen

Indicates image sharpening, which is used to sharpen the edges of objects.

do_validation: indicates whether to validate data before data amplification. The default value is True.

Shear

Indicates image shearing, which is used for geometric transformation of images. Pixels are mapped using linear functions.

  • shearXY: shearing direction. X indicates horizontal, and Y indicates vertical. The default value is X.
  • shear_min: lower limit of the random shearing angle range. The default value is -30.
  • shear_max: upper limit of the random shearing angle range. The default value is 30.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Translate

Moves an image along the x-axis or y-axis, discards the part that exceeds the original image, and fills the blank part with black.

  • translateXY: translation direction. X indicates horizontal, and Y indicates vertical. The default value is X.
  • do_validation: indicates whether to validate data before data amplification. The default value is True.

Weather

Adds weather information to simulate the weather effect.

weather_mode: weather mode. The default value is Rain.

  • Rain: rain
  • Fog: fog
  • Snow: snow
  • Clouds: cloud

do_validation: indicates whether to validate data before data amplification. The default value is True.

Operator Input Requirements

The following two types of operator input are available:

  • Datasets: Select a dataset and its version created on the ModelArts console from the drop-down list. Ensure that the dataset type be the same as the scenario type selected in this task.
  • OBS Catalog: The storage structure supports Images and labels.

    Images and labels: The structure varies depending on the scenario type.

    The following shows the directory structure in the image classification scenario. The following directory structure supports only single-label scenarios.

    input_path/
        --label1/
            ----1.jpg
        --label2/
            ----2.jpg
        --../

    The following shows the directory structure in the object detection scenario. Images in JPG, JPEG, PNG, and BMP formats are supported. XML files are standard PACAL VOC files.

    input_path/
        --1.jpg
        --1.xml
        --2.jpg
        --2.xml
        ...

Output Description

Some data will be discarded due to some operations of the operators. Therefore, the output folder may not contain the full dataset. For example, Rotate will discard the images whose bounding boxes exceed the image boundaries.

The following shows the output directory structure. In this structure, the Data folder stores newly generated images and labeling information. The manifest file stores the structure of images in the folder and can be directly imported to the dataset in Data Management.

|----data_url
    |----Data
        |----xxx.jpg
        |----xxx.xml(xxx.txt)
    |----output.manifest

A manifest file example is as follows:

{
	"id": "xss",
	"source": "obs://home/fc8e2688015d4a1784dcbda44d840307_14.jpg",
	"usage": "train", 
	"annotation": [
		{
			"name": "Cat", 
			"type": "modelarts/image_classification"
		}
	]
}