Image Classification using keras:

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.

Train data:

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.

Image Classification using keras in Python for Data Science - PST Analytic

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.

Image Classification using keras in Python for Data Science - PST Analytic

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:

Image Classification using keras in Python for Data Science - PST Analytic

This code will be used for checking the data format.

Image Classification using keras in Python for Data Science - PST Analytic

Now we will see the terms used above:

Compile function:

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:

Image Classification using keras in Python for Data Science - PST Analytic

We can also save the model.

Below we will see the complete implementation.

OUTPUT:

So, to learn more about in python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.