Object Classification(Electric Car and Electric Bus Classification)

Photo by Ahmed Maghrabi on Dribbble

Classification is the categorization of the object based on defined classes..

Introduction

  • Object Detection is one of the most famous and extensively researched topics in the field of Machine Vision.
  • To understand Object Detection in simplistic terms, it deals with identifying and localizing some of the classes such as person, car, bus, spoon, etc. from the image.
  • In this article, let’s have a proper understanding of these trends which are followed in Deep and other Traditional Learning approaches. We will also be looking at the upsides and downside of both the approaches in a modularized fashion — Object Detection.

Classification/Regression

  • The final step of our pipeline is to classify the existing crops using the obtained feature descriptor values and assign a crop to a given class. Simultaneously, drawing a bounding box around an object in a given image. Most of the well-known classification techniques used are Support Vector Machines, AdaBoost, Random Forest, etc.
  • These models need far more information about a class and so, tedious tweaking is needed to get good results. For example, SVM generally does not support class probability discrimination. So, it becomes very tedious in multi-class classification. These methods also fail in generalizing the data i.e. SVM generally performs very bad on the data containing noise and have overlapping data points.

But after the advent of the CNNs and Deep Neural Network architecture, it has become more convenient and reliable to fill the gaps which are present in the traditional object detection algorithms.

Importing the necessary libraries

We will use some commonly used libraries like Matplotlib. We will use Matplotlib to access the images and display it in the notebook.

Other imports include Tensorflow and Keras to create the convolutional neural network and perform preprocessing of the data to perform training on it.

https://gist.github.com/MohdShariqMalik/786ef3e729f42631115a2dff5e066d0b

Preparing the data

The training data is present inside Two folders — Electric Bus and Electric Car. We will use the ImageDataGenerator offered by Keras to prepare the data and get appropriate labels pertaining to the folder structure.

Image Preprocessing

https://gist.github.com/MohdShariqMalik/e9041cd5354b090aec29e6da8d24dd38

Creating the Model

As mentioned, we will create a Convolutional Neural Network to predict the correct classes of cells from the images. We have used 3 Conv2D layers with MaxPool2D layers after each for the feature extraction from the images. The activation function used is ReLU. The output layer has only three neurons corresponding to the two classes of Electric Bus and Electric Car, with Sigmoid activation function.

https://gist.github.com/MohdShariqMalik/6ca4b69a85c029ee1b4344a56282e74c

The model summary for the above created model is as follow:

Compiling and Training the Model

We will compile the model with Adam as the optimizer and Binary Crossentropy as the loss function. We will train the model for 20 epochs. We will store the accuracy, loss, val_accuracy and val_loss at each epoch in the history for plotting meaningful data later.

https://gist.github.com/MohdShariqMalik/5e5de367133d58de181295a072348fb3

Accuracy & Loss

We will now plot the model performance at each epoch during the training phase.

https://gist.github.com/MohdShariqMalik/582d0043996f9847a00bd7b323d0302c

Training accuracy and Validation accuracy

https://gist.github.com/MohdShariqMalik/c5eca3847e4b5c7e88c51af72dee6602

Training loss and Validation loss

Model Evaluation:

https://gist.github.com/MohdShariqMalik/1f64f6d27b746a611a2a14f10f4f402a

Notebook : Here

Credit: Mohd Shariq Malik