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, shearing, flipping and zooming.

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.

Image augmentation examples
Figure 1. Image augmentation examples
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

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”.

  • None. 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

Vertical shift

Randomly shift the image vertically up to this proportion. Natural images default: 0.1

Vertical shift
Figure 3. Vertical shift

Horizontal shift

Randomly shift the image horizontally up to this proportion.

Natural images default: 0.1

Horizontal shift
Figure 4. Horizontal shift

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

Horizontal flip

Randomly flip horizontally.

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

Natural images default: Yes

Horizontal flip
Figure 7. Horizontal flip

Vertical flip

Randomly flip vertically.

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

Natural images default: No

Vertical flip
Figure 8. Vertical flip

Fill mode

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.

Constant values

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

Cval default: 0.
0 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

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.

Get started for free