How it works...

In step 1, we used the flow_images_from_directory() function to load the images from a directory. To use this functionality, we must structure our data as we did for the Fruits 360 dataset. This function gives us the flexibility to transform our images while loading them in R. In our implementation, we reshaped each image to a size of 20 × 20 and changed the color mode to RGB channel. Next, we explored the data and looked at the distribution of images in the training and test datasets. 

In the next step, we defined our model. In this model, we fit a max-pooling layer followed by two dense layers. The last layer of the network had softmax activation with 23 units since we had 23 output labels. Next, we looked at the summary of the model, and we observed that the number of trainable parameters in the pooling layer is zero because it has no weights and biases to train. The output shape of the pooling layer can be determined by: floor(input size/pool size).

In the last step, we compiled and trained the model. To train the model, we used the fit_generator() function because we had to train our model on the generator object returned by flow_images_from_directory(). Next, we evaluated our model's performance on the test dataset and printed the evaluation metrics.

..................Content has been hidden....................

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