How I Create Simple Multiclass Image Classification Model Using Own Dataset

Source :cios233 community

Today we’ll create a multiclass classification model which will classify images into multiple categories. In this we’ll be using Colour Classification Dataset. for example — Model will be able to predict whether the inputted image is Red,Blue or Green.

You can pick any colour of your choice and any number of I am choosing Red,Blue and Green. let’s go step by step

1.Get Your System Ready

Requirements : Python 3.6 or above , Jupyter Notebook or Spyder

Machine learning Libraries : keras,tensorflow,numpy,PIL(Pillow)

2.Getting The dataset

Most important requirement for Deep learning model is well balanced dataset. Due to lack of balance in dataset , model will end up predicting wrong predictions. In deep learning models,it is advisable to have large dataset so that model will not overfit .

First,download the dataset from kaggle.

Click here to get complete dataset of Colour Classifcation

Once you download the dataset ,you’ll see folder structure like this.

Each folder contain 900 images for train and 100 images for test .

In this tutorial ,I will be using subset of this dataset which will contain 400 images in each class for training and 100 images in each class for test.

3. Importing all necessary Libraries

Numpy library handles the numerical computations.Tensorflow is free and open source library which mainly used for building machine learning and deep learning models .PIL or Pillow is Python Image Library which supports range of simple and sophisticated image manipulation functionality.Keras is also free and open source library designed to enable fast experimentation with deep neural networks and it is capable of running on top of TensorFlow and other libraries.

4.Image Preprocessing

Above code defines the class categories as [Red,Blue,Green] and will detect the images from dataset folder .You can refer this keras documentation .

4.Build the model

Now,we will build our model.Here we have two convolution layers followed by two Max Pooling layer each which will extract import features in image and for that it will make use of stride of 3x3 which will be traced on the 3D matrix,Remember : More the convolution layers,more the accurate model. Then we have used flatten and dense layer as well which will flatten the matrix into 1-D array .Here we are using softmax activation function at output layer as our model is going to perform multi-class classification

Lets See Model Summary .

5.Compile the model

Lets compile our model.Here,we are using categorical cross entropy loss because we are going to classify images into multiple classes.For Binary Classification binary_crossentropy loss is used.And we’ve used RMSprop optimizer ,we can also use adam optimizer.

6.Train the model

Now,we will train the model. In the code,steps_per_epoch represents the total number of images in train set(400+400+400). Epochs means how many times we are going to iterate over dataset and validation_steps represent the total number of images in test set(100+100+100). Training process may take time.

7.Evaluate the model

Lets evaluate the model by finding loss and accuracy percentile on test dataset.So, as you can see we’re getting 98 % accuracy on test set which is great.

8. Test the model

Now we will test on one image. I am taking Blue coloured image .Let’s check whether our model predicts correct or not.

So,as you can see that our model accurately predicts that the given image is belongs to Blue Class.

So,thats it.We,ve succesfully created our multi-colour classification model .

Click here to get complete code available on GitHub.

Check out this Links

Blog ->

Github ->

Kaggle ->

Thank You For Reading !

Learning is all about simplifying things and make it useful. Reading blogs is worth thing you could do your build your career to next level. START READING NOW.