Correlate Image Classification with Keras and PyTorch (CIFAR-10)| Snehit Vaddi
Introduction😪😉:
Image classification is a task of classifying images into different classes. It is mostly considered a Supervised Learning problem. With advancements in the field of Deep Learning, Image classification has seen bright colors in the current decade.
Image classification can be performed with different types of Neural Networks like RNN, LSTM, ANN, etc. Among these CNN’s (Convolutional Neural Networks) are easily most popular. Image classification can also perform without Neural Networks using algorithms like SVM and kNN having said that dimensionality of data acceptable to the algorithm.
There are various datasets that you can leverage for applying convolutional neural networks. Here are the three most popular datasets used by beginners:
- MNIST
- CIFAR -10
- ImageNet
What are we going to Learn🤔??
In this article, I am going to briefly explain:
- Image Classification using python libraries -Keras, PyTorch
- Comparison of Approach in both libraries
- Comparing Accuracy and Loss of both models.
Let’s start Booming - Keras model🧨🔥:
Import Keras module. CIFAR-10 is built-in Keras.datasets module. CIFAR-10 is a dataset of 50,000 32x32 color training images, labeled over 10 categories, and 10,000 test images.
You can access the complete Keras model and code here:
- Jovian Notebook: https://jovian.ml/v-snehith999/keras-cnn-cifar-10
So, let's import the CIFAR-10 dataset.
Import matplotlib.pyplot as plt. It can be used for visualizing images and graphs.
Preview of mages:
PreProcessing:
Normalizing data helps to reduce numerical values of the image keeping the features of the image unchanged.
x_train = x_train/225
x_test = x_test/255
In Keras, the to_categorial module is used to convert categories labels into one-hot encodings.
y_cat_train = to_categorical(y_train,10)
y_cat_test = to_categorical(y_test,10)
Building the Keras Model:
Our model contains two convolutional models and two dense layers. Each convolutional layer is followed by a pooling layer. We are using ‘relu’ activation function. The convolutional layer is flattened and input into the first Dense layer and its outputs are fed into the output dense layer.
Training the model:
We are training our 2 Convolutional layers and one Dense layer model for 10 epochs.
At last, the metrics are:
Training set: 📈
- Accuracy: 0.8275
- Loss: 0.5252
Testing Set:📉
- Precision: 0.68
- Recall: 0.64
- F1-Score: 0.65
And now, Let’s start Booming - Pytorch Model🎇🔥
For now, I am uploading complete notebook since I am busy. I will update with a detailed explanation in next week.
Hope you can understand and please leave a “clap” if you like it🤩.