How To Create a Deep Neural Network Model Using CIFAR-10 Dataset.

Here is my third week of Deep Learning with PyTorch: Zero to GANs.

source: https://futurism.com

In this blog, we will take a look at What is a neural network, What is CIFAR-10 dataset, How to develop & train a neural network model, etc.

What is a Neural Network?

Neural networks are a set of algorithms. These algorithms interpret the received data into real-world data that are images, sound, text, videos, and series. Neural networks are multi-layer networks of neurons that we use to classify things, make predictions, etc.

What is so special about a neural network?

  1. It is used to resolve highly complicated problems existed in a real-world scenario.
  2. Highly complicated algorithms can work more efficiently than a human brain.
  3. Reduces the chance of risks and mistakes.
  4. It possesses more versatility than humans.

What is CIFAR-10 Dataset?

CIFAR stands for the Canadian Institute For Advanced Research and the CIFAR-10 dataset was developed along with the CIFAR-100 dataset by researchers at the CIFAR institute.

source: https://www.researchgate.net/

The CIFAR-10 dataset is consists of 60,000 (50,000 dataset & 10,000 test dataset) 32×32 pixel color photographs of objects from 10 classes. The class labels and their standard associated integer values are listed below.

Here 3 for color images and 32x32 pixel images.
The number of classes i.e, 10.
These are the classes.

Load CIFAR-10 Dataset:

Number of Images belonging to each class:

Here you can see from the 50,000 datasets each class has the same number of images.

Prepare The Training Model:

We’ll use a validation set with 5000 images (10% of the dataset). To ensure we get the same validation set each time, we’ll set PyTorch’s random number generator to a seed value of 43.

Let’s use the random_split method to create the training & validation sets

We can now create data loaders to load the data in batches.

Traning The Model:

Now, Extend the ImageClassificationBase class to complete the model definition. For class details, you can check here My Notebook.

Now, Check the validation loss & accuracy.

Finally, we can train the model using the fit function to reduce validation loss & improve accuracy. We will train the model in multiple phases, adjusting the no. of epochs & learning rates each time based on the result of the previous training phase.

20 epochs at learning rate 0.1
15 epochs at learning rate 0.01
10 epochs at learning rate 0.001
5 epochs at learning rate 0.0001

Check how well our model can perform on this dataset by plotting the losses and the accuracies.

Finally, evaluate the model on the test dataset report its final performance.

We got almost 55% of accuracy! Here our model can classify images with this rate of accuracy.

By changing no. of epochs & learning rates each time based on the result we may get better accuracy.

References

Final Advice:

I hope you liked this post. Feel free to share your ideas, thoughts, and suggestions below.

Good luck!

Let’s Connect — My Linkedin

Linkedin — @Rksensational

Undergraduate ME and Passionate About New Technologies. Data Science, Web-Dev, DevOps, Self-Driving Car Etc..