Classify any Object using pre-trained CNN Model

Original article was published on Artificial Intelligence on Medium

DS in the Real World

Classify any Object using pre-trained CNN Model

Large Scale Image Classification using pre-trained Inception v3 Convolution Neural Network Model

Photo by Lenin Estrada on Unsplash

Today we have, the super effective technique as Transfer Learning where we can use a pre-trained model by Google AI to classify any image of classified visual objects in the world of computer vision.

Transfer learning is a machine learning method which utilizes a pre-trained neural network. Here, the image recognition model called Inception-v3 consists of two parts:

  • Feature extraction part with a convolutional neural network.
  • Classification part with fully-connected and softmax layers.

Inception-v3 is a pre-trained convolutional neural network model that is 48 layers deep, which is a version of the network already trained on more than a million images from the ImageNet database. It is the third edition of Google’s Inception Convolutional Neural Network, originally introduced during the ImageNet Recognition Challenge.

This pre-trained network can classify images into 1000 object categories, such as keyboard, mouse, pencil, and many animals. As a result, the network has learned rich feature representations for a wide range of images. The network has an image input size of 299-by-299. The model extracts general features from input images in the first part and classifies them based on those features in the second part.

Schematic diagram of Inception v3 — By Google AI

Inception v3 is a widely-used image recognition model that has been shown to attain greater than 78.1% accuracy on the ImageNet dataset and around 93.9% accuracy in top 5 results. The model is the culmination of many ideas developed by multiple researchers over the years. It is based on the original paper: “Rethinking the Inception Architecture for Computer Vision” by Szegedy, et. al.

More information about the Inception architecture can be found here.

In Transfer Learning, when you build a new model to classify your original dataset, you reuse the feature extraction part and re-train the classification part with your dataset. Since you don’t have to train the feature extraction part (which is the most complex part of the model), you can train the model with less computational resources and training time. In this article, we will just use the Inception v3 model to predict some images and fetch the top 5 predicted classes for the same. Let’s begin.

We are using Tensorflow v2.x

Import Data

Data Loading

Setup all initial variables with default file locations and respective values.

Create Inception v3 model

Define function for loading images and resizing for sending to model for evaluation in RGB mode.