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.

You can install it here: github.com/fastai/fastai
5/ Next we download the data

𝚙𝚊𝚝𝚑 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 🙂

You can sign up for it here 👇 learnersdigest.radekosmulski.com
11/ Last but not least, we tell our 𝙳𝚊𝚝𝚊𝙻𝚘𝚊𝚍𝚎𝚛𝚜 to normalize the data!

Normalization is a big name for subtracting the mean of pixel values of images a model has been trained on and dividing by the standard deviation. 🤷

This helps the model train.
12/ It's time to train our model!

We create a convolutional neural network (CNN), we pass in the architecture - 𝚛𝚎𝚜𝚗𝚎𝚝𝟷𝟾, and we train the model for four epochs.

An epoch is an iteration through our dataset - a model will see each example 4 times.
13/ An architecture tells the model how to perform the computation.

For CNNs, it's mostly tiny windows sliding across the image and looking for patterns!

There are many architectures that are widely used and we'll look more closely at them in my tweets to follow.
14/ After 25 minutes of training, the results are in!

Let us save the trained model for later use (a trained model is a fully-fledged computer program that can do interesting things!).

But wouldn't it be great to see where our model makes mistakes?
15/ The @fastdotai library makes this super easy.

These are some of the images that our model got wrong. Not bad at all!
16/ I hope you enjoyed this thread as it sure has taken me quite a while to write it 😂

I plan on doing more of such threads in near future - please share with others so that I can reach more people 🙂

Thank you for reading and let me know what you think!

Ah I nearly forgot...
17/ Do you have any suggestions on how we could improve the results of our model?

Please share them with me in the comments below!

A thread on how we can improve our results, pulling all your suggestions together, coming soon...

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Radek Osmulski

Radek Osmulski Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @radekosmulski

5 Feb
THREAD: Can you go from being a treasurer to doing cutting edge DL research through the power of the community? ✨

Sarada Lee (@moodymwlee) is the founder of the Perth ML Group and a Scholar @DataInstituteSF and @Uni_Newcastle.

Her amazing journey began with a selfless act...
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 💡
Read 4 tweets
21 Dec 18
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
Read 4 tweets
8 Dec 18
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
Read 8 tweets
26 Dec 17
Favorite recent jupyter notebook discovery - the %debug magic:

1. Get an exception.
2. Insert a new cell, type %debug and run it.

An interactive debugger will open bringing you to where the exception occurred and allowing you to look around!
Type `help` for a listing of available dev superpowers. `up` takes you one level up in the stack.
You can also set a breakpoint and open the interactive debugger at an arbitrary point via doing the following.
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!