Image augmentation

When training deep networks to classify images, you can sometimes get a significant increase in validation accuracy if you augment the data. This means that you randomly transform the images in certain ways, for example, varying lighting, coloring, flipping and zooming.

Image augmentation examples
Figure 1. Image augmentation examples

Image augmentation adds more variation to the training dataset and if it is done right, reflects the variation in the real data and therefore helps the model to generalize better.

Image augmentation is helpful for both large and small datasets.

Note
Image augmentation only works on images and image-like data. It is mostly useful for images but may be interesting to use on any 3 axis tensor for advanced users.

Image augmentation settings

In the drop-down select one of the following:

  • Natural images. This randomly changes each image to mimic how natural images look. Often real images aren’t centered and a little bit rotated. By mimicking this we will get better predictions. For example, if you reflect or rotate an image of a car you get another image of a car.

  • Custom. Set your own custom values. Some datasets do not consist of natural images, e.g., MNIST. All available image augmentation options should not be used then. For example, it does not make sense to reflect a “3”, since then it’s not a “3” anymore. If you, however, rotate it an image of a “3” it’s still a “3”.

  • No. Well no image augmentation.

Settings

Note
When you set a value to an image augmentation parameter all samples are uniformly sampled between positive and negative of the set value. For example, if you set “Randomly rotate” to 30 all values of rotation in the span -30 – +30 are uniformly probable.

Rotate

Randomly rotate up to this many degrees in any direction.

Natural images default: 30

Rotate
Figure 2. Rotate

Shift height

Randomly shift height up to this proportion.

Natural images default: 0.1

Shift height
Figure 3. Shift height

Shift width

Randomly shift width up to this proportion.

Natural images default: 0.1

Shift width
Figure 4. Shift width

Shear

Randomly shear up to this angle.

Natural images default: 0

Shear
Figure 5. Shear

Zoom

Randomly zoom up to this proportion.

Natural images default: 0.2

Zoom
Figure 6. Zoom

Flip horizontally

Randomly flip vertically.

Natural images default: No

When enabled (Yes) this option will randomly flip images on reading them with a 50% probability.

Flip horizontally
Figure 7. Flip horizontally

Flip vertically

Randomly flip horizontally.

Natural images default: Yes

When enabled (Yes) this option will randomly flip images on reading them with a 50% probability.

Flip vertically
Figure 8. Flip vertically

Advanced options

Some transformations introduce new pixels from outside of the bounds of the original image. For example, after a rotation there would be new areas in the image (in black below) which weren’t included in the original image. The way we handle these areas are specified by the Fill mode for pixels outside the image.

Constant values

Constant values - all new pixels (and subpixels if the input is a color image) are given the constant value specified.

Default is 0 which corresponds to setting all new pixels to black. This is the most common and recommended value. Similarly setting the constant value to 1 will be equivalent to filling these areas with white.

Constant values
Figure 9. Constant values

Note that if the images are standardized the mean value will be shifted to 0, whereby filling with zeroes will correspond to this value, which most likely will mean grey-filling these areas. To fill with true black you may therefore set this value to the value of "- <mean> / <standard deviation>" . These values may be retrieved from the Datasets view.

Nearest neighbor

Nearest neighbor — Adds the value of the nearest pixel of the original image. This will result in lines in the augmented image.

Nearest neighbor
Figure 10. Nearest neighbor

Reflect values

Reflect values — Mirrors the original image to the new pixels.

Reflect values
Figure 11. Reflect values

Wrap values

Wrap values — The original image repeats in the new pixels.

Wrap values
Figure 12. Wrap values

How to augment images in a dataset

  1. Select the Input block.

  2. In the Parameters section select Image augmentation.

  3. Select either of:

    • Natural images. This randomly changes each images to mimic how natural images look.

    • Custom. Set your own custom values.

Try the platform