Data augmentation

These layers perform random transformations over the previous layer.

RandomCrop

layer eddl::RandomCrop(layer parent, vector<int> new_shape, string name = "")

Crop the given image at a random location with size [height, width].

Parameters
  • parent – Parent layer

  • new_shape – Vector (height, width) size

  • name – A name for the operation

Returns

Output of random crop transformation

Example:

l = RandomCrop(l, {20, 20});

RandomCropScale

layer eddl::RandomCropScale(layer parent, vector<float> factor, string da_mode = "nearest", string name = "")

Crop the given image randomly by the size in a range [a, b] by and scale it to the parent size.

Parameters
  • parent – Parent layer

  • factor – Factor Range for random crop

  • da_mode – One of “nearest”, “constant”, (ToDo: “mirror”, “reflect”, “wrap”, “original”)

  • name – A name for the operation

Returns

Output of random crop scale transformation

Example:

l = RandomCropScale(l, {0.9f, 1.0f});

RandomCutout

layer eddl::RandomCutout(layer parent, vector<float> factor_x, vector<float> factor_y, float constant = 0.0f, string name = "")

Randomly selects a rectangle region in an image and erases its pixels. The random region is defined by the range [(min_x, max_x), (min_y, max_y)], where these are relative values.

Parameters
  • parent – Parent layer

  • factor_x – Vector of factor fraction for horizontal size

  • factor_y – Vector of factor fraction for vertical size

  • constant – Erasing value

  • name – A name for the operation

Returns

Output of random cutout transformation

Example:

// The values of x_min, x_max, y_min and y_max should be between 0.0 and 1.0
l = RandomCutout(l, {0.3, 0.7},{0.3,0.9});

RandomFlip

layer eddl::RandomFlip(layer parent, int axis, string name = "")

Flip the given image at axis=n randomly with a given probability.

Parameters
  • parent – Parent layer

  • axis – Flip axis

  • name – A name for the operation

Returns

Output of random flip transformation

Example:

l = RandomFlip(l, 0);

RandomHorizontalFlip

layer eddl::RandomHorizontalFlip(layer parent, string name = "")

Horizontally flip the given image randomly with a given probability.

Parameters
  • parent – Parent layer

  • name – A name for the operation

Returns

Output of random horizontal flip transformation

Example:

l = RandomHorizontalFlip(l);

RandomRotation

layer eddl::RandomRotation(layer parent, vector<float> factor, vector<int> offset_center = {0, 0}, string da_mode = "original", float constant = 0.0f, string name = "")

Rotate the image randomly by an angle defined in a range [a, b].

Parameters
  • parent – Parent layer

  • factor – Range In degrees counter clockwise order

  • offset_center – Optional center of rotation. Default is the center of the image

  • da_mode – One of “original”

  • constant – Fill value for area outside the rotated image, it is used for all channels respectively.

Returns

Output of rotate transformation

Example:

l = RandomRotation(l, {-20,30});

RandomScale

layer eddl::RandomScale(layer parent, vector<float> factor, string da_mode = "nearest", float constant = 0.0f, string coordinate_transformation_mode = "asymmetric", string name = "")

Resize the input image randomly by the size in a range [a, b].

Parameters
  • parent – Parent layer

  • factor – Vector of factor size range new shape

  • da_mode – One of “nearest”

  • constant – Fill value for area outside the resized image, it is used for all channels respectively.

  • coordinate_transformation_mode – This attribute describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor.

Returns

Output of scale transformation

Example:

l = RandomScale(l, {0.9,1.1});

RandomShift

layer eddl::RandomShift(layer parent, vector<float> factor_x, vector<float> factor_y, string da_mode = "nearest", float constant = 0.0f, string name = "")

Shift the input image randomly in range [a, b].

Parameters
  • parent – Parent layer

  • factor_x – Vector of factor fraction for horizontal translations

  • factor_y – Vector of factor fraction for vertical translations

  • da_mode – One of “nearest”, “constant”, (ToDo: “mirror”, “reflect”, “wrap”, “original”)

  • constant – Fill value for area outside the resized image, it is used for all channels respectively.

Returns

Output of scale transformation

Example:

// The shift factors must fall within the range [-1.0, 1.0]
l = RandomShift(l, {-0.3,0.3},{-0.2, 0.2});

RandomVerticalFlip

layer eddl::RandomVerticalFlip(layer parent, string name = "")

Vertically flip the given image randomly with a given probability.

Parameters
  • parent – Parent layer

  • name – A name for the operation

Returns

Output of random vertical flip transformation

Example:

l = RandomVerticalFlip(l);