How it works...

In step 1, if we don't need a random flip but a specified mode of flip (deterministic), then we can do the following:

int flipMode = 0;
ImageTransform flipTransform = new FlipImageTransform(flipMode);

flipMode is the deterministic flip mode. 

  • flipMode = 0: Flips around the x axis
  • flipMode > 0: Flips around the y axis
  • flipMode < 0: Flips around both axes

In step 2, we passed in two attributes: Random(seed) and delta. delta is the magnitude in which an image is warped. Check the following image sample for the demonstration of image warping:

(Image source: https://commons.wikimedia.org/wiki/File:Image_warping_example.jpg
License: CC BY-SA 3.0)

WarpImageTransform(new Random(seed),delta) internally calls the following constructor:

public WarpImageTransform(java.util.Random random,
float dx1,
float dy1,
float dx2,
float dy2,
float dx3,
float dy3,
float dx4,
float dy4

It will assume dx1=dy1=dx2=dy2=dx3=dy3=dx4=dy4=delta.

Here are the parameter descriptions:

  • dx1: Maximum warping in x for the top-left corner (pixels)
  • dy1: Maximum warping in y for the top-left corner (pixels)
  • dx2: Maximum warping in x for the top-right corner (pixels)
  • dy2: Maximum warping in y for the top-right corner (pixels)
  • dx3: Maximum warping in x for the bottom-right corner (pixels)
  • dy3: Maximum warping in y for the bottom-right corner (pixels)
  • dx4: Maximum warping in x for the bottom-left corner (pixels)
  • dy4: Maximum warping in y for the bottom-left corner (pixels)

The value of delta will be auto adjusted as per the normalized width/height while creating ImageRecordReader. This means that the given value of delta will be treated relative to the normalized width/height specified while creating ImageRecordReader. So, let's say we perform 10 pixels of warping across the x/y axis in an image with a size of 100 x 100. If the image is normalized to a size of 30 x 30, then 3 pixels of warping will happen across the x/y axis. You need to experiment with different values for delta since there's no constant/min/max delta value that can solve all types of image classification problems.

In step 3, we used RotateImageTransform to perform rotational image transformations by rotating the image samples on the angle mentioned.

In step 4, we added multiple image transformations with the help of PipelineImageTransform into a pipeline to load them sequentially or randomly for training purposes. We have created a pipeline with the List<Pair<ImageTransform,Double>> type. The Double value in Pair is the probability that the particular element (ImageTransform) in the pipeline is executed.

Image transformations will help CNN to learn image patterns better. Training on top of transformed images will further avoid the chances of overfitting. 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset