<?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 Annamraju</title>
    <description>The latest articles on DEV Community by Abhishek Annamraju (@abhishek4273).</description>
    <link>https://dev.to/abhishek4273</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%2F127552%2Fc61c0448-e866-4f07-8976-6c0f26d32a00.jpg</url>
      <title>DEV Community: Abhishek Annamraju</title>
      <link>https://dev.to/abhishek4273</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abhishek4273"/>
    <language>en</language>
    <item>
      <title>Ensemble of classifiers using Monk: Creating a food classifier</title>
      <dc:creator>Abhishek Annamraju</dc:creator>
      <pubDate>Tue, 03 Dec 2019 11:23:39 +0000</pubDate>
      <link>https://dev.to/abhishek4273/ensemble-of-classifiers-using-monk-creating-a-food-classifier-lco</link>
      <guid>https://dev.to/abhishek4273/ensemble-of-classifiers-using-monk-creating-a-food-classifier-lco</guid>
      <description>&lt;p&gt;TLDR;&lt;br&gt;
&lt;a href="https://drive.google.com/file/d/1ELNkFaMqEU_xOYG1V80vqc0WQJeSaGQO/view?usp=sharing&amp;amp;source=post_page-----ccc215b283ff----------------------"&gt;Colab Notebook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  What will you build!
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GIij0zgG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://miro.medium.com/max/300/1%2AykiHyGErizGRhBGxileQKA.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GIij0zgG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://miro.medium.com/max/300/1%2AykiHyGErizGRhBGxileQKA.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this post we will make 3 levels of Food Classification models :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Classify input image as Food vs Non Food&lt;/li&gt;
&lt;li&gt;Classify an input image of Food into 11 super categories&lt;/li&gt;
&lt;li&gt;Classify an input image of Food as one of 101 dishes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And finally combine the 3 projects into one Food Classification application.&lt;/p&gt;

&lt;p&gt;Let’s begin!&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;We start by setting up Monk and it’s dependencies on colab. For further setup instructions on different platforms check out the &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/setup/setup"&gt;DOCS&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/Tessellate-Imaging/monk_v1
$ cd monk_v1/installation &amp;amp;&amp;amp; pip install -r requirements_cu10.txt
$ cd ../..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Setup the dependencies based on the platform you are working with. Monk is compatible with Ubuntu, MacOS, Windows and online Jupyter environments like Kaggle and Colab.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h2&gt;
  
  
  Project 1 : Food vs Non Food Classification
&lt;/h2&gt;

&lt;p&gt;Let’s create our first project for classifying an input image into food or non food categories. The goal of this project is solely to determine if a food item is present in the input image and can be further classified into a super and sub category.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Start Experiment 1
&lt;/h3&gt;

&lt;p&gt;Import monk library&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import sys
sys.path.append("./monk_v1/monk/");
import psutil
from pytorch_prototype import prototype
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and create a new experiment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1);
ptf.Prototype(“food_nonfood”, “exp1”);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Dataset
&lt;/h3&gt;

&lt;p&gt;For this project we are using the Food-5k dataset.&lt;/p&gt;

&lt;p&gt;“This dataset contains 2500 food and 2500 non-food images, for the task of food/non-food classification from the paper “Food/Non-food Image Classification and Food Categorisation using Pre-Trained GoogLeNet Model”. The whole dataset is divided in three parts: training, validation and evaluation. The naming convention is as follows:&lt;/p&gt;

&lt;p&gt;{ClassID}_{ImageID}.jpg&lt;/p&gt;

&lt;p&gt;ClassID: 0 or 1; 0 means non-food and 1 means food.”&lt;/p&gt;

&lt;p&gt;For our project we will combine the training, validation and evaluation sets into one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from glob import glob
import os
import shutil
from tqdm import tqdmfolders = glob("./food-5k/*")food_dir = './food-5k/food'
non_food_dir = './food-5k/non-food'
if not os.path.exists(food_dir):
    os.makedirs(food_dir)
if not os.path.exists(non_food_dir):
    os.makedirs(non_food_dir)c = 1
n_c = 1
for i in folders:
    imageList = glob(i + '/*.jpg')
    print(len(imageList))
    for j in tqdm(imageList):
        imgName = j.split('/')[-1]
        label = imgName.split('_')[0]
        if label == '0':
            outPath = non_food_dir + '/' + str(n_c) + '.jpg'
            n_c += 1
        elif label == '1':
            outPath = food_dir + '/' + str(c) + '.jpg'
            c += 1
        shutil.move(j,outPath)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we can load our dataset, select our CNN architecture to train and set the number of epochs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Default(dataset_path="./food-5k/", model_name="resnet18", freeze_base_network=True, num_epochs=5)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And begin training :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After training is finished we can observe the loss and accuracy plots stored inside &lt;strong&gt;workspace&amp;gt;”project_name”&amp;gt;”exp_name”&amp;gt;output&amp;gt;logs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1yNGUk_K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2Akwa1nfPzgCGvat85YhLk5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1yNGUk_K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2Akwa1nfPzgCGvat85YhLk5g.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;accuracy plot for food_nonfood experiment 1&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let’s create a new experiment with a different CNN architecture and see if we can achieve better performance.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Start Experiment 2
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1);
ptf.Prototype(“food_nonfood”, “exp2”);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;We can check the available models using :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.List_Models()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our experiment 1 was created using &lt;em&gt;‘resnet18’&lt;/em&gt;. For experiment 2 we will select &lt;em&gt;‘resnet101’&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;By using residual networks, many problems can be solved such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ResNets are easy to optimize, but the “plain” networks (that simply stack layers) shows higher training error when the depth increases.&lt;/li&gt;
&lt;li&gt;ResNets can easily gain accuracy from greatly increased depth, producing results which are better than previous networks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To know more about ResNet architectures check out this &lt;a href="https://neurohive.io/en/popular-networks/resnet/"&gt;post&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Default(dataset_path=”./food-5k/”, 
            model_name=”resnet101", 
            freeze_base_network=True, num_epochs=5);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For experiment 2 we will unfreeze a few more layers from our pre-trained model to make them available for training. We also increase the number of epochs and reload the experiment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.update_freeze_layers(100);
ptf.update_num_epochs(30);
ptf.Reload()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And finally train the model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once again we can observe the loss and accuracy plots for this experiment:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eeeC8RTl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2A5taQKqeZKCNwKPNlD-aoYw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eeeC8RTl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2A5taQKqeZKCNwKPNlD-aoYw.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;accuracy plot for food_nonfood classifier experiment 2&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Comparison&lt;/p&gt;

&lt;p&gt;We can compare the two experiments for training and validation accuracies and losses. (Check out &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/compare_experiment"&gt;DOCS&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from compare_prototype import compare
ctf = compare(verbose=1);
ctf.Comparison("food_nonfood");
ctf.Add_Experiment("food_nonfood", "exp1");
ctf.Add_Experiment("food_nonfood", "exp2");
ctf.Generate_Statistics();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HZgci65Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AkvuIbfkg-xL1nn8EiyFogg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HZgci65Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AkvuIbfkg-xL1nn8EiyFogg.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s test our model on food and non_food images.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Inference
&lt;/h3&gt;

&lt;p&gt;First we load the experiment in evaluation mode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Prototype(“food_nonfood”, “exp2”, eval_infer=True);
img_name = “./test.jpg”;
predictions = ptf.Infer(img_name=img_name, return_raw=False);
print(predictions);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hzh1vkO3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/5760/1%2Akd7pJ9qzH48zZ3F9Vr6WMg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hzh1vkO3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/5760/1%2Akd7pJ9qzH48zZ3F9Vr6WMg.jpeg" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prediction
    Image name:         ./test.jpg
    Predicted class:      food
    Predicted score:      4.16873025894165

{'img_name': './test.jpg', 'predicted_class': 'food', 'score': 4.1687303}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h2&gt;
  
  
  Project 2 : Food-11 Classification
&lt;/h2&gt;

&lt;p&gt;Now that we can classify input image as food or nonfood, we shall begin with classifying food images into different categories of dishes.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Dataset
&lt;/h3&gt;

&lt;p&gt;For this project we will utilise &lt;a href="https://mmspg.epfl.ch/downloads/food-image-datasets/"&gt;Food-11&lt;/a&gt; dataset.&lt;/p&gt;

&lt;p&gt;“This dataset contains 16643 food images grouped in 11 major food categories. The 11 categories are Bread, Dairy product, Dessert, Egg, Fried food, Meat, Noodles/Pasta, Rice, Seafood, Soup, and Vegetable/Fruit. Similar as Food-5K dataset, the whole dataset is divided in three parts: training, validation and evaluation. The same naming convention is used, where ID 0–10 refers to the 11 food categories respectively.”&lt;/p&gt;

&lt;p&gt;We will combine the training, evaluation and validation folders into one set of images and split them into respective class folders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;classes = {'0':'Bread','1':'Dairy_Product','2':'Dessert','3':'Egg','4':'Fried_Food','5':'Meat','6':'Noodles_Pasta','7':'Rice','8':'Seafood','9':'Soup','10':'Vegetable_Fruit'}from glob import globfolders = glob("./food-11/*")
print(folders)import osfor k,item in classes.items():
    directory = './food-11/' + item
    if not os.path.exists(directory):
        os.makedirs(directory)import shutil
from tqdm import tqdmc = 1
for i in folders:
    imageList = glob(i + '/*.jpg')
    #print(len(imageList))
    for j in tqdm(imageList):
        imgName = j.split('/')[-1]
        label = imgName.split('_')[0]
        outPath = './food-11/' + classes[label] + '/' + str(c) + '.jpg'
        c += 1
        shutil.move(j,outPath)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Start Experiment 1
&lt;/h3&gt;

&lt;p&gt;We can now create a new project, start with our experiment and load our dataset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1);
ptf.Prototype("food-11", "exp1");
ptf.Default(dataset_path="./food-11/", 
            model_name="resnet101", 
            freeze_base_network=True, num_epochs=10)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For this experiment we are using Resnet101 as our pre-trained model. Finally we can begin training :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---DyJUJCX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2A37s-DSnnEHGo0wbTs3CBTw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---DyJUJCX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2A37s-DSnnEHGo0wbTs3CBTw.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Loss curves&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We can observe that after 10 epochs the model achieves an accuracy of ~ 75%. The validation loss was still going down and we can achieve better accuracy if we train for more epochs. Let’s try that out using &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/copy_experiment"&gt;Copy_Experiment&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Start Experiment 2
&lt;/h3&gt;

&lt;p&gt;We create the new experiment using the previous experiment 1 as a template and make a few updates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1)
ptf.Prototype("food-11", "exp2", 
              copy_from=["food-11", "exp1"]);

ptf.update_freeze_layers(100);
ptf.update_num_epochs(30);

ptf.Reload();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note : Don’t forget to reload the experiment with ‘ptf.Reload()’ after making &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/update_mode/update_dataset"&gt;updates to your experiment&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And now we can begin our training. Once training is complete we will compare the both the experiments and choose one to inference with.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Compare
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctf = compare(verbose=1);
ctf.Comparison("food-11");

ctf.Add_Experiment("food-11", "exp1");
ctf.Add_Experiment("food-11", "exp2");

ctf.Generate_Statistics();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JByGmuqU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AVoabo64c5AL6j6uzTLB_kA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JByGmuqU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AVoabo64c5AL6j6uzTLB_kA.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since we used Copy_Experiment the accuracy for experiment 2 for epoch 1 starts from a better value that experiment 1. We can also observe that we quickly reach saturation around 10 epochs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S1PH8KQr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AK5Qw8F_c2oerulQA4B4qUw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S1PH8KQr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AK5Qw8F_c2oerulQA4B4qUw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can also observe the validation accuracy keeps fluctuating. We can definitely choose to go ahead with experiment 2 model with considerably better training and validation performance.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Inference
&lt;/h3&gt;

&lt;p&gt;Our food-11 project model can classify an input food image into one of 11 top level food categories.&lt;/p&gt;

&lt;p&gt;Let’s test it on our waffles image!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hzh1vkO3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/5760/1%2Akd7pJ9qzH48zZ3F9Vr6WMg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hzh1vkO3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/5760/1%2Akd7pJ9qzH48zZ3F9Vr6WMg.jpeg" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'img_name': './test.jpg', 'predicted_class': 'Dessert', 'score': 27.722319}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The prediction comes out to ‘Dessert’!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h2&gt;
  
  
  Project 3 : Food-101 Classification
&lt;/h2&gt;

&lt;p&gt;Finally we move on to classifying the input image into exactly what we are looking at. In this project we will classify the image from out of 101 classes of food items.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Dataset
&lt;/h3&gt;

&lt;p&gt;For this experiment we will be utilising dataset gathered by these awesome researchers : &lt;a href="https://www.vision.ee.ethz.ch/datasets_extra/food-101/"&gt;LINK&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Citations at the bottom of the post.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;“This dataset contains 101 food categories, with 101'000 images. For each class, 250 manually reviewed test images are provided as well as 750 training images. On purpose, the training images were not cleaned, and thus still contain some amount of noise. This comes mostly in the form of intense colors and sometimes wrong labels. All images were rescaled to have a maximum side length of 512 pixels.”&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Start Experiment 1
&lt;/h3&gt;

&lt;p&gt;For this experiment we will utilise a denset201 pretrained model.&lt;/p&gt;

&lt;p&gt;We can create the experiment, load the dataset, select the pretrained architecture, set the number of epochs and begin training all in just 4 lines of code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1)
ptf.Prototype("food-101", "exp1")

ptf.Default(dataset_path="./food-101/images/", 
            model_name="densenet169", freeze_base_network=False,
            num_epochs=10)

ptf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After 10 epochs the training accuracy comes out to ~87% which is not bad to start out with.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QkCzQIuD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2AkrPnXfmWmq5c6cPSf40WWw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QkCzQIuD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2AkrPnXfmWmq5c6cPSf40WWw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s finally test our waffles input image and see the results.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Inference
&lt;/h3&gt;

&lt;p&gt;Let’s load up the experiment in evaluation mode and test on single image. Check out our Docs for running test on a batch of images.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hzh1vkO3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/5760/1%2Akd7pJ9qzH48zZ3F9Vr6WMg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hzh1vkO3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/5760/1%2Akd7pJ9qzH48zZ3F9Vr6WMg.jpeg" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{'img_name': './test.jpg', 'predicted_class': 'waffles', 'score': 74.87055}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;And guess what! The model predicts that the input image is of “Waffles”.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h2&gt;
  
  
  Food Classification Application
&lt;/h2&gt;

&lt;p&gt;Finally we will combine the 3 projects to create a Food Classification application, which can detect if an input image is of a food item and if yes then predict the super (out of 11) and sub (out of 101) category of the food.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import requests
import os
import sys
sys.path.append("./monk_v1/monk/");
import psutil
from pytorch_prototype import prototypedef saveImg(img_url):
    # URL of the image to be downloaded is defined as image_url 
    r = requests.get(img_url) # create HTTP response object 
    with open('test.jpg','wb') as f: 
        f.write(r.content)def classify(img_url):
    saveImg(img_url)
    img_name = './test.jpg'
    ptf1 = prototype(verbose=0)
    ptf1.Prototype("food_nonfood", "exp2", eval_infer=True);    predictions = ptf1.Infer(img_name=img_name, return_raw=False);    if predictions['predicted_class'] == "non_food":
        return "Input image does not contain food"
    else:
        ptf2 = prototype(verbose=0)
        ptf2.Prototype("food-11", "exp2", eval_infer=True);
        predictions = ptf2.Infer(img_name=img_name,  return_raw=False);    superLabel = predictions['predicted_class']    ptf3 = prototype(verbose=0)
        ptf3.Prototype("food-101", "exp1", eval_infer=True);
        predictions = ptf3.Infer(img_name=img_name, return_raw=False);    subLabel = predictions['predicted_class']    return "Input image is of category {}, and is actually {}.".format(superLabel,subLabel)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally to test the classification app run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;test_url = "https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/delish-keto-waffle-horizontal-034-1543784709.jpg"
output = classify(test_url)
print(output)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To test with a new image, update the test_url.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XSs6YJkE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/750/1%2A6piu-HjpGlponFwrjVHLtA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XSs6YJkE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/750/1%2A6piu-HjpGlponFwrjVHLtA.jpeg" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input image is of category Bread, and is actually pizza.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;That’s all for this post folks. Hope you enjoyed going through this.&lt;/p&gt;

&lt;p&gt;The trained models are available to download here as a workspace directory &lt;a href="https://docs.google.com/uc?export=download&amp;amp;id=1Bn3rAY5MmRiXCeY-qJnAxs_b7h-qAdfY"&gt;HERE&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The workspace folder is cross platform compatible. All you need to do is setup monk and paste the workspace in your working directory to be able to run inference.&lt;/p&gt;

&lt;p&gt;Do give us a star on &lt;a href="https://github.com/Tessellate-Imaging/monk_v1/"&gt;Github&lt;/a&gt; if you like what you see (All the haters of food get out!)&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

&lt;p&gt;References&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://neurohive.io/en/popular-networks/resnet/"&gt;https://neurohive.io/en/popular-networks/resnet/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.vision.ee.ethz.ch/datasets_extra/food-101/"&gt;https://www.vision.ee.ethz.ch/datasets_extra/food-101/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://mmspg.epfl.ch/downloads/food-image-datasets/"&gt;https://mmspg.epfl.ch/downloads/food-image-datasets/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@inproceedings{bossard14,
  title = {Food-101 -- Mining Discriminative Components with Random Forests},
  author = {Bossard, Lukas and Guillaumin, Matthieu and Van Gool, Luc},
  booktitle = {European Conference on Computer Vision},
  year = {2014}
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>deeplearning</category>
      <category>ensemble</category>
      <category>classification</category>
    </item>
    <item>
      <title>Quick Prototyping with Monk: Creating a sign language classifier</title>
      <dc:creator>Abhishek Annamraju</dc:creator>
      <pubDate>Tue, 03 Dec 2019 11:23:05 +0000</pubDate>
      <link>https://dev.to/abhishek4273/quick-prototyping-with-monk-creating-a-sign-language-classifier-3bg7</link>
      <guid>https://dev.to/abhishek4273/quick-prototyping-with-monk-creating-a-sign-language-classifier-3bg7</guid>
      <description>&lt;p&gt;TLDR;&lt;br&gt;
&lt;a href="https://colab.research.google.com/drive/1FWiathcbPx_DbBiWhH9WSC92WAylrhAG?source=post_page-----6850bc6fc4ea----------------------"&gt;Colab Notebook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Communication is an essence of human life. From ancient hieroglyphics to the 6500 languages spoken currently across the world, they all signify the importance of our ability to reach out to our fellow human beings.&lt;/p&gt;

&lt;p&gt;Even though the global literacy rate for all people aged 15 and above is 86.3%, there are only about 250 certified sign language interpreters in India, translating for a deaf population of between 1.8 million and 7 million. The wide disparity in population estimates exists because the Indian census doesn’t track the number of deaf people — instead, it documents an aggregate number of people with disabilities.&lt;br&gt;
(Source : &lt;a href="https://www.pri.org/stories/2017-01-04/deaf-community-millions-hearing-india-only-just-beginning-sign"&gt;https://www.pri.org/stories/2017-01-04/deaf-community-millions-hearing-india-only-just-beginning-sign&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  What will you build!
&lt;/h3&gt;

&lt;p&gt;In this blog post we build an American Sign Language classifier and try to automate the process of sign language translation.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;We start by setting up Monk and it’s dependencies on colab. For further setup instructions on different platforms check out the &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/setup/setup"&gt;DOCS&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/Tessellate-Imaging/monk_v1
$ cd monk_v1/installation &amp;amp;&amp;amp; pip install -r requirements_cu10.txt
$ cd ../..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Dataset
&lt;/h3&gt;

&lt;p&gt;We will utilise the ASL image dataset from Kaggle — &lt;a href="https://www.kaggle.com/grassknoted/asl-alphabet"&gt;LINK&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Training
&lt;/h3&gt;

&lt;p&gt;Next we will use Pytorch as our backend to create a new Project and use Resnet50 as our pre-trained model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1);
ptf.Prototype("asl", "exp1");
ptf.Default(dataset_path="./dataset/train", 
            model_name="resnet50", 
            freeze_base_network=True, num_epochs=10);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We train our model for 10 epochs and check the training and validation accuracy.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yolzg23N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2A2Cmj4404cRadG_ut3Wj6lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yolzg23N--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2A2Cmj4404cRadG_ut3Wj6lg.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Accuracy curves&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The plot shows that even though our training accuracy is lower, the model performs quite well on the validation set.&lt;/p&gt;

&lt;p&gt;The dataset is not diverse enough to create a generalised model.&lt;/p&gt;

&lt;p&gt;However further improvement can be achieved by using image augmentation strategies.&lt;/p&gt;

&lt;p&gt;Let’s put the model to test with a realtime video classification.&lt;/p&gt;

&lt;p&gt;*Note: A process automation pipeline for image or video processing requires much more than just a classification model. In our case we would require a hand detector to localise the position of hands within the frame, a hand tracker to reduce jitter from the hand detector and finally the sign language classifier. Even after setting up all the modules, the heuristics and dataset requirements would differ based on the application and deployment scenario. To give an example, the current classifier is built with a webcam dataset and will surely not work with AR headsets which have a different point of view.&lt;/p&gt;

&lt;p&gt;For this exercise we will set a region of interest within the frame where our hand must be placed for the model to determine the gestures.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Realtime Gesture Classification
&lt;/h3&gt;

&lt;p&gt;We begin by loading our experiment in evaluation mode.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import sys
sys.path.append(“./monk_v1/monk/”);
import psutil
from pytorch_prototype import prototype
from imutils.video import VideoStream
import cv2ptf = prototype(verbose=1)
ptf.Prototype(“asl”, “exp1”, eval_infer=True);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We capture a video stream from our webcam, set a region of interest within the frame and store it in a file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if __name__ == ‘__main__’:
  vs = VideoStream().start()
  im_height, im_width = (None, None)
  while True:
    # Read Frame and process
    frame = vs.read()
    frame = cv2.resize(frame, (640, 480))
    frame = cv2.flip( frame, 1 )    #Set ROI
    cv2.rectangle(frame, (350,50), (600,300), (255,0,0) , 3, 1)    roi = frame[50:300,350:600]    roi = cv2.cvtColor(roi, cv2.COLOR_BGR2RGB)
    cv2.imwrite(“roi.jpg”,roi)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next we load the ROI image and infer using our classification model generated with Monk and display the predicted class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    predictions = ptf.Infer(img_name=”roi.jpg”, return_raw=False);

    cv2.putText(frame, predictions[‘predicted_class’],(350,40),cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0), 2)

    cv2.imshow(‘ASL’, cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))

    if cv2.waitKey(25) &amp;amp; 0xFF == ord(‘q’):
      cv2.destroyAllWindows()
      vs.stop()
      break
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The model performs fairly well in proper lighting conditions. In the following video I try to write the word “MONK” using hand gestures.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vcvZ0O-f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://tessellate-pytorch-serverless.s3.amazonaws.com/asl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vcvZ0O-f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://tessellate-pytorch-serverless.s3.amazonaws.com/asl.gif" alt="Sign language Classification"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;

&lt;h3&gt;
  
  
  Coming Soon!
&lt;/h3&gt;

&lt;p&gt;We are constantly striving to improve the features available in Monk. Following are some developments that we will be releasing soon:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding custom layers and creating custom Deep Neural architectures&lt;/li&gt;
&lt;li&gt;More optimisers, regularisers and loss functions&lt;/li&gt;
&lt;li&gt;Multi-label classification for image tagging&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We are creating a community of collaborators for Monk.&lt;/p&gt;

&lt;p&gt;Signup here to become a beta tester : &lt;a href="https://monkai-42.firebaseapp.com/"&gt;LINK&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mention in comments which features and applications you would like us to build next.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Do give us a star on &lt;a href="https://github.com/Tessellate-Imaging/monk_v1/"&gt;Github&lt;/a&gt; if you like what you see!&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>prototyping</category>
      <category>classification</category>
    </item>
    <item>
      <title>Find hyper-parameters using Monk - Creating a Plant Disease Classifier</title>
      <dc:creator>Abhishek Annamraju</dc:creator>
      <pubDate>Tue, 03 Dec 2019 11:22:25 +0000</pubDate>
      <link>https://dev.to/abhishek4273/find-hyper-parameters-using-monk-creating-a-plant-disease-classifier-1ep9</link>
      <guid>https://dev.to/abhishek4273/find-hyper-parameters-using-monk-creating-a-plant-disease-classifier-1ep9</guid>
      <description>&lt;p&gt;TLDR;&lt;br&gt;
&lt;a href="https://drive.google.com/file/d/1BrWdjgXREy6VWYlyn9wF4iaqSGf8yvEa/view?usp=sharing&amp;amp;source=post_page-----3a4d7ba419b9----------------------"&gt;Colab Notebook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In agriculture, leaf diseases cause a major decrease in both quality and quantity of yields. Automating plant disease detection using Computer Vision could play a role in early detection and prevention of diseases.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  What will you build!
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nA5ODKM9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/say2x4wkvea0kctxz01r.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nA5ODKM9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/say2x4wkvea0kctxz01r.gif" alt="Plant disease classification"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this exercise we will explore how to build a plant leaf disease classifier using Monk’s quick &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/hp_finder/model_finder"&gt;Hyper-Parameter finding feature&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Monk provides a syntax invariant transfer learning framework that supports Keras, Pytorch and Mxnet in the backend. (Read — &lt;a href="https://clever-noyce-f9d43f.netlify.com/"&gt;Documentation&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Computer Vision developers have to explore strategies while selecting the correct learning rates, a fitting CNN architecture, use the right optimisers and fine-tune many more parameters to get the best performing models.&lt;/p&gt;

&lt;p&gt;The Hyper-Parameter finding features assists in analysing multiple options for a selected hyper-parameter before proceeding with the actual experiment. This not just saves a lot of time spent in prototyping but also assists in quickly exploring the how well a selected set of parameters perform on the dataset in use and the final application.&lt;/p&gt;

&lt;p&gt;Let’s begin!&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;We start by setting up Monk and it’s dependencies on colab. For further setup instructions on different platforms check out the &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/setup/setup"&gt;DOCS&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/Tessellate-Imaging/monk_v1
$ cd monk_v1/installation &amp;amp;&amp;amp; pip install -r requirements_cu10.txt
$ cd ../..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Dataset
&lt;/h3&gt;

&lt;p&gt;For this exercise we will use dataset gathered by the awesome folks at &lt;a href="https://plantvillage.psu.edu/"&gt;PlantVillage&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Experimentation
&lt;/h3&gt;

&lt;p&gt;Before setting up our analysis, we have to start by creating a new project and experiment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Step 1 - Create experimentptf = prototype(verbose=1);ptf.Prototype("plant_disease", "exp1");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and setup the ‘Default’ dataset paths&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Default(dataset_path=["./dataset/train", "./dataset/val"], 
            model_name="resnet18", 
            freeze_base_network=True, num_epochs=5);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we are ready to run some analysis and find the best Hyper-Parameters.&lt;/p&gt;

&lt;p&gt;Currently we can analyse the following parameters :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Find the best CNN architecture — &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/hp_finder/model_finder"&gt;DOCS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Find the right batch size — &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/hp_finder/batch_size_finder"&gt;DOCS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Find the a good input shape — &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/hp_finder/input_dimension_finder"&gt;DOCS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Select a good starting learning rate — &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/hp_finder/LR_finder"&gt;DOCS&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Select the best performing Optimiser — &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/hp_finder/optimiser_finder"&gt;DOCS&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will analyse each of the above parameters to select the best and finally train our model to build the application of Plant Leaf disease classification.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Model Finder
&lt;/h3&gt;

&lt;p&gt;Start by giving a name to the analysis. For every analysis a new project is created with multiple experiments inside.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;analysis_name = “Model_Finder”;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we pass on the list of Models from which to analyse&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First element in the list — Model Name&lt;/li&gt;
&lt;li&gt;Second element in the list — Boolean value to freeze base network or not&lt;/li&gt;
&lt;li&gt;Third element in the list — Boolean value to use pretrained model as the starting point or not
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;models = [[“resnet34”, True, True], [“resnet50”, False, True],[“densenet121”, False, True], [“densenet169”, True, True], [“densenet201”, True, True]];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Set the Number of epochs for each experiment to run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;epochs=5;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Select the Percentage of original dataset to take in for experimentation&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;percent_data=10;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally we run the analysis function to search for best performing models:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;“keep_all” — Keeps all the experiments created&lt;/li&gt;
&lt;li&gt;“keep_none” — Deletes all experiments created
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Analyse_Models(analysis_name, models, 
                   percent_data, num_epochs=epochs, 
                   state=”keep_none”);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When the analysis is running, the estimated time is displayed for every experiment&lt;/p&gt;

&lt;p&gt;Running Model analysis&lt;br&gt;
Analysis Name : Model_Finder Running experiment : 1/5 &lt;br&gt;
Experiment name : Model_resnet34_freeze_base_pretrained &lt;br&gt;
Estimated time : 2 min&lt;/p&gt;

&lt;p&gt;Finally after the experiment is completed we receive the following output on training and validation accuracies and losses:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uite0sLm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/851/1%2AVPXPpgLOyhSvlFVgZq8WwA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uite0sLm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/851/1%2AVPXPpgLOyhSvlFVgZq8WwA.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Experiment Output&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Select the best performing CNN architecture, update your experiment and continue with further analysis. Don’t forget to reload the experiment after updating.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Update Model Architecture
ptf.update_model_name(“densenet121”);
ptf.update_freeze_base_network(False);
ptf.update_use_pretrained(True);
ptf.Reload();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For further instructions on updating experiment parameters, check out the &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/update_mode/update_dataset"&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Batch Size Finder
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Analysis Project Name
analysis_name = “Batch_Size_Finder”;# Batch sizes to explore
batch_sizes = [4, 8, 16, 32];# Num epochs for each experiment to run
epochs = 10;# Percentage of original dataset to take in for experimentation
percent_data = 10;
ptf.Analyse_Batch_Sizes(analysis_name, batch_sizes, 
                        percent_data, 
                        num_epochs=epochs, state=”keep_none”);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Generated output:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5rb7MWBd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/644/1%2AM3_aakYsou85v9FGjr_xfQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5rb7MWBd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/644/1%2AM3_aakYsou85v9FGjr_xfQ.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Experiment Output&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Update the experiment :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Update Batch Size
ptf.update_batch_size(8);
ptf.Reload();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Input Shape Finder
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Analysis Project Name
analysis_name = “Input_Size_Finder”;# Input sizes to explore
input_sizes = [224, 256, 512];# Num epochs for each experiment to run
epochs=5;# Percentage of original dataset to take in for experimentation
percent_data=10;
ptf.Analyse_Input_Sizes(analysis_name, 
                        input_sizes, percent_data, 
                        num_epochs=epochs, state=”keep_none”);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Generated output :&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Rj0UdTKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/644/1%2AFhEz5PoB9WxaBZ2SUzO33w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Rj0UdTKZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/644/1%2AFhEz5PoB9WxaBZ2SUzO33w.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Experiment Output&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Update the experiment :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Update Input Sizeptf.update_input_size(224);
ptf.Reload();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Learning Rate Analysis
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Analysis Project Name
analysis_name = “Learning_Rate_Finder”# Learning rates to explore
lrs = [0.01, 0.005, 0.001, 0.0001];# Num epochs for each experiment to run
epochs=5# Percentage of original dataset to take in for experimentation
percent_data=10
ptf.Analyse_Learning_Rates(analysis_name, lrs, percent_data, 
                           num_epochs=epochs, state=”keep_none”);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Generated output :&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d_rJHbD5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/659/1%2AHt6x1pf1giaFnXaO7ipjhA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d_rJHbD5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/659/1%2AHt6x1pf1giaFnXaO7ipjhA.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Experiment Output&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Update the experiment :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Update Learning Rateptf.update_learning_rate(0.01);
ptf.Reload();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Optimiser Analysis
&lt;/h3&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Analysis Project Name
analysis_name = “Optimiser_Finder”;# Optimizers to explore
optimizers = [“sgd”, “adam”, “adamax”, “rmsprop”]; #Model name
epochs = 5;# Percentage of original dataset to take in for experimentation
percent_data = 10;
ptf.Analyse_Optimizers(analysis_name, optimizers, percent_data, 
                       num_epochs=epochs, state=”keep_none”);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Generated output :&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6FGq7Abs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/659/1%2ARIZhPczLnDrvMcnmgJepbQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6FGq7Abs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/659/1%2ARIZhPczLnDrvMcnmgJepbQ.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Experiment Output&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Update the experiment :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## Update Optimiserptf.optimizer_adamax(0.001);
ptf.Reload();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Training
&lt;/h3&gt;

&lt;p&gt;Finally after setting the correct hyper-parameters, we can begin training the model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Train();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;

&lt;h3&gt;
  
  
  Copy Experiment
&lt;/h3&gt;

&lt;p&gt;We can visualise the accuracy and loss plots, located inside the workspace directory. From the plots we observe that the losses can go further down:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--o8_S0qhI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2AE8ofVh7_ZxaIKIMNNNDLDQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--o8_S0qhI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/432/1%2AE8ofVh7_ZxaIKIMNNNDLDQ.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Loss curves&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To continue training, we copy our previous experiment and resume from that state — &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/copy_experiment"&gt;DOCS&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;

&lt;h3&gt;
  
  
  Compare Experiments
&lt;/h3&gt;

&lt;p&gt;After finishing our training we can compare both these experiments to check if we actually improved performance using Compare Experiment feature in Monk.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VXJLH-c6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AneuU89tS7bCUCglWdGs97A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VXJLH-c6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AneuU89tS7bCUCglWdGs97A.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Validation accuracy curves&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our ‘experiment 1’ ran for 5 epochs and ‘experiment 2’ ran for 10 epochs. Even though a minor improvement in validation accuracy, an increase from 96% to 97% could help achieve leader board positions for competitions hosted on Kaggle and EvalAi.&lt;/p&gt;

&lt;p&gt;Hope you have fun building niche solutions with our tools.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>hyperparameter</category>
      <category>classification</category>
    </item>
    <item>
      <title>Project management with Monk: Creating an indoor-scene classifier</title>
      <dc:creator>Abhishek Annamraju</dc:creator>
      <pubDate>Tue, 03 Dec 2019 11:21:09 +0000</pubDate>
      <link>https://dev.to/abhishek4273/project-management-with-monk-creating-an-indoor-scene-classifier-4a07</link>
      <guid>https://dev.to/abhishek4273/project-management-with-monk-creating-an-indoor-scene-classifier-4a07</guid>
      <description>&lt;p&gt;TLDR;&lt;br&gt;
&lt;a href="https://drive.google.com/file/d/1Qd6XRWIsIfge5nbl0jT_RM8_a-iacEuH/view?usp=sharing&amp;amp;source=post_page-----6cec33fd6252----------------------"&gt;Colab Notebook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  What will you build?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bL5vpj2B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://tessellate-pytorch-serverless.s3.amazonaws.com/indoor_classification.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bL5vpj2B--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://tessellate-pytorch-serverless.s3.amazonaws.com/indoor_classification.gif" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this exercise we will create and fine-tune an ‘indoor scene classifier’ using Monk.&lt;/p&gt;

&lt;p&gt;We will use Transfer Learning, wherein we pick a ‘Model’ which has already been trained to answer a similar problem and retrain it for our case.&lt;/p&gt;

&lt;p&gt;Transfer Learning is a faster workaround than training a model from scratch.&lt;/p&gt;

&lt;p&gt;Monk provides a syntax invariant transfer learning framework that supports Keras, Pytorch and Mxnet in the backend. (Read — &lt;a href="https://clever-noyce-f9d43f.netlify.com/"&gt;Documentation&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Setup
&lt;/h3&gt;

&lt;p&gt;We start by setting up Monk and it’s dependencies on colab. For further setup instructions on different platforms check out the &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/setup/setup"&gt;DOCS&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/Tessellate-Imaging/monk_v1
$ cd monk_v1/installation &amp;amp;&amp;amp; pip install -r requirements_cu10.txt
$ cd ../..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Dataset
&lt;/h3&gt;

&lt;p&gt;We will utilise the image dataset gathered by these awesome researchers — &lt;a href="https://omidpoursaeed.github.io/publication/vision-based-real-estate-price-estimation/"&gt;LINK&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Optional : &lt;a href="https://medium.com/@paudelanjanchandra/download-google-drive-files-using-wget-3c2c025a8b99"&gt;How to download large files from Google drive&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Training
&lt;/h3&gt;

&lt;p&gt;Next we will use Pytorch as our backend to create a new Project and use Resnet101 as our pre-trained model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1);
ptf.Prototype("indoor_scene", "exp1");
ptf.Default(dataset_path="./Train/", 
            model_name="resnet101", 
            freeze_base_network=True, num_epochs=10);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With Monk you can download or upload your workspace onto different machines and resume your work from where you left.&lt;/p&gt;

&lt;p&gt;To demo this we will run inference by downloading the workspace to our local machine. To keep the download size small, we will disable saving intermediate models.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.update_save_intermediate_models(False);
ptf.Reload();
ptf.Train();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Inference
&lt;/h3&gt;

&lt;p&gt;Let’s zip our workspace and download it locally for inferencing. Before we can begin doing this we have to setup Monk on our local system. Check the documentation for further instructions on this — &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/setup/setup"&gt;SETUP&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ zip -r workspace.zip workspace
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After importing ‘Monk’ in our local workspace, we can test our model on a single image and check the predicted label. (&lt;a href="https://clever-noyce-f9d43f.netlify.com/#/quick_mode/quickmode_pytorch"&gt;DOCS&lt;/a&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Prototype("indoor_scene", "exp1", eval_infer=True);
img_name = "test.jpg";
predictions = ptf.Infer(img_name=img_name, return_raw=False);print(predictions);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Hyper-Parameter Tuning
&lt;/h3&gt;

&lt;p&gt;Now that we have achieved a baseline validation accuracy of ‘INSERT VALUE’, we can resume fine-tuning the generated model from the previous exercise. To do this we use the ‘copy_from’ feature in Monk.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Prototype("indoor_scene", "exp2", 
              copy_from=["indoor_scene", "exp1"]);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can now update our hyper-parameters,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;###########Update hyperparameters################
ptf.optimizer_asgd(0.001, weight_decay=0.00001);ptf.update_num_epochs(10);
################################################
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Add randomised cropping&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;########Update Transforms#####################
ptf.apply_random_resized_crop(224, train=True, val=True);
###############################################
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and freeze more layers from our pre-trained model to tune the weights and biases in the last few layers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;###########For freeze layers#####################
ptf.update_freeze_layers(100);
################################################
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can now retrain our model to see if we can churn a better validation accuracy.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE : Don’t forget to reload the experiment after adding updates.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Reload();
ptf.Train();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Ohh and don’t forget to take a break, stretch your legs. You can always resume training from the last break point using Monk’s resume training feature.&lt;/p&gt;

&lt;p&gt;All you have to do is load the experiment with resume state and begin. Read the docs for more information — (&lt;a href="https://clever-noyce-f9d43f.netlify.com/"&gt;DOCS&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Compare
&lt;/h3&gt;

&lt;p&gt;Finally to check if the second experiment was fruitful and if we can do further improvement, we can &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/compare_experiment"&gt;compare our experiments&lt;/a&gt; and visualise losses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from compare_prototype import compare

ctf = compare(verbose=1);
ctf.Comparison("indoor_scene");
ctf.Add_Experiment("indoor_scene", "exp1");
ctf.Add_Experiment("indoor_scene", "exp2");
ctf.Generate_Statistics()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The final training accuracy plots show that we definitely improved from our baseline model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HLpmeeyN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AM2RwUD8pzu6cq81AdqeZCw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HLpmeeyN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AM2RwUD8pzu6cq81AdqeZCw.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Training Accuracies&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We don’t have to stop here. We can utilise augmentation strategies on our dataset and further improve the model performance on newer data.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>prototyping</category>
      <category>projectmanagement</category>
    </item>
    <item>
      <title>Quick prototyping with Monk - Creating a fashion classifier</title>
      <dc:creator>Abhishek Annamraju</dc:creator>
      <pubDate>Tue, 03 Dec 2019 11:20:32 +0000</pubDate>
      <link>https://dev.to/abhishek4273/quick-prototyping-with-monk-creating-a-fashion-classifier-3n8l</link>
      <guid>https://dev.to/abhishek4273/quick-prototyping-with-monk-creating-a-fashion-classifier-3n8l</guid>
      <description>&lt;p&gt;TLDR;&lt;br&gt;
&lt;a href="https://colab.research.google.com/gist/li8bot/73cd78dd420588cae7bcd597ca0521a5/fashion_myntra.ipynb?source=post_page-----66f601117e61----------------------"&gt;Colab Notebook&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating a fashion classifier with Monk and Densenets
&lt;/h3&gt;

&lt;p&gt;In this exercise we will take a look some of MONK’s auxiliary functions while switching our backend framework between Pytorch, Keras and Mxnet.&lt;/p&gt;

&lt;p&gt;We will use Densenets as our CNN architecture. To get a deeper understanding of Dense blocks and Densenets do checkout this awesome blog post — &lt;a href="https://towardsdatascience.com/review-densenet-image-classification-b6631a8ef803"&gt;LINK&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As our dataset source we will be using Myntra Fashion dataset kindly shared by Param Aggarwal — &lt;a href="https://www.kaggle.com/paramaggarwal/fashion-product-images-small"&gt;LINK&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s begin.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  The Setup
&lt;/h3&gt;

&lt;p&gt;We start by setting up Monk and its dependencies on colab. For further setup instructions on different platforms check out the DOCS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git clone https://github.com/Tessellate-Imaging/monk_v1
$ cd monk_v1/installation &amp;amp;&amp;amp; pip install -r requirements_cu10.txt
$ cd ../..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next we grab the data. You can either download the dataset using kaggle. To skip setting up kaggle API on colab, we’ve created a dropbox link to the dataset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ wget https://www.dropbox.com/s/wzgyr1dx4sejo5u/dataset.zip
$ unzip dataset.zip
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Checking out the ground truth csv file we find different feature columns.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hIwPKGgk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/972/1%2A-ZlQkP5wSY5aHT2sU1iNAw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hIwPKGgk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/972/1%2A-ZlQkP5wSY5aHT2sU1iNAw.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this exercise we will classify fashion items into their sub category labels. To do this we extract the image ‘id’ column along with ‘subCategory’ to create a new labels file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
gt = pd.read_csv("./dataset/styles.csv",error_bad_lines=False)
label_gt = gt[['id','subCategory']]
label_gt['id'] = label_gt['id'].astype(str) + '.jpg'
label_gt.to_csv('./dataset/subCategory.csv',index=False)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that we have the images and label files ready, we can begin with creating experiments.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Monk with Pytorch
&lt;/h3&gt;

&lt;p&gt;After importing MONK creating an experiment is simple. We can load Pytorch backend and create a new project and experiment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import os
import sys
sys.path.append("./monk_v1/monk/");
import psutilfrom pytorch_prototype import prototype
ptf = prototype(verbose=1);
ptf.Prototype("fashion", "exp1");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next we create the ‘Dataset’ object and setup the dataset and label path along with CNN architecture and number of epochs.(DOCS)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Default(dataset_path="./mod_dataset/images", 
             path_to_csv="./mod_dataset/subCategory.csv", 
             model_name="densenet121", 
             freeze_base_network=True, num_epochs=5);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We can check for missing or corrupt images and take a look at class imbalances using Monk’s EDA function (DOCS)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.EDA(check_missing=True, check_corrupt=True);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3JsWyym_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/907/1%2AYDRNyjdi7fjLfN6sNvZYVg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3JsWyym_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/907/1%2AYDRNyjdi7fjLfN6sNvZYVg.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Find missing images in your dataset&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We have to update our labels file and remove rows containing missing or corrupt images. The notebook has a function ‘cleanCSV’ for this purpose.&lt;/p&gt;

&lt;p&gt;After cleaning our labels file if we generated a new CSV, we have to update our ‘Dataset’ object to the location. This can be done by using the update functions (&lt;a href="https://clever-noyce-f9d43f.netlify.com/#/update_mode/update_dataset"&gt;DOCS&lt;/a&gt;). Remember to run ‘Reload()’ after any making an update.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.update_dataset(dataset_path="./dataset/images",
                   path_to_csv="./dataset/subCategory_cleaned.csv");
ptf.Reload()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And now we can start our training with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For this experiment we are using densenet121 architecture. In the next experiments we will be using densenet169 and densenet201 architectures.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T9MFq4SW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/811/1%2AH3HjgnC-iqS2TTbFpp4iLw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T9MFq4SW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/811/1%2AH3HjgnC-iqS2TTbFpp4iLw.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Different Densenet architectures&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After training is complete we get our final model accuracies and losses saved in our workspace folder. Now we can continue with the experiment and test our the other 2 densenet architectures.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1);
ptf.Prototype("fashion", "exp2");
ptf.Default(dataset_path="./dataset/images", 
            path_to_csv="./dataset/subCategory_cleaned.csv", 
            model_name="densenet169", freeze_base_network=True, 
            num_epochs=5);
ptf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;AND&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ptf = prototype(verbose=1);
ptf.Prototype("fashion", "exp3");
ptf.Default(dataset_path="./dataset/images", 
            path_to_csv="./dataset/subCategory_cleaned.csv", 
            model_name="densenet201", 
            freeze_base_network=True, num_epochs=5);
ptf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After training is complete for the 3 experiments we can quickly compare these and find out differences in losses(both training and validation), compare training time and resource utilisation and select the best model.&lt;/p&gt;

&lt;p&gt;Since we have trained only for 5 epochs, it still will not be clear which architecture to choose from the 3, however, you can test out with either more epochs or even with a different CNN architecture. To update the model check out our &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/update_mode/update_model"&gt;DOCUMENTATION&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h3&gt;
  
  
  Compare experiments
&lt;/h3&gt;

&lt;p&gt;To run comparison we have to import the ‘compare’ module and add the 3 experiments.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from compare_prototype import compare
ctf = compare(verbose=1);
ctf.Comparison("Fashion_Pytorch_Densenet");
ctf.Add_Experiment("fashion", "exp1");
ctf.Add_Experiment("fashion", "exp2");
ctf.Add_Experiment("fashion", "exp3");
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;After adding the experiments to compare, we can generate the statistics. To find out more about the compare module check out (&lt;a href="https://clever-noyce-f9d43f.netlify.com/#/compare_experiment"&gt;DOCS&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6xFjMAM8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AH9zxlxRvfYCXNi8A0_PkKQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6xFjMAM8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AH9zxlxRvfYCXNi8A0_PkKQ.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Training accuracies over time&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The training accuracy performance shows that ‘densenet169’ performs marginally better than the other 2. However looking at the validation accuracy shows us a different picture.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ChsAP-KZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2ALqYtRoeYYCM4t92UpyfxeA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ChsAP-KZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2ALqYtRoeYYCM4t92UpyfxeA.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Validation accuracies over time&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Experiment 3 with ‘densenet201’ performs better that the others. If we compare the best validation accuracies for the 3 models, they are pretty close:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aDIS7Vwb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AWNyBLhbXd4i4s907uR66Cw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aDIS7Vwb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AWNyBLhbXd4i4s907uR66Cw.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Best validation accuracies&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;However one more metric to checkout before going ahead is the training times.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6WsHQuaV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AS4UcK7UHVlXtsNND6BusMQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6WsHQuaV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2AS4UcK7UHVlXtsNND6BusMQ.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Training times&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This shows that the more complex our CNN architecture the more time is takes to train per epoch. &lt;/p&gt;

&lt;p&gt;Next we’ll create similar experiments but with Keras and Mxnet.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h4&gt;
  
  
  Monk with Mxnet
&lt;/h4&gt;

&lt;p&gt;Monk is a &lt;strong&gt;syntax invariant library&lt;/strong&gt;. So working with either of the available backend Deep Learning framework does not change the program you have to write.&lt;/p&gt;

&lt;p&gt;The only change will be in import :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from gluon_prototype import prototype
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next we create experiments the same way with different densenet architectures and carry out training.&lt;/p&gt;

&lt;p&gt;Gluon experiments —&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gtf = prototype(verbose=1);
gtf.Prototype("fashion", "exp4");
gtf.Default(dataset_path="./dataset/images", 
            path_to_csv="./dataset/subCategory_cleaned.csv",
            model_name="densenet121", 
            freeze_base_network=True, num_epochs=5);
gtf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And so on…&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
 &lt;/p&gt;
&lt;h4&gt;
  
  
  Monk with Keras
&lt;/h4&gt;

&lt;p&gt;As mentioned in the previous section, the only thing that changes is the import. So to utilise keras in the backend we import:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from keras_prototype import prototype
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And then create some more experiments:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ktf = prototype(verbose=1);
ktf.Prototype("fashion", "exp7");
ktf.Default(dataset_path="./dataset/images", 
            path_to_csv="./dataset/subCategory_cleaned.csv", 
            model_name="densenet121", 
            freeze_base_network=True, num_epochs=5);
ktf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And so on…&lt;/p&gt;

&lt;p&gt;Finally when we have trained the 9 experiments we can compare which framework and which architecture performed the best by using the compare utility in Monk(&lt;a href="https://clever-noyce-f9d43f.netlify.com/#/compare_experiment"&gt;DOCS&lt;/a&gt;) and fine-tune the ones performing better.&lt;/p&gt;

&lt;p&gt;Comparison plot for training accuracy generated from our exercise :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VvgKlE67--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2A2UVlliOGzirXOaUIeH7m0A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VvgKlE67--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2A2UVlliOGzirXOaUIeH7m0A.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Training accuracy comparisons&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To achieve better results, try changing the learning rate schedulers and train for more epochs. You can easily copy an experiment and modify the hyper parameters, to generate better results. Check out our &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/copy_experiment"&gt;documentation&lt;/a&gt; for further instructions on this.&lt;/p&gt;

&lt;p&gt;Happy Coding!&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>prototyping</category>
      <category>classification</category>
    </item>
    <item>
      <title>Transfer learning with Monk</title>
      <dc:creator>Abhishek Annamraju</dc:creator>
      <pubDate>Tue, 03 Dec 2019 11:16:23 +0000</pubDate>
      <link>https://dev.to/abhishek4273/transfer-learning-with-monk-2m14</link>
      <guid>https://dev.to/abhishek4273/transfer-learning-with-monk-2m14</guid>
      <description>&lt;p&gt;&lt;strong&gt;Monk provides a syntax invariant transfer learning framework that supports Keras, Pytorch and Mxnet in the backend. (Read — &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/introduction"&gt;Documentation&lt;/a&gt;)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://monkai-42.firebaseapp.com/"&gt;Website&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Tessellate-Imaging/monk_v1"&gt;Github&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Transfer Learning
&lt;/h3&gt;

&lt;p&gt;Transfer learning is one of the most used techniques in training computer vision models. To put it simply, an already trained model is picked and retrained for a different use-case.&lt;/p&gt;

&lt;p&gt;The key steps involved are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data ingestion&lt;/li&gt;
&lt;li&gt;Model selection&lt;/li&gt;
&lt;li&gt;Setting parameters&lt;/li&gt;
&lt;li&gt;Training&lt;/li&gt;
&lt;li&gt;Evaluating results&lt;/li&gt;
&lt;li&gt;Comparing results with previous training sessions&lt;/li&gt;
&lt;li&gt;Changing the parameters and retraining until we find the best fit model&lt;/li&gt;
&lt;li&gt;………… Iterating the same&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Computer Vision developers have to explore strategies while selecting the correct learning rates, a fitting CNN architecture, use the right optimisers and fine-tune many more parameters to get the best performing models.&lt;/p&gt;
&lt;h3&gt;
  
  
  Let’s compare steps carried out traditionally vs Monk
&lt;/h3&gt;
&lt;h4&gt;
  
  
  1. Write less code to begin the prototyping process
&lt;/h4&gt;

&lt;p&gt;Typically to tackle transfer learning, frameworks like keras, pytorch or mxnet are used&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sNGwKbGD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1366/1%2AQcjk2NjfBaECHWR52AjWsg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sNGwKbGD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1366/1%2AQcjk2NjfBaECHWR52AjWsg.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Transfer learning using pytorch — Ref: &lt;a href="https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html"&gt;https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The traditional way&lt;/strong&gt;: The very first step to transfer learning is to understand pytorch and write these many lines of code!!!!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Monk way&lt;/strong&gt;: Start with 5 lines of code instead of 40 — Use Monk’s Quick Mode&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from monk.pytorch_prototype import prototype
gtf = prototype(verbose=1);
gtf.Prototype("Project-1", "Experiment-1");
gtf.Default(dataset_path="train",
              model_name="resnet18_v1",num_epochs=10);
gtf.Train();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
  &lt;/p&gt;
&lt;h4&gt;
  
  
  2.Seamlessly switch back-end frameworks
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hvzr6hWu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1366/1%2AIjdzO1Dmjz0cS_ockeAaZA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hvzr6hWu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1366/1%2AIjdzO1Dmjz0cS_ockeAaZA.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Transfer learning using keras — Ref: &lt;a href="https://medium.com/@14prakash/transfer-learning-using-keras-d804b2e04ef8"&gt;https://medium.com/@14prakash/transfer-learning-using-keras-d804b2e04ef8&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The traditional way&lt;/strong&gt;: Learn keras and again write many lines of code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Monk way&lt;/strong&gt;: Import Keras utilities from Monk and write the same code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from monk.keras_prototype import prototype
gtf = prototype(verbose=1);
gtf.Prototype("Project-1", "Experiment-1");
gtf.Default(dataset_path="train",model_name="resnet18_v1",
           num_epochs=10);
gtf.Train()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Monk is &lt;strong&gt;Syntax Invariant up-to a certain level of abstraction&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now, one may ask that with just these 5 lines of code one is losing the capabilities to manipulate parameters.&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
  &lt;/p&gt;
&lt;h4&gt;
  
  
  3. Manipulate parameters in a standardized way
&lt;/h4&gt;

&lt;p&gt;Load your experiment in the quick mode and make changes to parameters at every stage&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dataset updates&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gtf.update_input_size(256); - Change input shape
gtf.update_trainval_split(0.6); - Change splits
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and many more….. &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/update_mode/update_layers"&gt;Check out Monk’s Update Mode&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model updates&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gtf.update_freeze_layers(10); - freeze layers
gtf.append_linear(final_layer=True); - append layers
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;and much more. &lt;a href="https://clever-noyce-f9d43f.netlify.com/#/expert_mode"&gt;Check out Monk’s Expert Mode&lt;/a&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
  &lt;/p&gt;
&lt;h4&gt;
  
  
  4. Compare all the experiments executed using Monk
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;The traditional way&lt;/strong&gt;: Write extra code that creates comparisons, and make a lot of changes to training code in order to generate these metrics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Monk way&lt;/strong&gt;: Invoke comparison capabilities in simple functional format&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ctf = compare(verbose=1);
ctf.Comparison("Sample-Comparison-1")# Step 1 - Add experiments
ctf.Add_Experiment("Project-Testing-Optimizers", "SGD");
ctf.Add_Experiment("Project-Testing-Optimizers", "ADAM");
ctf.Add_Experiment("Project-Testing-Optimizers", "ADAGRAD");
ctf.Add_Experiment("Project-Testing-Optimizers", "NAG");
ctf.Add_Experiment("Project-Testing-Optimizers", "NADAM");
ctf.Add_Experiment("Project-Testing-Optimizers", "ADAMAX");# Step 2 - Compare
ctf.Generate_Statistics();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;And generate Results&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jqQzEq7k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2Am7BicvQ_zm8ffAsL2zOKfw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jqQzEq7k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1440/1%2Am7BicvQ_zm8ffAsL2zOKfw.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;Compare Accuracies&lt;/em&gt;&lt;/p&gt;

&lt;p&gt; &lt;br&gt;
 &lt;br&gt;
  &lt;/p&gt;

&lt;h4&gt;
  
  
  5. Other benefits of using Monk
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Resume training sessions&lt;/strong&gt; when interrupted from the last epoch&lt;/li&gt;
&lt;li&gt;Run &lt;strong&gt;Experimental data analysis&lt;/strong&gt; — discover class imbalance, missing data, corrupt data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Copy experiment from one system to another&lt;/strong&gt;, be it local or cloud&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Estimate training times&lt;/strong&gt; before actual runs&lt;/li&gt;
&lt;li&gt;Semi-automatically &lt;strong&gt;find hyper-parameters&lt;/strong&gt; by running mini-experiments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Upcoming stories: Tutorials on using MONK&lt;/p&gt;

&lt;p&gt;Happy Coding!!!&lt;/p&gt;

</description>
      <category>deeplearning</category>
      <category>computervision</category>
      <category>classification</category>
    </item>
  </channel>
</rss>
