<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ravi Vijayakumar on Medium]]></title>
        <description><![CDATA[Stories by Ravi Vijayakumar on Medium]]></description>
        <link>https://medium.com/@thehiphopswami?source=rss-e4b10e03ad32------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*KSXGgUccDVb7wedp.jpeg</url>
            <title>Stories by Ravi Vijayakumar on Medium</title>
            <link>https://medium.com/@thehiphopswami?source=rss-e4b10e03ad32------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:53:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thehiphopswami/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SpiderMan Vs Deadpool: Toy Learning on a Mac with 200 images in few minutes]]></title>
            <link>https://medium.com/@thehiphopswami/spiderman-vs-deadpool-fastai-on-a-mac-with-200-images-in-few-minutes-b050cba24832?source=rss-e4b10e03ad32------2</link>
            <guid isPermaLink="false">https://medium.com/p/b050cba24832</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Ravi Vijayakumar]]></dc:creator>
            <pubDate>Wed, 29 Nov 2017 02:04:06 GMT</pubDate>
            <atom:updated>2017-11-30T03:21:18.584Z</atom:updated>
            <content:encoded><![CDATA[<p>Here, I attempt to excite beginners like me by breaking few myths about deep learning that act as barriers from playing. Fastai Framework makes it easy.</p><p>Code is here: <a href="https://github.com/RaviVijay/toylearning/blob/master/Spiderman_vs_Deadpool.ipynb">https://github.com/RaviVijay/toylearning/blob/master/Spiderman_vs_Deadpool.ipynb</a></p><p>Main credit goes to <a href="https://medium.com/u/34ab754f8c5e">Jeremy Howard</a> and <a href="https://medium.com/u/ee56d0bac1b7">Rachel Thomas</a> who have an amazing teaching philosophy and have created a <a href="http://forums.fast.ai/">godawesome community</a>. This post is inspired from <a href="https://medium.com/u/1629686e65cf">Nikhil B</a>’s Fun with small datasets blogposts. The model’s are built using fastai framework created by <a href="https://medium.com/u/34ab754f8c5e">Jeremy Howard</a> and scripts to modify data are from the community. Toy learning problem: Mine.</p><h3>Myths</h3><p>Few myths I had which stopped me from getting to really play with deep-learning:</p><ol><li>Read the deep learning book before building anything</li><li>It’s arduous to download, organize and load even simple datasets</li><li>You need extremely fast GPUs or spend a fortune on cloud to get anything done</li><li>You need to master frameworks and need to code a lot to get them working</li><li>You cannot learn anything worthwhile by doing deep learning on small datasets.</li></ol><p>We will use transfer learning(discussed later) on small datasets and you’ll see these myths broken one by one along the way.</p><h3>Problem Statement</h3><p>I wanted a small funky problem that I can mention to my colleagues at lunch. Like hotdog classification or Nikhil’s examples. Superhero classification sounded exciting. For this post, to keep it simple, I classify between 2 of them: Spiderman and Deadpool.</p><p><strong>Initial Intuition about our problem: </strong>Spiderman and Deadpool look similar and this may confuse our NN . We can learn it’s behavior by observing it’s mistakes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*Bo1JzkIvFl069ZWqc-ylYA.png" /><figcaption>Spiderman Vs Deadpool</figcaption></figure><h3>Dataset</h3><p>Generally the <strong>driest part of the job</strong> once you have a cute idea is collecting the data. I saw below content in <a href="https://medium.com/@nikhil.b.k_13958/fun-with-small-image-data-sets-part-2-54d683ca8c96">Nikhil’s post</a> and jumped:</p><blockquote>“To do this, I used a nifty little script by <a href="https://github.com/hardikvasa/google-images-download">Hardikvasa</a>. This is a Python program to search keywords/key-phrases on Google Images and optionally download all Images.”</blockquote><p>and immediately started to work on this Toy Learning problem</p><blockquote>git clone <a href="https://github.com/hardikvasa/google-images-download">https://github.com/hardikvasa/google-images-download</a></blockquote><p>modify the line 21 of google-images-download.py to</p><blockquote>search_keyword = [“deadpool”, “spiderman”]</blockquote><p>modify the line 24 of google-images-download.py to</p><blockquote>keywords = [‘ ’]</blockquote><p>3 minutes. <strong>Boom!</strong> Our small dataset of 100 deadpool images and 100 spiderman images is downloaded, organized by category and ready to be uploaded into our python script.</p><p><strong>Myth Broken</strong> : <strong>3. It’s arduous to download, organize and load even simple datasets</strong></p><p>Let’s get the ipython notebook code next.</p><h3>Step0 : Install fastai framework:</h3><p><em>pip install fastai</em></p><h3>Imports:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*uHan6zNIUq3OiVR0nK1Drg.png" /><figcaption>fastai imports</figcaption></figure><h3>DataPrep for Neural Network:</h3><p>We have already data organized under categories ready. But deep learning requires data to be split in 3 sets:</p><ol><li>Training data: Like the homework problems we solve to understand a concept. You keep solving many of them to learn it.</li><li>Validation data: Like final exams we take to judge our understanding. If we fail here, start studying homework problems with a different approach.</li><li>Test data: Problems you will see once join work. You studied for this. If you see something out of the blue and are not ready, your training and validation methods were’nt good enough. Go back to school.</li></ol><p>For our “Toy Learning” problem, we can live with studying training and validation sets and do not need a test set. If any of you challenge my model with a new image of spiderman/deadpool, that will be the test set.</p><p>Fastai Framework lets you keep all training and validation data in the same directory and provide a csv file mentioning the categories. Below custom code does data movement and csv creation required by fastai framework:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tOBGaR6FhAc8JyjkuFZ8CA.png" /></figure><p>Once a csv is ready, below fastai framework code will consume them and do all transforms and augmentation on the input data.</p><p>Data Augmentations are similar to the twists professors give to homework problems to help you think about the concepts from different angles. Otherwise you will follow the textbook rigidly and end up rote learning.</p><p>Data Transformations is giving the data to neural net in a format it understands. It’s like converting jpg to png to a program that takes only png.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*is4IUleAQfY3rYSeXh5rlg.png" /></figure><h3>Transfer Learning</h3><p>Transfer learning is a technique to use a pretrained neural net architecture that has learnt a lot on a much bigger problem and ask it to learn a smaller problem quickly and give us reliable solution. It is like a C++ network programming guru who learns python over a weekend to automate simple stuff. He has tackled much tougher problems and has general techniques in his kitty. When given a new toy problem, he can to explore it quickly and then solve it reliably.</p><h3>Code for Transfer learning:</h3><p>Now that data is ready, let’s feed it to neural net. 2 things are fed to a neural network and we ask it take a guess in 2 minutes.</p><ol><li>Data augmented+transformed</li><li>Pretrained Learner</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*E6E5iiCPQIpBXEXqJWW2wA.png" /><figcaption>1. Feed NN-arch. and data. 2. Go Learn</figcaption></figure><p><strong>After 3 minutes. Boom:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*5d6-Qr_yRegb4uWKjikoWg.png" /></figure><p>The last column says how accurate the result is: As in how many images in validate set did the learnt model guess accurately. In 2 lines of code and after 2 minutes the pretrained arch takes a <strong>new problem</strong> and guesses which image is spiderman and which is deadpool correctly 2/3 times. It has not even learnt about it enough to change it’s intuitions.</p><p>Myth Broken : <strong>You need to master frameworks and need to code a lot to get them working</strong></p><h3>Tuning</h3><p>Here we give the pretrained neural net more time and flexibility. It can change it’s weights(intuitions) slightly to tackle this problem more accurately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/1*IBRzK6TKXthqCdnfTchFxA.png" /><figcaption>Tune it further in</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*nV83EnbVbhmptdu8lpN2wg.png" /><figcaption>88% Accurate</figcaption></figure><p>This took ~10 minutes on my loaded CPU. In a GPU it would have taken 1 minute or so. But ~10 minutes it within my margin of multiplexing.</p><p>All of this was done on Mac which does not have a GPU. I did not have to rent AWS either. If you want to have fun with “Toy learning”, you can do it on a Mac but if your laptop has a decent Nvidia GPUs, even better!</p><p><strong>Myth Broken</strong>:<strong> 4. You need extremely fast GPUs or spend a fortune on cloud to get anything done</strong></p><p><strong>But</strong>: That said, as the problems become more complicated, GPUs are absolutely required for compute. To learn concepts and get an initial understanding of data, GPUs are not required. Once you have grokked the data, run models with sample data, you can rent GPUs and use them solely for computation instead of wasting hours studying data on it.</p><h3>Data Analysis</h3><p>For this “Toy Problem”, I know the structures of data, hence I have this explained here. For more advanced problems, this step will come before and you learn the neural net or after asking it to make the first guess. This is the critical step in the whole process.</p><p>Once training is done and you are satisfied with validation accuracy, we run final predictions with data augmentation applied on validation dataset:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*kjIP5dUdR_mzrjQZ1oXMcw.png" /></figure><p>Lets look at some predictions. Probabilities &gt;0.5 are predicted as spiderman and &lt;0.5 is deadpool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*V-OYgMCmvXm-2td8v1fr4g.png" /><figcaption>Correctly Predicted as spiderman</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*xK62pIRKs3_njzO0Pc8gGA.png" /><figcaption>Correctly predicted as Deadpool</figcaption></figure><p>But looking at it’s mistakes gives us an understanding of how it works and where it breaks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*aYI44wLUKc3r70syG4abVw.png" /><figcaption>Incorrectly classified</figcaption></figure><p>Let’s go one by one.</p><ol><li>First image is clearly spiderman but it predicts it as deadpool. Maybe if we tune it further or feed it more data, it may get better</li><li>Clearly our neural network is illiterate by human standards. It is clearly written there: “Deadpool”. Jokes aside, we can understand that it is very unclear for it to decide either way since it looks like both</li><li>This image has both spiderman and deadpool but was categorised it as deadpool in our dataset. NN says, “Not my problem” and we have to agree</li><li>WTF is that ? Again it is very confusing like 3.</li></ol><p>We clearly were able to read the intuitions of the NN even with a small toy problem. We should also be able to test the efficacy of optimizers like SGD, ADAM etc. on this problem.</p><p><strong>Myth Broken: 5. You cannot learn anything worthwhile by doing deep learning on small datasets.</strong></p><p>And we did not need to understand all the concepts behind NN for geeking out on super heros.</p><p><strong>Myth Broken: 1. Read the deep learning book before building anything</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b050cba24832" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>