<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abhishek M Kori</title>
    <description>The latest articles on DEV Community by Abhishek M Kori (@abhishekori).</description>
    <link>https://dev.to/abhishekori</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2161%2F01803e79-a356-4369-8ae6-e79526505f54.jpg</url>
      <title>DEV Community: Abhishek M Kori</title>
      <link>https://dev.to/abhishekori</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhishekori"/>
    <language>en</language>
    <item>
      <title>Rock Paper Scissor classifier using fast AI and restnet 34 pretrained model</title>
      <dc:creator>Abhishek M Kori</dc:creator>
      <pubDate>Sun, 18 Aug 2019 07:07:50 +0000</pubDate>
      <link>https://dev.to/abhishekori/rock-paper-scissor-classifier-using-fast-ai-and-restnet-34-pretrained-model-gg7</link>
      <guid>https://dev.to/abhishekori/rock-paper-scissor-classifier-using-fast-ai-and-restnet-34-pretrained-model-gg7</guid>
      <description>&lt;h2&gt;
  
  
  We will be executing the below code in &lt;a href="https://colab.research.google.com"&gt;https://colab.research.google.com&lt;/a&gt; notebook
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Step1: Import fast ai vision library
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
from fastai.vision import *&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Create a path and directory
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
path = Path('data/rps')&lt;br&gt;
path.mkdir(parents=True, exist_ok=True)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Download the kaggle json file from your kaggle profile and and upload it to current directory (/content)
&lt;/h2&gt;

&lt;h2&gt;
  
  
  Step 4: Copy the kaggle json to ~/.kaggle
&lt;/h2&gt;

&lt;p&gt;change the file permissions&lt;br&gt;
download the drgfreeman/rockpaperscissors dataset&lt;br&gt;
&lt;code&gt;&lt;br&gt;
!mkdir ~/.kaggle&lt;br&gt;
!cp kaggle.json ~/.kaggle/&lt;br&gt;
!chmod 600 ~/.kaggle/kaggle.json&lt;br&gt;
!kaggle datasets download -d drgfreeman/rockpaperscissors&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Copy the dataset to data/rps/ dir and unzip it
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
!cp rockpaperscissors.zip data/rps/rockpaperscissors.zip&lt;br&gt;
!unzip data/rps/rockpaperscissors.zip -d data/rps&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Create ImageDataBunch bunch object which will
&lt;/h2&gt;

&lt;p&gt;Create train and validation dataset&lt;br&gt;
get_tranforms will get the default tranformations to add variety to the dataset. It might crop the image, tilt the image or skew it littlebit etc..&lt;br&gt;
valid_pct is 0.2 ie 80% train 20% test&lt;br&gt;
Image size of 224 pixels&lt;br&gt;
Normalize the pixels according imagenet statistics to avoid values going nuts!&lt;br&gt;
&lt;code&gt;&lt;br&gt;
np.random.seed(42)&lt;br&gt;
data = ImageDataBunch.from_folder(path, train=".", valid_pct=0.2,ds_tfms=get_transforms(), size=224, num_workers=4).normalize(imagenet_stats)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Lets see how our dataset looks
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
data.show_batch(rows=3, figsize=(7,8))&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Explore the data bunch object to see the number of classes, length of datasets
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
data.classes, data.c, len(data.train_ds), len(data.valid_ds)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: Lets create a CNN learner by passing in databunch object , restnet 34 pre tranined model (which the fast AI lib will download for us) and tell the trainer that we are inerested in error_rate as the metrics to meseaure
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
learn = cnn_learner(data, models.resnet34, metrics=error_rate)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 8: Lets try to fit the model by calling fit_one_cycle.
&lt;/h2&gt;

&lt;p&gt;This method accepts integer which will tell the learner how many times does it should see our data. In our case we will do for 4 times.&lt;br&gt;
Each time it sees the our data it will learn few features&lt;br&gt;
If we increase the number of cycles we might try to over fit the model to our dataset. We want it to just learn the general features of our images&lt;br&gt;
&lt;code&gt;&lt;br&gt;
learn.fit_one_cycle(4)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Lets analyze our metrics
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;epoch&lt;/strong&gt;: Going through one cycle of all classes of data&lt;br&gt;
&lt;strong&gt;train_loss&lt;/strong&gt;: Difference between the predicted value and actual ground truth in traning dataset&lt;br&gt;
&lt;strong&gt;valid_loss&lt;/strong&gt;: Difference between the predicted value and actual grounf truth in validation dataset&lt;br&gt;
&lt;strong&gt;error_rate&lt;/strong&gt;: number of predictions that are wrong.&lt;br&gt;
You can see that train loss is greater than validation loss because while traning it does not have the information about the image. As it learns about the features it tries to test its capability against the validation set. So as you can predict when running against validation set, it does have some idea about the image and performs better compare to traning set&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 9: Lets save our model!
&lt;/h2&gt;

&lt;p&gt;it creates a pth file in models directory&lt;br&gt;
&lt;code&gt;&lt;br&gt;
learn.save('stage-1')&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 10: Now we will draw some insights from our trained model
&lt;/h2&gt;

&lt;p&gt;ClassificationInterpretation.from_learner will give generate some insights.&lt;br&gt;
&lt;code&gt;&lt;br&gt;
interp = ClassificationInterpretation.from_learner(learn)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;lets see for which images our model went wrong and why?&lt;br&gt;
As you can see the predicted , actual, loss and what was the probability of the predicted class.&lt;/p&gt;

&lt;p&gt;You can also notice bottom 2 images it predicted the classes correctly but with low confidence&lt;br&gt;
&lt;code&gt;&lt;br&gt;
interp.plot_top_losses(4, figsize=(15,11))&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Lets explore out confusion matrix which tells us about exact number of correct and incorrect predictions&lt;br&gt;
In our example we had 2 incorrect predictions&lt;/p&gt;

&lt;p&gt;It predicted rock but it was a paper&lt;br&gt;
it predicted paper but it was a rock&lt;br&gt;
And you can see those incorrect predictions above in plot top losses. With this data you can further clean your data and tweak your model to get the best results&lt;br&gt;
&lt;code&gt;&lt;br&gt;
interp.plot_confusion_matrix(figsize=(12,12), dpi=60)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Most confused prints the exact classes which it was not able to predict&lt;br&gt;
&lt;code&gt;&lt;br&gt;
interp.most_confused()&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
lets unfreesze our model and experiment a bit&lt;br&gt;
What does it mean by unfreeze? Well till now we just tranied our last few layers of the existed pre tranined model. unfeeze will help us train all the layes of the model.&lt;br&gt;
&lt;code&gt;&lt;br&gt;
learn.unfreeze()&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Train all the layers of our model&lt;br&gt;
As you can see this was a bad idea. The train loss , valid loss and error rate is much higher for 1 epoc when train all the layer than only last few layers.&lt;br&gt;
This is because you are asking the model to re learn all the minute features of an image. It better to leave as it is because the pre trained model is good edges and small shapes which are common for all kinds of images.&lt;br&gt;
Telling it to relearn all those features by our limited expertise and data is not suited.&lt;br&gt;
&lt;code&gt;&lt;br&gt;
learn.fit_one_cycle(1)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 11: Lets load back our saved model and try to find the learning rate
&lt;/h2&gt;

&lt;p&gt;Learning rate is the change in step size during Stochastic gradient descent.&lt;br&gt;
We will observe how the loss changes&lt;br&gt;
&lt;code&gt;&lt;br&gt;
learn.load('stage-1');&lt;br&gt;
learn.lr_find()&lt;br&gt;
learn.recorder.plot()&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;From the graph we can see that after the learning rate power of 3 it shoots. So good rule of thumb is to retrain the model 10 times lower as the upper limit&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 12: Now lets re train our model with controlled learning rate between 10 to the power -06 to -04
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
learn.fit_one_cycle(2, max_lr=slice(1e-6,1e-4))&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 13: Lets save our final model
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
learn.save('rock-paper-scissors-1')&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Time to test!
&lt;/h2&gt;

&lt;p&gt;I have a taken an image of my hand , removed the background and replaced with green screen. Use this tool &lt;a href="https://www.remove.bg"&gt;https://www.remove.bg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&lt;br&gt;
img = open_image('/content/sci-removebg-preview.png')&lt;br&gt;
img&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;code&gt;&lt;br&gt;
learn.predict(img)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is a small tutorial of transfer learning by taking existing pre trained model and re train it for your use case.&lt;/p&gt;

&lt;p&gt;Fast AI library is really good for programmers and I strongly recommend. I learnt this concept from this lesson. For more &lt;a href="https://course.fast.ai/"&gt;https://course.fast.ai/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to experiment it your, self check this jupyter notebook and run it on &lt;a href="https://colab.research.google.com"&gt;https://colab.research.google.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Make sure you change the runtime type GPU&lt;/p&gt;

&lt;p&gt;Its time for you to try !&lt;/p&gt;

&lt;p&gt;&lt;a href="https://gist.github.com/abhishekori/4e4697ba7cb7d2b49fece674ce31cc00"&gt;https://gist.github.com/abhishekori/4e4697ba7cb7d2b49fece674ce31cc00&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me know what you think &amp;lt;3&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>restnet34</category>
      <category>python</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Basic introduction to Big data</title>
      <dc:creator>Abhishek M Kori</dc:creator>
      <pubDate>Sun, 16 Jun 2019 11:34:10 +0000</pubDate>
      <link>https://dev.to/abhishekori/basic-introduction-to-big-data-4ap5</link>
      <guid>https://dev.to/abhishekori/basic-introduction-to-big-data-4ap5</guid>
      <description>&lt;h1&gt;
  
  
  Basic introduction to Big data
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zVZEjoNC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0x0kyfw5th26yw1up82x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zVZEjoNC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/0x0kyfw5th26yw1up82x.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Apache Hadoop?
&lt;/h2&gt;

&lt;p&gt;“Apache Hadoop is an open source a software framework for storage and &lt;br&gt;
large scale processing of data-sets on clusters of commodity hardware”&lt;/p&gt;

&lt;p&gt;The most significant part about this is the power of large scale data processing on commodity hardware aka your regular server in a rack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding distributed computing
&lt;/h2&gt;

&lt;p&gt;I like to understand the above concept by drawing an analogy of how elections or collection of senses data works in a country.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each district or a constituency has a polling booth where people come and cast their vote.&lt;/li&gt;
&lt;li&gt;At the end of the election, each ballot box(EVM machine) is tasked to add all the votes for each candidate.&lt;/li&gt;
&lt;li&gt;Data from each ballot box from different polling stations is added together to find the final tally of votes for a particular political party
You can see how we can use this concept to do large scale computation with our data. We store our single file, in chunks in multiple servers. Whenever there is some calculation which needs to be done, we can do that on each server and collect the result. The results from each server are again processed to get the final result. This is the core concept of distributed computing&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Features of Hadoop
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Open source: Apache licence&lt;/li&gt;
&lt;li&gt;Highly Scalable: By adding new nodes and removing depending on demand&lt;/li&gt;
&lt;li&gt;Usage of commodity hardware&lt;/li&gt;
&lt;li&gt;Reliable: Replication of data and compute among multiple nodes&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Apache framework Hadoop modules
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Hadoop Common&lt;/li&gt;
&lt;li&gt;Hadoop Distributed File System 
(HDFS)&lt;/li&gt;
&lt;li&gt;Hadoop YARN&lt;/li&gt;
&lt;li&gt;Hadoop MapReduce&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s study each of the concepts one by one&lt;/p&gt;

&lt;h2&gt;
  
  
  Hadoop Distributed File System
&lt;/h2&gt;

&lt;p&gt;(HDFS)&lt;br&gt;
HDFS is a file system on distributed nodes. It is synonymous to a usual file system on your personal computer but the underlying data is distributed across multiple server nodes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Name node
&lt;/h3&gt;

&lt;p&gt;As we know that our files are broken into chunks and stored across multiple servers to co-ordinate among the multiple servers in our cluster we have a concept called “Name node”.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data node
&lt;/h3&gt;

&lt;p&gt;Data nodes are servers which store the data and do the computation&lt;/p&gt;

&lt;h2&gt;
  
  
  Map reduce Engine
&lt;/h2&gt;

&lt;p&gt;Map reduce is a programming model to do computation on a distributed parallel computing environment&lt;/p&gt;

&lt;h3&gt;
  
  
  Map: map task conducts the data processing on each data node
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Reduce: reduce task collects the results from all the map task and reduce it to single results.
&lt;/h3&gt;

&lt;p&gt;The business logic of what the map or reduce task should do is given by the programmer&lt;/p&gt;

&lt;h3&gt;
  
  
  Job tracker : Job tracker is a process in name node which gets the job from the client
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Task tracker: task tracker are the processes which reside in the data nodes. They take care of carrying out the process of their respective nodes.
&lt;/h3&gt;

&lt;p&gt;You can submit your jobs to the name node (job tracker) which schedules and tracks all the jobs&lt;/p&gt;

&lt;p&gt;Each data node receives the tasks from job tracker, and it’s the job of the task tracker for conducting and tracking the assigned task. It reports the status of its task back to Job tracker&lt;/p&gt;

&lt;p&gt;This was a basic uderstanding of the hadoop stack to carry out big data operation. As i explore into this field i will be posting more content on this subject.&lt;/p&gt;

&lt;p&gt;let me know your thoughts on these mamoth data porcessing softwares.&lt;/p&gt;

</description>
      <category>bigdata</category>
      <category>hadoop</category>
    </item>
  </channel>
</rss>
