<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Asya Frumkin on Medium]]></title>
        <description><![CDATA[Stories by Asya Frumkin on Medium]]></description>
        <link>https://medium.com/@asyafru?source=rss-654ea7ef5a7d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*TV7SddxNrFcUZ6a8IUkLag.jpeg</url>
            <title>Stories by Asya Frumkin on Medium</title>
            <link>https://medium.com/@asyafru?source=rss-654ea7ef5a7d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:39:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@asyafru/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Demo Your Model With Streamlit]]></title>
            <link>https://medium.com/data-science/demo-your-model-with-streamlit-a76011467dfb?source=rss-654ea7ef5a7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a76011467dfb</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[ml-model-deployment]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[streamlit-app-deployment]]></category>
            <dc:creator><![CDATA[Asya Frumkin]]></dc:creator>
            <pubDate>Sun, 20 Feb 2022 09:16:42 GMT</pubDate>
            <atom:updated>2022-02-21T10:33:18.398Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to quickly deploy your computer vision model without any backend or frontend knowledge</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-VtCjzjJ3IdodPJ4" /><figcaption>Photo by <a href="https://unsplash.com/@punttim?utm_source=medium&amp;utm_medium=referral">Tim Gouw</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>The task</h3><p>Suppose that you need to present the progress you’ve made on a cool computer vision model you’re developing. The model you are working on is not ready yet, so deploying it to proper development or production environment can take time and a lot of work. On the other hand, developing a specific web interface to interact with your model can be a tedious task and requires a skillset that is not very common for a data scientist.</p><h3>The rescue</h3><p><a href="https://streamlit.io/">Streamlit</a>, is an open-source Python library that makes it easy to create and share web apps for machine learning and data science. It can be extremely useful in presenting progress on a project to your team, gain and share insights to your managers and even get feedback from clients.</p><p>It doesn’t replace a proper deployment to production that requires monitoring, logging etc. However, it enables you to create “something that works” in a few hours without any web development prior knowledge and even without knowing how to use <a href="https://flask.palletsprojects.com/en/2.0.x/">flask</a> or <a href="https://www.djangoproject.com/">Django</a> for backend.</p><p>Let’s see how this magic works.</p><h3>Installation</h3><p>To install Streamlit run:</p><pre>pip install streamlit</pre><p>If you are using <a href="https://python-poetry.org/">Poetry</a> then run instead:</p><pre>poetry add streamlit</pre><p>To verify that all works well you can run this line and see a few explanations and demos:</p><pre>streamlit hello</pre><h3>Your first app — upload an image</h3><p>Lets start simple by loading an image from local storage and displaying it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ebb0ca0d581685aae8384f43f7158d4/href">https://medium.com/media/1ebb0ca0d581685aae8384f43f7158d4/href</a></iframe><p>To run the app simply type:</p><pre>streamlit run image_upload.py</pre><p>It will then open the app in your browser. It should look like this:</p><figure><img alt="Image upload demo app interface. It has a drag-and-drop section and a file browsing button" src="https://cdn-images-1.medium.com/max/1024/1*qqddCLmSQiVbIydLY1jCwQ.png" /><figcaption>Image upload demo app, image by author</figcaption></figure><p>You can browse through your computer and upload any image you like. I chose to upload an image of some cute penguins.</p><figure><img alt="Image upload demo app in action. Uploaded image is an image of penguins" src="https://cdn-images-1.medium.com/max/1024/1*PkW4wJLUEPDrnbBCYz_-ww.png" /><figcaption>Image upload demo app in action. App image by author, uploaded photo by <a href="https://unsplash.com/@mudmanuk?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Paul Carroll</a> on <a href="https://unsplash.com/s/photos/king-penguin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Deploying a pre-trained model</h3><p>Sometimes it is useful to see how a pre-trained model works in order to have a good baseline. You will now deploy one of these models, in this case ResNet18, in a Streamlit app.</p><p>To do that with PyTorch you need to load the model and download ImageNet labels:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78a14469622d1d18ba962e2a2de1967d/href">https://medium.com/media/78a14469622d1d18ba962e2a2de1967d/href</a></iframe><p>In order to run the model on the image load_image function, that you used before, should be modified to return the image. You need to convert image_data to PIL image object so that it can be fed into the model:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b884474569db165f3b4cb4e0eff1268/href">https://medium.com/media/0b884474569db165f3b4cb4e0eff1268/href</a></iframe><p>The code below is a modified version of <a href="https://pytorch.org/hub/pytorch_vision_resnet/">PyTorch ResNet tutorial</a> that runs a model prediction and presents the top 5 categories for the image:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9909deaa7d71c23211ecee95941744bb/href">https://medium.com/media/9909deaa7d71c23211ecee95941744bb/href</a></iframe><p>Of course, that you also need to modify the main function accordingly:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ead47e73e29f5961a2ecc0a1937b62b3/href">https://medium.com/media/ead47e73e29f5961a2ecc0a1937b62b3/href</a></iframe><p>The first thing that needs to be changed is the title. Then, you will load the model, the labels and the image. You should also add a button that triggers the model inference on the loaded image.</p><p>And this is what the application looks like when it runs on the image I loaded before:</p><figure><img alt="Web app running ResNet18 model on an image of penguins" src="https://cdn-images-1.medium.com/max/1024/1*OjKCF-_OuT9rNkZW-W-qNA.png" /><figcaption>Pre-trained ResNet18 model app with sample output. App image by author, uploaded photo by <a href="https://unsplash.com/@mudmanuk?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Paul Carroll</a> on <a href="https://unsplash.com/s/photos/king-penguin?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The model classifies the image as “king penguin” with 1.0 probability. The 4 other top classes get negligible probability.</p><p>The full code for this example is in <a href="https://github.com/asyaf/fun_mini_projects/blob/master/streamlit_examples/resnet_pretrained.py">Github</a>.</p><h3>Deploying a custom image classification model</h3><p>Now you are ready to deploy a custom model. You will be using a PyTorch model which classifies an image by penguin type. The process for creating a web app that uses a custom model is quite similar to the one involving a pre-trained model, with a few modifications. The code can be found <a href="https://github.com/asyaf/fun_mini_projects/blob/master/streamlit_examples/custom_model.py">here</a>.</p><h4>About the model</h4><p>Usually, pre-trained models are not enough for our needs, as the task at hand is more specific and not covered by such models. For example, ImageNet has a “king penguin” class but there are actually more penguin types out there. So, in order to classify images based on penguin type I had to train my own model. I used <a href="https://github.com/asyaf/fun_mini_projects/blob/master/penguin_classification/transfer_learning_penguin.ipynb">this notebook</a> for training.</p><p>If you want to understand more about how this model was built you can read about it in <a href="https://medium.com/mlearning-ai/penguins-from-head-to-toe-how-penguins-can-help-you-master-image-classification-process-8be9cd68121d">my previous post</a>.</p><h4>Getting the model</h4><p>Create a directory for the model-related files:</p><pre>mkdir custom_model</pre><p>To download the model file directly you can use <a href="https://drive.google.com/file/d/1yTxSAWNnq4az36-FHGqeR-HBdwDnHRvH/view?usp=sharing">this link</a>. Copy it to the new directory.</p><p>Add this constant definition to the code:</p><pre>MODEL_PATH = &#39;custom_model/model.pt&#39;</pre><h4>Creating labels file</h4><p>Create a text file with the names of the classification classes, one row per class. Make sure that the order of the classes matches the order that was used during training.</p><p>For example, to discover the order for the penguin dataset you can look for the following line in the training notebook and add a print after it:</p><pre>class_names = image_datasets[&#39;train&#39;].classes</pre><pre>print(class_names)</pre><p>This will give you the output:</p><pre>[‘Adelie Penguin’, ‘Chinstrap Penguin’, ‘Emperor Penguin’, ‘Gentoo Penguin’]</pre><p>Therefore, you should copy the following class names into a file called model_classes.txt and place it in the custom_model directory:</p><pre>Adelie Penguin<br>Chinstrap Penguin<br>Emperor Penguin<br>Gentoo Penguin</pre><p>Add the new labels file to the code as a constant:</p><pre>LABELS_PATH = &#39;custom_model/model_classes.txt</pre><h4>Loading model and labels</h4><p>Model and labels loading became simpler since they are local now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c50a008ade0d31e777733205901cb10/href">https://medium.com/media/4c50a008ade0d31e777733205901cb10/href</a></iframe><h4>A few more fixes</h4><p>Unlike ResNet18, which has many labels, this custom model has only 4 labels. Therefore, you should modify the prediction code to output probabilities for all the existing classes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9970774cf732cf9067f7aece5f2d657/href">https://medium.com/media/e9970774cf732cf9067f7aece5f2d657/href</a></iframe><p>Change the main function to have a different title for the app and pass on the local paths for the model and labels:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26932c3930479fc17ef6303e879e0d9f/href">https://medium.com/media/26932c3930479fc17ef6303e879e0d9f/href</a></iframe><p>Finally, this is what the application should look like:</p><figure><img alt="A web app running a custom image classification model on a penguin image" src="https://cdn-images-1.medium.com/max/1024/1*ClS2mtQ5Wj6gOkD5JRdkig.png" /><figcaption>Custom image classification model results. App image and uploaded photo by author</figcaption></figure><p>To test the app I uploaded an image of a Gentoo penguin. The model classified the image as an image of a Gentoo penguin with 0.91 probability. Other penguin types got much lower probability. Along with the confirmation that the app works well, I got another proof for the model correctness. Sweet, right?</p><h3>Conclusion</h3><p>It takes a lot of time and effort to develop a computer vision model that works well. During this process, you might need to deploy your model and illustrate its capabilities to your managers, teammates, and clients. Streamlit is a powerful and easy-to-use tool that lets you achieve this even if you don’t have the proper in-house tooling or frontend knowledge.</p><p>I illustrated the potential usage of Streamlit for image classification. However, it can be used for other types of computer vision tasks as well as visualizations, data analysis and much more. I encourage you to browse through the examples in the <a href="https://streamlit.io/gallery">Streamlit website</a> and try out the tool yourself to see how it can be integrated into your every day work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a76011467dfb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/demo-your-model-with-streamlit-a76011467dfb">Demo Your Model With Streamlit</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Penguins from Head to Toe — How Penguins Can Help You Master Image Classification Process]]></title>
            <link>https://medium.com/@asyafru/penguins-from-head-to-toe-how-penguins-can-help-you-master-image-classification-process-8be9cd68121d?source=rss-654ea7ef5a7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8be9cd68121d</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[image-classification]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[ml-so-good]]></category>
            <category><![CDATA[penguins]]></category>
            <dc:creator><![CDATA[Asya Frumkin]]></dc:creator>
            <pubDate>Fri, 04 Feb 2022 11:54:00 GMT</pubDate>
            <atom:updated>2022-02-04T11:54:00.821Z</atom:updated>
            <content:encoded><![CDATA[<h3>Penguins from Head to Toe — How Penguins Can Help You Master Image Classification Process</h3><h4>A step-by-step guide for creating your custom penguin image classification model</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zC65EvuwpoWhPyQ4" /><figcaption>Photo by <a href="https://unsplash.com/@goosegrease?utm_source=medium&amp;utm_medium=referral">Derek Oyen</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>I’m a penguin lover so I decided to create my own small dataset of penguin images and train an image classification model on it. This is a guide that lets you follow my work on this project. It can help you build your own model for any image classification project you’re interested in.</p><h3>Download the data</h3><h4>google-image-download</h4><p>Every data project has to start with some data. You will build your custom penguin dataset based on images collected from Google Images using google-image-download. The dataset will consist of 4 types of penguins: Adélie, Chinstrap, Emperor and Gentoo.</p><p><a href="https://github.com/hardikvasa/google-images-download">google-image-download</a> is a simple command-line tool for downloading images from Google based on keywords. To install it run:</p><pre>git clone <a href="https://github.com/hardikvasa/google-images-download.git">https://github.com/hardikvasa/google-images-download.git</a><br>cd google-images-download &amp;&amp; python setup.py install</pre><p>Unfortunately, the latest version in this repository is broken. A fix is suggested in one of its <a href="https://github.com/Joeclinton1/google-images-download">forks</a>.</p><h4>Dataset size</h4><p>Later on you are going to utilize a pre-trained model using transfer learning. At this stage you need to decide how large is the dataset going to be.</p><p>A dataset of 100 images or less per penguin type is a small-enough dataset that can be easily managed, and can be enough for the model to learn in a transfer learning setup. However, this might result in a model that is overfitting.</p><p>If you think that this dataset size is enough for you, then you can use the following download script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b833ef4167d34df8f92f1bfa55c8681a/href">https://medium.com/media/b833ef4167d34df8f92f1bfa55c8681a/href</a></iframe><p>To run it:</p><pre>python penguin_download.py</pre><p>This script tries to download 100 images of Adélie, Chinstrap, Emperor and Gentoo penguins. Each penguin type is saved into a dedicated folder called “downloads/&lt;Penguin Type&gt;”. The downloaded images are of medium size in order to reduce download running times and to improve training times later. Image size can be set to “large” or “icon”, or not passed at all to the library.</p><p>Note, Adélie penguin has a French name with an accent on e, however google-image-download returns pretty irrelevant results on this keyword, even if it’s latin-encoded, so you will search for “Adelie” instead..</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*9z5rODc1qD6SyeFf.jpg" /></figure><h4>Download more than 100 images per penguin type</h4><p>google-image-download requires a few modifications in order to download a larger amount of data.</p><p>First, you need to install <a href="https://www.selenium.dev/">Selenium</a>:</p><pre>pip install selenium</pre><p>And then to download chromedriver from <a href="https://sites.google.com/chromium.org/driver/">here</a>. Note, that chromedriver version should match your chrome version (you can check your chrome version <a href="https://www.whatismybrowser.com/detect/what-version-of-chrome-do-i-have">here</a>).</p><p>After the download is finished, you need to copy chromedriver file to the folder with the download script:</p><pre>cp ~/Downloads/chromedriver .</pre><p>MacOS might refuse to run chromedriver so this command can help fix the issue:</p><pre>xattr -d com.apple.quarantine chromedriver</pre><p>Here is the modified script that downloads 150 images per penguin type. Running it takes a while to complete so now you can go and get yourself a cup of coffee.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5570965ec10cb676968f6ebee30958c9/href">https://medium.com/media/5570965ec10cb676968f6ebee30958c9/href</a></iframe><h3>Clean the data</h3><p>Data cleaning is a crucial step in the process of training deep learning models because of the principal <a href="https://en.wikipedia.org/wiki/Garbage_in,_garbage_out">“garbage in, garbage out”</a>. If you train the model with faulty or incorrect images it will fail to learn and will give bad results. It is even more important when training on a small dataset as each image has a much larger effect on the training outcome than in datasets that consist of thousands or millions of images.</p><p>To clean the data you need to browse manually through the images and delete all the images that are not relevant. This includes drawings, pictures of penguins taken from too far away, pictures of multiple penguin species, pictures of penguin dolls and more. Everything that is not an image of a live penguin should be deleted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/0*AVqqsNucuzED6oxn" /><figcaption>An image of a cute Emperor penguin doll that should be removed from the dataset, <a href="https://www.bookvine.com/prod-20-1-96-121/baby-emperor-penguin-puppet.htm">https://www.bookvine.com/prod-20-1-96-121/baby-emperor-penguin-puppet.htm</a></figcaption></figure><h3>Balance the data</h3><p>Since some of the image downloads may fail and quite a few images are removed from the data in the cleaning phase you might get a dataset that is not balanced, meaning that some classes get significantly less images then the others. This might affect training results and there are several methods to tackle this problem.</p><p>To see how the dataset is balanced it is enough to count the number of images in the downloads directory.</p><p>To count the penguin images run:</p><pre>find downloads -type f -not -name &quot;.*&quot; | cut -d/ -f2 | sort | uniq -c</pre><p>These are the numbers of relevant images that I obtained after downloading 150 images per penguin type and cleaning the dataset:</p><pre>119 Adelie Penguin</pre><pre>124 Chinstrap Penguin</pre><pre>103 Emperor Penguin</pre><pre>126 Gentoo Penguin</pre><p>The classes are fairly balanced in this scenario.</p><h3>Split the data</h3><p>The train-test split is important in order to estimate the performance of the model. We will split the data into 3 parts: train, validation and test, which will have the sizes: 80%, 10% and 10% of the data, respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/0*fiWfS8dD_CXcu41m.jpg" /></figure><p>Splitting the dataset is easy. First, you need to install a python library called <a href="https://pypi.org/project/split-folders/">split-folders</a>:</p><pre>pip install split-folders</pre><p>Then, you need to run this command:</p><pre>python -c &quot;import splitfolders; splitfolders.ratio(&#39;downloads&#39;, output=&#39;output&#39;, seed=1337, ratio=(.8, 0.1, 0.1))&quot;</pre><p>This command splits the dataset according to the specified ratio. It generates a folder called “output” with the following structure:</p><pre>ls output/</pre><pre><strong>test</strong>/  <strong>train</strong>/ <strong>val</strong>/</pre><p>Each subfolder now has a dedicated folder for each penguin type. This is how the train folder should look like:</p><pre>$ ls output/train/</pre><pre><strong>Adelie Penguin</strong>/    <strong>Chinstrap Penguin</strong>/ <br><strong>Emperor Penguin</strong>/   <strong>Gentoo Penguin</strong>/</pre><h3>Zip and upload the data</h3><p>Now it’s time to create a zip file with all the images and upload it to a place where it can be accessed during training.</p><p>To zip the output folder into a file called data.zip you need to run:</p><pre>zip -r data.zip output</pre><p>Now upload the zip file into your Google Drive. You will use it as your cloud storage.</p><h3>Train</h3><p>(If you only want to run training you can skip the dataset preparation phase and download the data through <a href="https://drive.google.com/file/d/1i8Ayy8zsKeI40Lt4pgQOKRZfzJhu1-3I/view?usp=sharing">this link</a>)</p><h4>Transfer learning</h4><p>Transfer learning is a technique that lets you use a model that was previously trained on a large dataset for a different but similar task. The intuition behind transfer learning for image classification is that if a model is trained on a large and general enough dataset (like ImageNet), this model will effectively serve as a generic model of the visual world.</p><p>For more information on transfer learning you can refer to <a href="https://cs231n.github.io/transfer-learning/">CS231n notes.</a></p><h4>The setup</h4><p>The training code is based on this <a href="https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html">PyTorch tutorial</a> for transfer learning. The tutorial explains how to use transfer learning of ResNet18 model for classification of 2 classes: ants and bees.</p><p>I created a notebook with a few modifications and improvements of the tutorial code. Notebook code is available <a href="https://github.com/asyaf/fun_mini_projects/blob/master/penguin_classification/transfer_learning_penguin.ipynb">here</a>.</p><p>This notebook is designed to be executed on <a href="https://colab.research.google.com/">Google Colab</a>. It will require some changes for you to execute it. We will now go over the major parts of the notebook and the modifications I added to it.</p><h4>Load the data into Google Colab</h4><p>To let Google Colab access your Google Drive you need to execute the following lines:</p><pre>from google.colab import drive</pre><pre>drive.mount(&#39;/content/drive&#39;)</pre><p>Next you need to replace the path of the data file with the location on your Google Drive:</p><pre>DATA_FILE = ‘drive/My\ Drive/Data/penguin\ data/data.zip’</pre><p>Last step at this stage is unzipping the zip file such that the images it contains can be accessed by PyTorch:</p><pre>!unzip $DATA_FILE</pre><h4>Create dataloaders</h4><p>You need to setup 3 types of datasets: train, validation and test. Each dataset requires a few transformations that are done on the data:</p><ul><li>Images are resized to the input size of the network, which is 224*224.</li><li>Data is converted into tensor format.</li><li>Image data is normalized according to the mean and standard deviation of ImageNet (this is a common practice, and is also explained in <a href="https://pytorch.org/vision/stable/models.html">the documentation on pre-trained models in PyTorch</a>)</li><li>For training the augmentation RandomHorizontalFlip is also added. This allows to create more data samples by randomly flipping the image along the horizontal axis.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bcf460e0c268851020e428e37ae45195/href">https://medium.com/media/bcf460e0c268851020e428e37ae45195/href</a></iframe><h4>Add Tensorboard logging</h4><p>Tensorboard is a tool for measurement and visualization of the training process. You will track the loss and accuracy of the model by adding a few lines to the training code.</p><p>To setup tensorboard execute this code before starting training:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9a6bb8d2df67a85e1c03b9b631de3f8/href">https://medium.com/media/f9a6bb8d2df67a85e1c03b9b631de3f8/href</a></iframe><p>Also, add the code below to “train” function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b04f8cec3f642ba0391b3795268a999/href">https://medium.com/media/7b04f8cec3f642ba0391b3795268a999/href</a></iframe><p>After training is finished you can view the collected metrics by running:</p><pre>%tensorboard --logdir=&#39;./runs&#39;</pre><h4>Train</h4><p>Run training by executing:</p><pre>model_ft = train_model(model_ft, criterion, optimizer_ft, exp_lr_scheduler, num_epochs=24)</pre><p>In the end of the training process you should see what was the accuracy of the best model on the validation set. I got the following result:</p><pre>Best val Acc: 0.977778</pre><p>Here are some examples of the results taken from the validation set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*2kMMGj8kG9QqUWRhtjSv-w.png" /></figure><h4>Run model on test</h4><p>After training is finished you might want to know how well the model generalizes. This can be achieved by calculating the accuracy of the model on the test set. The code below also shows some images the model was wrong on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1635ce656f9f1acf33890b36b5b6ceaf/href">https://medium.com/media/1635ce656f9f1acf33890b36b5b6ceaf/href</a></iframe><h4>Save model</h4><p>Save the model to file by running:</p><pre>torch.save(model_ft, ‘model.pt’)</pre><p>To persist the trained model you can either download it:</p><pre>from google.colab import files</pre><pre>files.download(‘model.pt’)</pre><p>or copy it to your Google Drive by running:</p><pre>!cp model.pt &quot;drive/My Drive/Data/&quot;</pre><h3>Conclusion</h3><p>Creating a custom image classification model is a very common task in computer vision. By leveraging Google Images and existing pre-trained models this task can be achieved in a few hours. I hope that this guide will help you solve your cool image classification problem, whether it involves penguins or not.</p><p><a href="https://medium.com/mlearning-ai/mlearning-ai-submission-suggestions-b51e2b130bfb">Mlearning.ai Submission Suggestions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8be9cd68121d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I went from C++ to Python: a conceptual change]]></title>
            <link>https://medium.com/free-code-camp/how-i-went-from-c-to-python-a-conceptual-change-8bf29d059428?source=rss-654ea7ef5a7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bf29d059428</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Asya Frumkin]]></dc:creator>
            <pubDate>Fri, 11 Jan 2019 00:03:41 GMT</pubDate>
            <atom:updated>2019-01-11T00:03:41.387Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EcvHYcjxXGGMn-L1NUme5g.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/xDxiO7sldis?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Pop &amp; Zebra</a> on <a href="https://unsplash.com/search/photos/change?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>People say that coding in Python is so easy that even a 6 year old can do it. This was the thought that I had in mind when I started coding in Python at work. I had been a full-time software developer for 4 years at that time, writing mainly in C++ on Linux, heavily using the QT library. However, I wrote bad Python code at first.</p><p>It has been around 3 years since I’ve made that switch and I think that it’s a good point to sum-up the progress that I’ve made during this time. When looking back, I didn’t only change my main programming language, but also changed my work environment and the way I think about code.</p><p>I won’t go into the details and differences between C++ and Python, as there are <a href="https://www.educba.com/python-vs-c-plus-plus/">numerous resources online</a>, but rather will describe my own experience. I hope that this post would be useful for people going through the same transition that I did.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cJRAtfMPu_7QGFyq2n_FiQ.jpeg" /><figcaption>Jumping from C++ to Python (Photo by <a href="https://unsplash.com/photos/TZ-D7A7Oy0s?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Erik Dungan</a> on <a href="https://unsplash.com/search/photos/deep-dive?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>)</figcaption></figure><h3>C++ is diving, Python is snorkeling</h3><p>C++ feels like diving into the magical mysteries of the sea - it is beautiful, but requires more learning and practice, and overall, the distance that you cover is not that big. Python is a bit like snorkeling - you see the beauty as soon as you stick your head into the water, but you don’t go much further down. You keep on swimming in shallow waters, and can cover a long distance easily. From this description it is clear, that each of these languages should be used at its right place and time.</p><h4>Diving into C++ and surviving it</h4><p>C++ is more strict and penalizes you more harshly on your mistakes. It’s not an effective coding session if you haven’t gotten a surprising <em>Segmentation fault</em> at least once. Therefore, it requires a deeper understanding of the computer, the compiler and the language. When you go deeper, you can really see and be impressed by beautiful things, like the compilation process and memory management.</p><p>As a C++ programmer I cared more about syntax tweaks and weird examples. I always knew where I allocated memory and how I was releasing it. The programs I wrote were more stand-alone as I preferred to know what was happening inside my code. The main idea was, that code that someone else wrote was less reliable, more error-prone, and might blow-up your memory usage.</p><p>My main everyday tools were <strong>Vim </strong>with numerous plugins for writing code, <strong>GDB </strong>for debugging and <strong>Valgrind </strong>for analyzing my memory usage and errors. I compiled with <strong>g++ </strong>and wrote my own <strong>Makefiles</strong>. Back then, I didn’t feel that an IDE would benefit me, but would rather slow things down and make me lose touch with my code. <em>In retrospect, I relied heavily on the compiler for finding my type errors</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*jMgqp7rYd9uPMcpwueJKdQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/Td9FnTMHu0A?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jakob Boman</a> on <a href="https://unsplash.com/search/photos/diving?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h4>Shallow swimming in Python</h4><p>One of the first things that you need to learn when switching to Python is how to let go - you don’t know what is happening under the hood, where memory is allocated and released, and it’s OK. You are also encouraged to use code that was written by others, packed into libraries, as it saves you time and helps you code faster. It doesn’t mean that you need to write code that is dog-slow and relies on unmaintained and nonfunctional libraries, but the focus is definitely different.</p><p>When I started coding in Python, I first wrote C++ code in Python. It worked, but I didn’t gain any benefit from the language. My coding improved when I started writing in a more “Pythonic” fashion and started using libraries, and more advanced concepts such as <a href="http://book.pythontips.com/en/latest/generators.html">generators</a>, <a href="http://book.pythontips.com/en/latest/decorators.html">decorators </a>and <a href="http://book.pythontips.com/en/latest/context_managers.html">contexts</a>.</p><p>As a Python developer I tend to look first for the library that solves the issue at hand. Python has a rich<a href="https://pypi.org/"> library ecosystem</a> and community that supports it. There are libraries for doing practically anything. Here are some handy ones that I use on a daily basis: <a href="http://www.numpy.org/"><strong>NumPy </strong></a>for numerical calculations, <a href="https://opencv.org/"><strong>OpenCV </strong></a>for computer vision, <a href="https://docs.python-guide.org/scenarios/json/"><strong>json </strong></a>for reading json files, <a href="https://www.scipy.org/scipylib/index.html"><strong>SciPy</strong></a><strong> </strong>for scientific calculations, <a href="https://docs.python.org/3.7/library/sqlite3.html"><strong>sqlite3 </strong></a>for databases.</p><p>My everyday tool is<strong> PyCharm </strong>(yes, an IDE) with <strong>IdeaVim </strong>plugin. I started using it mainly due to the fact that it’s a powerful debugger, which is much friendlier than the default Python debugger, <strong>pdb</strong>. I also use <strong>pip </strong>for installing libraries that I need. I don’t monitor my memory usage anymore unless I really have to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N-QqfPSLuC_ainXH45ZNfg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/fYjIBVvUuRM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Channey</a> on <a href="https://unsplash.com/search/photos/snorkeling?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Some Practical Tips</h3><p>If you are a C++ developer, and you consider starting to code in Python, here are my advice for you:</p><ul><li><strong>Get rid of old habits</strong> — Stop using the C++ compiler as a debugger. Don’t over-optimize memory usage. Avoid writing C++-like code. And by all means, try not to rely on types.</li><li><strong>Get new habits </strong>— Start using libraries. Write Pythonic code (but don’t overdo it). Keep things readable. Use more complex concepts such as generators/decorators/contexts. Try PyCharm.</li><li><strong>Use C++ and Python common libraries</strong> — Some C++ libraries, like OpenCV and QT, have a Python interface. It is easy to start using the same library in Python rather than learning a new library from scratch.</li><li><strong>Don’t forget your origins </strong>— Sometimes Python is just too slow or not optimal for the task. This is when your C++ knowledge kicks in. The are many ways (<strong>SIP</strong>, <strong>ctypes</strong> etc) to use C++ code inside Python.</li></ul><h3>Bottom Line</h3><p>No matter what other people say, switching to a different programming language, especially to a language that is fundamentally different than the one you are used to, is not easy. Take the time to learn, to dig in, to discover. But most importantly, understand that not only the language should change, but also your coding style and work methodology.</p><p>Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bf29d059428" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-i-went-from-c-to-python-a-conceptual-change-8bf29d059428">How I went from C++ to Python: a conceptual change</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>