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:
zoom_range: Float or [lower, upper]. Range for random zoom. If a float, [lower, upper]=[1-zoomrange, 1+zoomrange].
horizontal_flip: Boolean. Randomly flip inputs horizontally.
shear_range: Float. Shear Intensity (Shear angle in counter-clockwise direction in degrees)
The only other argument that the ImageDataGenerator class needs is rescale =1/255, which scales every pixel in the image such that its value lies between 0 and 255- 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 training_generator with a 20% shear range, a 20% zoom range, and a horizontal flip:
training_generator = ImageDataGenerator(
rescale =1/255,
shear_range =0.2,
zoom_range =0.2,
horizontal_flip = 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 flow_from_directory method on our new training_generator object. This method takes a number of parameters. This method will apply the necessary image augmentation techniques to our training data.
training_set = training_generator.flow_from_directory('training_data',
target_size =(64,64),
batch_size =32,
class_mode = 'binary')
Let's examine each of the parameters from this method one-by-one:
The first parameter is the folder that the training data is contained in
The target_size variable contains the dimensions that each image in the data set will be resized to
The batch_size variable represents the size of batches of data that the method will be applied to
The class_mode 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 8000 images belonging to 2 classes.
Now that this is done, we can move on to preprocessing our test data.
Please print the output of training_generator.flow_from_directory as an image here [1 Mark]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!