How to tell your dog’s breed with Deep Learning in three steps

Source: Deep Learning on Medium

How to tell your dog’s breed with Deep Learning in three steps

Figure 1. Labrador Retriever

Dogs are always humans’ best friends. But sometimes it would be awkward that you do not know the breed of your best friend. Do not worry, let me tell you how to identify the dog breed with deep learning.

Step 1: Human or Dog?

Of course, the first step is to judge that if the picture is a dog or a human. Some person might look like a dog, see Figure 2.

Figure 2. A person looking like an Afghan Hound

Here we use OpenCV’s implementation of Haar feature-based cascade classifiers to detect human faces in images, and we use a pre-trained ResNet-50 model to detect dogs in images.

Step 2: Convolutional Neural Networks (CNN)

Wow, do not panic. It is easy. The basic workflow for CNN is that we first apply different filters (C part) to locate different features in the figure, such as eyes, wheel, and so on. Then with the help of training data, the model will learn how to classify dogs through neural networks (NN part) by itself. See, that is simple. We follow the model architecture in Figure 3 and improve it. We get the accuracy of identification: 8%. It is quite low, right? But we have additional help from Transfer Learning.

Figure 3. Model architecture

Step 3: CNN with Transfer Learning

So, I guess the first question is: What is transfer learning? Transfer learning involves taking a pre-trained neural network and adapting the neural network to a new, different data set. Usually, it will significantly improve the accuracy of our deep learning model which means it identifies the dog breed better.

In my project, I have tried VGG16, VGG19, ResNet50, Inception, Xception. Take VGG16 as one example, I use the pre-trained VGG-16 model as a fixed feature extractor, where the last convolutional output of VGG-16 is fed as input to our model. I only add a global average pooling layer and a fully connected layer, where the latter contains one node for each dog category and is equipped with a softmax.

Results:

Their final accuracies are at about 40%, 75%, 80%, 80%, 84%. I will say pretty good. Check the result in Figure 4 and Figure 5.

Figure 4. Prediction on a real dog picture
Figure 5. Prediction of the closest dog breed on a human picture

To see more about this analysis, see the link to my Github available here.