Image Classification using CNN
- hxr8557
- Oct 21, 2022
- 3 min read
This blog post gives an overview and all the steps that is being followed to build an image classifier using CNN
( Note : The development is still in progress. As I am a beginner to Tensorflow, CNN, Keras etc, I am learning all the concepts from its roots, and developing this model. Hence, it is taking me more time to build this model. I will keep updating this post, as and when I make a progress in my code
P.S. - I'm aiming to build a good model, no matter how much time it takes.)
Problem Statement : The main aim of the model to be built - is to perform the image classification on the given dataset - which comprises of 3 types of image classes i.e. Motorbikes, Airplanes and Schooner
Beginning steps :
I started with understanding the problem statement.
I referred YouTube tutorial videos to understand the basic concepts of CNN and how exactly it works.
Here's an overview of my understanding of a CNN:
The main idea behind CNN is - Feature Extraction
Different set of neurons will be working on different set of features
How to make computers recognize the tiny features? - For this we use filters.
For example - if we have to detect an image of a cat - we will have to use the separate filters for detecting eyes, nose, ears, legs etc.
By applying the convolution operation, we create a feature map - that will detect a particular feature.
Aggregated results of first layer can be fed for the filters in the next layer.
On a whole, CNN can be divided into two parts - Feature extraction and Classification
In the end, we will obtain a fully connected dense neurons
Step 1 - Import all the required packages

Step 2 : Declare the image paths of - Motorbikes, airplanes and schooner

Step 3 : Loading the image data
using cv2.imreaad() function to read the images from the path - and appending them to a list of images.
I have also created a separate list for motorbikes, airplanes and schooners, and happening the respective images to that list
There is another list - labels_list : which will be used to store all the labels

Step 4:
In the next part, I'm converting the images_list to a Numpy Array and encoding the labels using one hot encoding

From the image data obtained, plotting one of the sample image using matplotlib. I have defined a function which in general, takes the image_data, image_labels and index as the arguments. And, as result it plots the image in the specified index.
( Note: I referred this piece of code to plot the images using matplotlib - from a YouTube tutorial. Link for the same is provided in the below Reference section)

Step 5 : The next step here would be, to split the data into train data and test data.
This can be achieved by making use of sklearn's train_test_split
It will divide the data in the ratio of 80% : 20% respectively for the training data and test data

Step 6 : In the next step, I'm normalizing the data - by dividing each pixel value by 255 - to obtain it in the range of 0 to 1

Step 7 : Building the model :
To build the model, I referred a YouTube tutorial
(P.S - I'm still exploring - to build a good model. And as of now, this is the model I've got)
As the beginning step, I have just built the model with single convolutional layer
One step of max pooling is applied
And, the model is compiled, once it is built

Step 8 : Model fitting - At this stage when I'm trying to run model.fit(...) - I'm getting some errors. This is the point I'm still working on currently. Will update the blog post - once I make progress here

Contributions as of now:
From my part, I would like to say that, as a beginner - I learnt the concepts of CNN, and tried to understand all the root concepts
From whatever I have understood so far, I tried my best in conveying the conceptual understanding in this blog post.
I am trying to put all the concepts together and build a good model. As of now, I'm stuck at the model fitting point. But, I will definitely make some progress here and update this blog post with the progress.
References :
I referred stack overflow.com to understand some of the code snippets for unzipping file, importing the files and reading them.
https://www.kaggle.com/code/maricinnamon/multiclass-classification-caltech101-tensorflow
I referred the below YouTube videos - to get and understanding on CNN :
https://www.youtube.com/watch?v=7HPwo4wnJeA
https://www.youtube.com/watch?v=iqQgED9vV7k


Comments