My first deep learning hackathon

--

I recently started the deep learning course on fastai.

I had previously done a course on neural networks and deep learning, and I was really intimidated by the mathematical approach the course took. I couldn’t understand a lot of proofs, coding was completely different from the theoretical concepts and after 4 weeks of video lectures and assignments I couldn’t even build a decent pet classifier by myself.

Pertaining to my fears, I taught myself python libraries for numerical data and stuck to numerical problems because that’s where I felt safe. But where there’s comfort there is no growth.

And that’s where I have to thank fastai since its top down approach really helped me dive right in. I really recommend the course to everyone regardless of their background. Their background will only prove useful for the awesome projects they’ll be able to build.

Trending AI Articles:

1. Bursting the Jargon bubbles — Deep Learning

2. How Can We Improve the Quality of Our Data?

3. How to train a neural network to code by itself ?

4. Machine Learning using Logistic Regression in Python with Code

I’m only two weeks into the course and I’m already on my 4th or 5th project. To test my skills I decided to take part in an online hackathon. And with just a few lines of code I was in the top 2% of the competition as shown below. As of writing this article, out of 2276 participants, my rank on the leader board is 37. So how did I do it? Let’s find out.

The jupyter notebook for the same can be found on Kaggle.

Problem description and class mappings

Find the problem statement and dataset description below.

My solution:

Import the library

We start by importing the fastai library. Once imported we load our dataset. There are various ways of loading the dataset using the fastai library (from a folder, from a url, etc.) Here I’m using the data block api instead of factory methods because I find it more readable and intuitive.

We have a csv file with the names of images and their labels. We will use this to create our data bunch. Sometimes we might use the folder name as labels. For example, there will be 2 folders called cats and dogs where cat images will be in the cats folder and so on.

The way to read this code would be:

  1. There is a list of images in the given path, and their corresponding labels in a csv file
  2. Split these images into train and validation set randomly.
  3. Label the data using the csv file shown. (or df = data frame)
  4. Add a test set. (This step is optional)
  5. Set the size of the images and apply various transforms on them.
  6. And finally create a data bunch. (This can be thought of as a format in which fastai stores images)

Viewing our data

As shown, our data includes various scenes, with their labels shown above them. We need to train our model to recognize these scenes. This type of problem is known as image classification.

Training the model

We download a pretrained model called resnet34 because it’s generally a good idea to do so instead of training from scratch. The model has been trained to identify thousands of categories of images and it’s initial weights will help us learn better. We take this model and we train it for a number of cycles. We record the learning rate, check various metrics and learn some more. We can interpret the results plotting the confusion matrix. Fastai has a great method called .most_confused that helps us find out what our model is most confused about. For example,

This shows that our model was confused between 2(glacier) as 3(mountain) 87 times and between 0 (buildings) and 5 (street) 36 times which makes sense because these things are easy to confuse.

Once we think we’ve trained enough without overfitting, we make predictions on the test set and submit our results.

Some tips for getting started:

If you don’t come from a programming background then getting things running can be a little difficult but keep trying. Get help from a friend if required. Also, when your code keeps giving errors its very easy to blame it and give up. But if you cannot create a data bunch with one method, try another one. Try reading the docs and source code to make sense of things. The key is to remember you will not know everything at once. But you will know a lot if you just keep trying. If you just keep pushing yourself.

If you liked this article give it at least 50 claps:p

If you want to learn more about deep learning check out my series of articles on the same:

~happy learning.

Don’t forget to give us your 👏 !

--

--