Dog Breed Classification with Deep Learning in Simple English and Minimal Code

Abdelrahman Ashraf
4 min readApr 15, 2020

Deep learning became quite powerful! Not only we can use it to differentiate between males and females, dogs and cats, but we can now use it to classify among different dog breeds.

Source: GoMine

Not only this but there are some breeds looking super alike even humans sometimes can’t distinguish their breeds, like these for example:

Alaskan Malamute and Siberian Husky
Whippet and Italian Greyhound

Using deep learning not only we can distinguish their breeds, also we can catch the alike features between these breeds with humans, sounds interesting!! Now let's jump to the magic world of deep learning and Artificial Neural Networks.

But first what’s a neural network simply?
A neural network (also called an ANN or an artificial neural network) is a sort of computer software, inspired by biological neurons. Similarly, a neural network is made up of cells that work together to produce the desired result, although each individual cell is only responsible for solving a small part of the problem. For more info Wikipedia.

Source: TowardsDataScience

Using these bunch of layers and neurons we can then teach the computer on how to classify between stuff and the more powerful the network are the harder the task it could achieve. like humans have different kinds of learning; through books and videos, also these artificial neurons have different types of parameters/hyper-parameters to tune to learn better and better. For more info click here.

Source: istockphoto

Reaching this far means you’re quite interested, well then let’s dig more. Adding to what you’ve learnt so far you should also know that the Artificial Neural Networks have many types some are called CNN, RNN and some other types, we won’t get into further technicality, but CNN are quite interesting to know about.

CNN or Convolutional Neural Network are a certain type of neural networks which is primarily used when we are dealing with image data; Classification, Object detection, Object tracking, Facial recognition, ..etc. They tend to help the computer grasp the main features in an image to help it classify, detect, ..etc. The math behind the CNN is quite different than that’s behind the usual ANN. In CNN we perform convolution operations whereas in ANN we tend to use matrix multiplication.

Source: AwarenessDay

And now let’s learn about how it’s done, using an easy to use high level neural network API called Keras we built our layers in the following manner:

model = Sequential() # Here we define our modelprob_drop_conv = 0.2    # Here we prevent overfitting# -- Here we add a convolutional layer (1st layer)
model.add(Conv2D(16, kernel_size=(3,3), activation = 'relu', input_shape = (224, 224, 3)))
model.add(Dropout(prob_drop_conv))
model.add(MaxPooling2D((2,2)))
# -- Here we add a convolutional layer (2nd layer)
model.add(Conv2D(24, kernel_size=(3,3), activation = 'relu'))
model.add(Dropout(prob_drop_conv))
model.add(MaxPooling2D((2,2)))
# -- Here we add a convolutional layer (3rd layer)
model.add(Conv2D(32, kernel_size=(3,3), activation = 'relu'))
model.add(Dropout(prob_drop_conv))
model.add(MaxPooling2D((2,2)))
# -- Here we add a fully connected layer (4th layer)
model.add(Flatten())model.add(Dense(512, activation='relu'))
model.add(Dropout(0.3))
# -- Here we add the output Layer with the number of breeds we have in our dataset (133 dog breed)
model.add(Dense(133,activation='softmax'))
# Model Summary
model.summary()

And that’s our model’s summary

Model’s Architecture

Now let’s see what are the results performed by this model know!!

First: Dog Detection and breed classification

It’s Golden Retriever Indeed!

Now to the more magical part let’s test our model on humans!

Source: Forbes
Source: Nature

So let’s try and trick our model!

Although almost no model in the world with 100% accuracy yet, but looks like we couldn’t trick our model yet!!

But I think you could trick it with a different image.. You should try, here’s the Code. Have fun and tell me if you could trick it, spoiler Alert! It’s not easy.

--

--

Abdelrahman Ashraf
0 Followers

Data Scientist | Data Analyst | Applied Scientist | AI Engineer