Convolutional Neural Network CNN Applied To Swiss Watches, Using Fast.ai Library and Resnet34

Carlos Coto
5 min readNov 5, 2018

--

First of all, I must start by admitting that I am not a Computer Engineer…I’m a Psychologist. I used to be a University Professor, Experimental Psychology in The School of Psychology of University Dr. José Matías Delgado, in my home country, El Salvador.

I came with my family, one year ago, to live to Switzerland. My wife and kids are Swiss, so we wanted a better future for our kids, hence we came to Switzerland. We love Switzerland, and everything in it!

I love programming…been programming for 15 years, mostly web page, backend and frontend.

I learned about Data Science, not so long ago, since in El Salvador, there are no Data Scientists, it is not a career as there is no university teaching it.

I am currently taking the Third instance of Fast.ai MOOC. The course is still not officially out, till next year, but once a week, we are taking a class, and it is AWESOME! Jeremy Howard, the course professor explains everything in simple words, even I understand it… Side note: After a few classes, I learned that Jeremy is also NOT a Computer Engineer…He is a Philosopher! So for everyone not an Engineer, we too can study Data Science without having the Math background!

In the last class, we needed to build an Image Classifier. Since I am living in Switzerland, I thought, why not build a classifier for Swiss Watches? So here is my take into a Convolutional Neural Network, based on Resnet34 architecture, and classifying 13 different brands of Swiss Watches.

Why 13 brands? Well why not? Those were the ones that came to my mind when I was thinking about the classifier. Of course, more brands may be added! The more, the better, as they say!

The 13 brands I used were:

‘Audemars’, ’Cartier’, ’Delma’, ’Jaeger-lecoultre’, ’Mondain’, ’Omega’, ’Oris’, ’Patek-Phillippe’, ’Rolex’, ’Swatch’, ’Tag-heuer’, ’Tissot’, and ’Vulcain’.

I’m currently working on a companion App, where you may upload an image of one of these brand watches, and the App will infer its brand.

9 out of 13 brands of Watches in the Classifier

Fast.ai is an awesome library, with everything you need to make Deep Learning or any kind of Machine Learning easy and fast! It is based on PyTorch, with everything you will need built in… You just have to plug in your data, sort of speak, and then it does its magic! You may check my github with all the info on the classifier.

I used 13 different brand of watches, with 1754 images on the Training set, and 470 on the Validation set.

With all that in place, you start the difficult process of writing all the code needed for the Learner…

“learn = create_cnn(data, models.resnet34, metrics=error_rate)”

That is all you need! Really!!!

The model uses Resnet34 Architecture, which is a pre-trained Residual Network, in this case with 34 different levels of training. Since it is pretrained, it makes the process of classification easier, since it uses what it learned from the previous images.

Here is a great video with Andrew Ng, explaining Residual Networks.

With the previous code, I got this:

Initial Training

You can see that with the initial training with 4 epochs, you get a 0.455319 error_rate, which is not that great, but, having in mind it is analyzing different watch brands, is better than mere chance!

We then need to Unfreeze the layers of the learner, with: learn.unfreeze()

This makes it possible for the learner to train all its layers, and be able to get a better result.

learn.lr_find()

Makes possible to find the Learning Rate you need to use in your classifier learner.

Using learn.lr_find() I used later 10e-5, and 3e-4

Using a sliced learn rate, I managed after 7 Epochs to get the error rate down to 0.280851!

I will try to use more Epochs, maybe I can get it lower without over-fitting!

interp.plot_confusion_matrix()
interp.plot_top_losses(9, figsize=(10,9))

The most-confused were:

“Jaeger-lecoultre with Patek Phillippe”

“Patek Phillippe and Delma”

Rolex and Swatch where probably the less confused on the learner, maybe because they stay strong with their brand’s look, and they don’t mix designs in their models and brand.

Out of the 13 brands, the most confused was Delma. I love Delma watches… I even live beside their Headquarters in Lengnau, Canton of Bern! They tend to have various models, and different designs, I love them, but… they could differentiate even more from the other brands.

In the most confused you may see the last image, which is NOT a real watch. This means I need to clean up my image samples, and check for NON watch images. This could make my error lower.

With the Most-confused table, you may see that even YOU as human, may get confused with them! For instance, the green Swatch…It is not a Swatch, it is a Mondain! These watches have gone out of their “normal” brand design, maybe catering for new Trends?

Well, thanks for reading! It was a great exercise for me in Computer Vision. I would love to take it up a notch! Maybe, I could create a learner to classify REAL vs. FAKE Swiss watches! Why not? Tell me what you think in the comments!

--

--

Carlos Coto

Psychologist, Ex-University Professor, Experimental Psychology, Machine Learning, Deep Learning, AI, FastAI