Image classification method is used for classifying images into respective category classes by using the methods in python for data science:
- Training a small network from scratch.
- Fine tuning of top layers of the model by using VGG16.
Now we will discuss the training of model from scratch and then classifying the data which contains cars and planes.
The train data contains 200 images of each car and planes so, there are a total of 400 images in the training data set.
Test data: It will contain 50 images of cars and planes so, in total, there will be 100 images in the test data set.
Model description: We need to, first of all, prepare the dataset and its arrangement before the start of the model. Let us look at the image given below.
In order to train the model we do not need a large high end machine and GPU’s; it is possible to use CPUs as well. We will include the following libraries.
In this the train_data_dir is the train dataset directory. The validation_data_dir directory is used for validation of data. The nb_train_samples is total number of train samples. The nb_validation_samples is total number of validation samples.
Code for checking format of image:
This code will be used for checking the data format.
Now we will see the terms used above:
The compile function used involves using of loss, optimizers, and metrics. The loss function used is binary_crossentropy, optimizers used is rmsprop.
Using the data generator:
The part of the dataGenerator will come into picture in which we have used:
We can also save the model.
Below we will see the complete implementation.