AWS Project 3 — Transfer Learning with VGG19

Samarth Goenka
4 min readMay 11, 2018

--

For this project I work with a Kaggle dataset and attempt to identify dog breeds from a collection of images and around 120 labels for breeds. The model building and accuracy plots are not as interesting as some of the Style Transfer visualizations. Look out for that!

Model building

I decided to use the pre-trained VGG19 model and add a Dropout and Flatten layer. I then called the Dense layer with the specified number of classes in my sample.

By using this model I could exploit the pre-trained weights on ImageNet and then change the top layer. I then compile with the ‘adam’ optimizer and ‘categorical_crossentropy’ loss function, and fit it with 5 epochs.

Model accuracy

As can be seen, the model reaches a 40% training accuracy but only a 10% validation accuracy. Similarly, the training loss decreases to with every epoch, but the validation loss decreases much slower and seems to end at around 4%. Although this might seem poor, it is worth noting that there are 120 different potential dog breed labels to choose from implying that if we were to guess at random then we have a 0.83% of guessing correctly. In fact, even if I were shown a picture of a dog there is a high likelihood that I would not be able to guess the breed correctly (as long as it were not a labrador or retriever or bulldog, everyone can guess those breeds correctly!). Hence, this model seems to perform really well after 5 epochs. However, the poor performance on the validation set as compared to the training set implies that the model is overfit to the training data.

Model visualizations

I decided to take a couple images from my dog training set and see how they would look if I style transferred the image of Holi in India below.

https://www.smithsonianmag.com/travel/holi-festival-colors-meaning-180958119/

The two dog images that I worked with are below.

I was hoping that the style transfer would make the image more colorful and would apply to both the dogs in the second image. I conducted the transfer with 2, 5, and 10 iterations to see how the number of iterations affected the transfer. Lets see what we got!

Style transfer with 2 (Left), 5 (Middle) and 10 (Right) iterations

Yeah it’s pretty cool.

As can be seen there is an improvement in the transfer with more iterations. The strength of the colors in the background increase as the iterations increase. The pictures also become clearer and the colors are better spread out throughout the dog as well. Looking closely at the nose of the dog in snow, we can see that the edges and curves become more colorful as the iterations increase. Looking closely at the picture with the pair of dogs, we can see that as the iterations increase, both dogs get more colorful.

In order to see all the code, please visit my Github

Click here to see my project on CNN, and here to see my project on RNN.

--

--