My 3 months with Computer Vision — Part 5 — Transfer Learning for Stanford Dog Dataset

Angadpreet Nagpal
2 min readApr 18, 2021
Stanford dog Dataset

Let’s start with the 3rd Project — Stanford Dog Dataset. This dataset asks you to identify dogs of 120 different breeds. We can go with our previous approach. Creating a custom neural network for identifying the breed. But that will take a lot of computation and a lot of time. Let’s introduce a new concept then.

You can clone the repository at https://github.com/angadp/DeepLearning

Transfer Learning

Transfer Learning is the concept of using pretrained models for your own use. Most Kaggle competition winners and models in production use transfer learning. These models are trained on dataset of objects and have saved weights for what has worked for recognizing other objects.

We will use frozen transfer learned model ( The features of this model are not learned. ) in the start and then have dense layers to learn the application specific features.

The above model is called Xception. We will get the model that was trained on imagenet and the input shape to it will be (300, 300). In the second line, we make all the layers of Xception model to non trainable

Loading the data

Similar to how we did it for CatsVDogs, let’s load the data using ImageDataGenerator and flow from directory.

Model

Let’s now define the model. As we had said, the first layer will be the model we downloaded with the pretrained features and frozen weights and get dense layers to learn application specific features.

In the end of the model e have 120 outputs for the 120 classes.

Compile

Again we have categorial as we have 120 categories and we have SGD as optimizer.

Training

Finally, we train it. We will get 96% accuracy on training and 90% on validation.

Conclusion

For larger models, it is better to go for pretrained models with frozen weights. Otherwise the amount of computation and time required is large.

--

--

Angadpreet Nagpal
0 Followers

Senior Software Engineer at M56Studios. Interested in mobile and web development and Deep Learning.