Question: These transformations are known as geographical transformations or geographic transformations. The broader process of modifying the original data set to avoid overfitting is called image
These transformations are known as geographical transformations or geographic transformations. The broader process of modifying the original data set to avoid overfitting is called image augmentation.
The tool that we will use for image preprocessing is called the ImageDataGenerator class, which we imported earlier in this lab.
This function is capable of applying a number of different transformations. The transformations and their definitions from the keras documentation are shown below:
zoomrange: Float or lower upper Range for random zoom. If a float, lower upperzoomrange, zoomrange
horizontalflip: Boolean. Randomly flip inputs horizontally.
shearrange: Float. Shear Intensity Shear angle in counterclockwise direction in degrees
The only other argument that the ImageDataGenerator class needs is rescale which scales every pixel in the image such that its value lies between and which, as you'll recall from earlier in this course, is required for convolutional neural networks.
With all of this out of the way, let's create an instance of the ImageDataGenerator class called traininggenerator with a shear range, a zoom range, and a horizontal flip:
traininggenerator ImageDataGenerator
rescale
shearrange
zoomrange
horizontalflip True
We have now created an object that can be used to perform image augmentation on our data set. However, the augmentation has not yet been done. We do not yet have the training data we will use to train our convolutional neural network.
To generate our data, we'll need to call the flowfromdirectory method on our new traininggenerator object. This method takes a number of parameters. This method will apply the necessary image augmentation techniques to our training data.
trainingset traininggenerator.flowfromdirectorytrainingdata',
targetsize
batchsize
classmode 'binary'
Let's examine each of the parameters from this method onebyone:
The first parameter is the folder that the training data is contained in
The targetsize variable contains the dimensions that each image in the data set will be resized to
The batchsize variable represents the size of batches of data that the method will be applied to
The classmode specifies which time of classifier you're building. The two main options are binary for two classes or categorical for two or more classes There are other options which you can read about in the keras documentation if desired.
Once you run this command, you should see the following output:
Found images belonging to classes.
Now that this is done, we can move on to preprocessing our test data.
Please print the output of traininggenerator.flowfromdirectory as an image here Mark
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
