Dog Breed Classification using Deep Learning

Photo by Emma Gilberg on Dribbble

Task

In this project, we will be classifying the breed of the dog from the given photo of a dog as input.

Dataset- https://cainvas-static.s3.amazonaws.com/media/user_data/AmrutaKoshe/dog_photos.zip

The dataset consists of 5 selected different breeds of dogs. Each folder is named after a breed and contains around 120 images of that breed. Based on the given image, we need to classify the breed as one of the 5 breeds present.

The 5 different breeds are-

Preprocessing –

  • First, import all the required libraries –

https://gist.github.com/AmrutaKoshe/116fab4c7b14f2dd205ffc6a352ffc67

  • Download the data and unzip it to access the images and labels from your notebook.

https://gist.github.com/AmrutaKoshe/6f8d978b65c5d6812f46a157c381454c

  • List all the folder names in your dataset and check the number of classifications to make (number of breeds present)

https://gist.github.com/AmrutaKoshe/6a878641231f7a756db2d2ac0e4227f1

output:

[\'bulldog\', \'pug\', \'rottweiler\', \'german shepherds\', \'labrador\']
5
  • To understand our dataset better, display some images

Split the training dataset into train and validation set

  • Perform data augmentation by using ImageDataGenerator so that we can acquire more relevant data from the existing images by making minor alterations to the dataset.

https://gist.github.com/AmrutaKoshe/01580e342f3285fe6147a5a2620b2454

  • Divide the training dataset into train set and validation set.

https://gist.github.com/AmrutaKoshe/c5f1bba64c1eda05f306e9f362f65380

output:

Found 459 images belonging to 5 classes.
Found 112 images belonging to 5 classes.

Training the model

https://gist.github.com/AmrutaKoshe/7695a37df993403df460aac15d040cb3

  • compile and fit the model

https://gist.github.com/AmrutaKoshe/9b0a21b62a18b2f558f3b290d701fdcf

output:

Epoch 1/170
14/14 [==============================] - 2s 116ms/step - loss: 1.6112 - accuracy: 0.2277 - val_loss: 1.6012 - val_accuracy: 0.2411
Epoch 2/170
14/14 [==============================] - 1s 99ms/step - loss: 1.6091 - accuracy: 0.2482 - val_loss: 1.6041 - val_accuracy: 0.2411
Epoch 3/170
14/14 [==============================] - 1s 99ms/step - loss: 1.6014 - accuracy: 0.2365 - val_loss: 1.6013 - val_accuracy: 0.2411
...
...
...
Epoch 168/170
14/14 [==============================] - 1s 99ms/step - loss: 0.3052 - accuracy: 0.8899 - val_loss: 0.9355 - val_accuracy: 0.7054
Epoch 169/170
14/14 [==============================] - 1s 99ms/step - loss: 0.3965 - accuracy: 0.8454 - val_loss: 1.0105 - val_accuracy: 0.7054
Epoch 170/170
14/14 [==============================] - 1s 103ms/step - loss: 0.2919 - accuracy: 0.8839 - val_loss: 0.7971 - val_accuracy: 0.7768

Model Performance

Making Predictions

  • Chose an image from the test set

https://gist.github.com/AmrutaKoshe/940766bd88ab800b4e887b6fb6ac5ca6

https://gist.github.com/AmrutaKoshe/8a3bca12bfb5320e8d9f1e72f0b6e344

output:

Prediction is bulldog.

Conclusion

Hence, we have trained a sequential model to predict the breed of a dog with the image of the dog as the input.

Notebook link: https://cainvas.ai-tech.systems/notebooks/details/?path=AmrutaKoshe/dog%20photos.ipynb

Credit: Amruta Koshe