THREAD: Can you start learning cutting-edge deep learning without specialized hardware? 🤖
In this thread, we will train an advanced Computer Vision model on a challenging dataset. 🐕🐈 Training completes in 25 minutes on my 3yrs old Ryzen 5 CPU.
Let me show you how...
2/ We will train on the challenging Oxford-IIIT Pet Dataset.
It consists of 37 classes, with very few examples (around 200) per class. These breeds are hard to tell apart for machines and humans alike!
Such problems are called fine-grained image classification tasks.
3/ These are all the lines of code that we will need!
Our model trains to a very good accuracy of 92%! This is across 37 classes!
How many people do you know who would be as good at telling dog and cat breeds apart?
Let's reconstruct how we did it...
4/ We first import all the necessary functionality from the @fastdotai library.
This is the best deep learning library for learning and for doing research.
𝚙𝚊𝚝𝚑 points to the location where the data has been downloaded.
It contains an 𝚒𝚖𝚊𝚐𝚎𝚜 directory with all the pictures in the dataset.
6/ Let's now create our 𝙳𝚊𝚝𝚊𝙻𝚘𝚊𝚍𝚎𝚛𝚜
We tell 𝙳𝚊𝚝𝚊𝙻𝚘𝚊𝚍𝚎𝚛𝚜 where to find our data and how to process it.
We pass the location of our data (𝚙𝚊𝚝𝚑 / 'images') and ask for the images to be resized to 224 x 224 pixels.
This is important!
7/ Many advanced DL models require that all examples are of the same shape. Since the pictures in the dataset have different dimensions, we need to resize them before we can train on them.
𝚋𝚜 (batch size) is how many images our model will be shown at a time.
8/ We also need to tell our 𝙳𝚊𝚝𝚊𝙻𝚘𝚊𝚍𝚎𝚛𝚜 how to assign labels.
We are passing in a regex that tells them how to look for the class within a file name.
9/ The regex says:
✅ start from the end of the file name, skip .jpg, then skip 1 or more digits followed by an underscore
✅ now take everything up to the first forward slash, this will be our class name
10/ Regex patterns can be intimidating, but they don't have to be!
The next issue of my newsletter will demystify them once and for all 🙂
2/ In 2016 Sarada founded the Perth ML Group to help others learn.
How can the community support you? 🤗
It can...
✅ help you set up your environments 🧑💻
✅ provide technically-sound answers to challenging questions 💡
✅ make learning more fun! 🥳
3/ What are some tips for community participation?
✅ explaining things to others will help you learn 🦉
✅ it's okay to be anxious about sharing your answers publicly - DMs are always an option 📨
✅ experiment with various approaches and learn in a way that suits you best 💡
This is how little code it takes to implement a siamese net using @fastdotai and @pytorch.
I share this because I continue to be amazed.
Here is a refactored version that will be easier to change
The models above were my naive adaptations of the simple siamese network concept from cs.utoronto.ca/~gkoch/files/m… (screenshot on the left below) to a CNN setting.
On the right is the network from the Learning Deep Convolutional Feature Hierarchies section but using pretrained models
Now that the Quickdraw! competition is over, I added my solution to the repository github.com/radekosmulski/…. It is a model consisting of outputs of res50, incv4 and an rnn along with country code embeddings fed to an fc classifier. The most interesting aspect of the architecture
is how little code wiring everything together required thx to the @fastdotai lib. I replaced the classifier during training (while retaining the other weights) which the @fastdotai / @pytorch combo made very easy to accomplish.
In some sense there is nothing particularly
interesting about my solution above and beyond the basic motions of building a model. For various reasons I didn't get to the point of applying competition specific insights. The model is also partially trained
The winning solution was a CNN ensemble done using LightGBM. It also