Learn deep learning with GPU enabled kaggle kernels and fastai MOOC

Written by shub777_56374 | Published 2018/07/29
Tech Story Tags: machine-learning | deep-learning | artificial-intelligence | kaggle | gpu

TLDRvia the TL;DR App

One of the biggest hurdles of democratizing deep learning has been the need of a GPU accelerated environment. If we want to spend our time efficiently testing and learning across problem statements we need a GPU based server.But these GPU based environments across platforms (GCP, AWS, Azure, Paper-space, floydhub) can cost you anything between ~$0.60 -$1.5.This cost when combined with cost of storage and if we are using instances which are persistent may really add to the burden on our money bag.

picked up from slav’s blog https://blog.slavv.com/learning-machine-learning-on-the-cheap-persistent-aws-spot-instances-668e7294b6d8

To put things in perspective,According to the most recent estimates, in 2013, 10.7 percent of the world’s population lived on less than US$1.90 a day(http://www.worldbank.org/en/topic/poverty/overvie).Now for the learners falling in this spectrum using a GPU enabled instance is almost impossible when it costs almost half of what they earn in a day.

But some amazing news came in when kaggle introduced GPU enabled kernels which can be now used to learn and solve deep learning problems across the problem statements without need of hiring a GPU.

For all the learners who are a big fan of fastai which simplifies learning and practicing Deep learning ,This comes as one of the biggest gifts.

Lets quickly look at the steps needed to implement a fastai lesson using a kaggle kernel.

How to use kaggle kernel if learning fastai

Step-1 Go to kaggle and fire up a new kernel

Step-2 Make the kernel GPU enabled(you will see options atthe bottom right hand side of the screen)

Step-3 The kaggle kernels don’t have fastai repo installed so we need to do that ourself .Go to Add custom package and in the git hub repo paste github.com/fastai/fastai

Step-4 Import all required fastai tools needed for us to proceed

In this case I am using cat vs dog redux competition as the baseline competition to try out if fastai will be usable on kaggle kernels.Also the plan is to use Resnet34 for transfer learning hence the next step for us is to get the data of the competition and the pre-trained weights of Resnet34

Step-5 Get the data to the kernel and also add the pretrained weights for your usage

On the centre of the right control pane of your kernel you will find an option called **“Add dataset”.**This is what you need to get the data of the competition and the pre-trained weights of the network that we have decided to proceed with.

Data for cat vs Dogs Redux(get from add datasets →competitions)

Get weights of Resnet-34(Add datasets->datasets)

We are all set now with the GPU environment setup, fastai library loaded ,competition images loaded and also we have added pretrained weights of Resnet34.Lets move ahead and develop a quick deep learning model using fastai library.

Step-5 Load up all important fastai tool kits needed

Step-6 In the data input library we have two folders train and test with images of cats and dogs in them.One of the ways to create an image data for training the deep learning model is we get details and labels of training data in a csv and use that as a reference.We will do exactly that.

Step-7 Now after the above step we will have details of the training data as a csv stored.Now lets create the validation index and proceed with creating a model data object.

Step-8 Fastai training code expects the pre-trained weights of networks we are using in specific folders within our development environment.The below steps do exactly that.

Step-9 Lets precompute the weights of the model and find the learning rates using the learning rate finder

Step10-We are now done with a quick baseline training but what if we now want to get the predictions in a csv and we want to do that without committing the whole kernel.Below code gets that done.

Get predictions for the test data

Get a download link straight from the data-frame of test predictions

Conclusion

I was able to develop a Deep learning model for one of the most popular problem statements in computer vision(Object identification) using one of my most favoraite libraries (fastai) at zero cost.Google had google colab previously which also had GPU enabled infrastructure to use but somehow i found it too slow and too unstable to get concrete learning done.But Kaggle kernels in their current form should be probably used as learning environments as well as for development.

Acknowledgments

I referenced below two kernels by Anshul Rai and Rachael Tatman while trying to solve few quirks in the problem that I was trying to solve.

Using fastai in Kaggle Kernel_Edit description_www.kaggle.com

Download a .csv file from a kernel | Kaggle_Edit description_www.kaggle.com


Published by HackerNoon on 2018/07/29