<?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 Ashish lotake on Medium]]></title>
        <description><![CDATA[Stories by Ashish lotake on Medium]]></description>
        <link>https://medium.com/@ashishlotake?source=rss-5cd5daf4498f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cxH4FkHberrji5JzgaLWDw.jpeg</url>
            <title>Stories by Ashish lotake on Medium</title>
            <link>https://medium.com/@ashishlotake?source=rss-5cd5daf4498f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:20:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashishlotake/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[Do you really know what is data science?]]></title>
            <link>https://medium.com/codex/do-you-really-know-what-is-data-science-6694ce633ddb?source=rss-5cd5daf4498f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6694ce633ddb</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learnign]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data-analyst]]></category>
            <dc:creator><![CDATA[Ashish lotake]]></dc:creator>
            <pubDate>Wed, 19 Oct 2022 21:27:57 GMT</pubDate>
            <atom:updated>2022-10-25T17:38:55.892Z</atom:updated>
            <content:encoded><![CDATA[<p>Although data science very hot topic and considered the sexiest job of the 21st century, still many of us can’t define DATA SCIENCE.</p><h3>Why define?</h3><p>Last year after my graduation I had a conversation with my dad</p><p><em>dad:- So what’s now?</em><br><em>me:- I will learn Data Science and Machine Learning</em>.<br><em>dad:- Why and What is Data Science?</em><br><em>me:- Its has the best job market, best pay and I can easily land a job with XXX amounts in just one year</em>.<br><em>dad:- Sounds great, but what it is?</em><br><em>me:- I will work with data</em><br><em>dad:- Great, but WHAT IS DATA SCIENCE?</em><br><em>me:- 😵 ………………………..…</em></p><h3>What various sources says?</h3><blockquote><em>“</em>Data science combines math and statistics, specialized programming, advanced analytics, artificial intelligence (AI), and machine learning with specific subject matter expertise to uncover actionable insights hidden in an organization’s data. These insights can be used to guide decision making and strategic planning.” — <a href="https://www.ibm.com/cloud/learn/data-science-introduction"><strong>IBM</strong></a></blockquote><blockquote>“Data science is the process of building, cleaning, and structuring datasets to analyze and extract meaning. It’s not to be confused with data analytics, which is the act of analyzing and interpreting data. These processes share many similarities and are both valuable in the workplace.” —<a href="https://online.hbs.edu/blog/post/what-is-data-science"> <strong>Harvard</strong></a></blockquote><blockquote>“Data science is an inter-disciplinary field that uses scientific techniques from statistics and computer science to systematically extract knowledge from data.” — <a href="https://openlearninglibrary.mit.edu/courses/course-v1:MITx+HST.953x+3T2020/courseware/b0cd3598ed5940249f6dbbd79707f468/8d8cfbae8dd34fdfb5a019df22cadccc/?activate_block_id=block-v1%3AMITx%2BHST.953x%2B3T2020%2Btype%40sequential%2Bblock%408d8cfbae8dd34fdfb5a019df22cadccc"><strong>MIT- OCW</strong></a></blockquote><blockquote>“Data Science is the science of collecting, storing, processing, describing and modelling data<em>.” — </em><strong>IIT Madras</strong></blockquote><h3>What I have understood after learning academically for almost 1 year.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IdwneR76YA6EEdO9JHU7qQ.png" /><figcaption>Image by author — Data Science Workflow</figcaption></figure><p>Data science is an assortment of several tasks (roughly 5 tasks) from collecting data to modeling, these tasks are not concrete as they change depending on the problem at hand.</p><p>eg:- steps required to build a fake news detector will have significantly different steps when compared to building an Image Classifier.</p><p>We will go through each stage/step briefly.</p><ol><li>Collect Data</li><li>Store Data</li><li>Processing Data</li><li>Analyzing &amp; Describing Data</li><li>Building Model</li></ol><p>Now many of us who have worked/are working or trying to land a role of data scientist position may have done only one or a few stages, as I told it all depend upon the problem at hand, some of us are more concerned about building a model and some of are more concerned about the Analyzing/Describing data.</p><p>Many new terms have come forth like Data Engineer, Data Analyst or Business Intelligence Analyst, Machine Learning Engineer, etc</p><p><strong>Data Engineer</strong>:- Collecting, Storing, and Analyzing data at scale.<br><strong>Data or BI Analyst</strong>:- Processing, Analyzing and Describing Data.<br><strong>Machine Learning</strong>:- Focus on building Models for making the prediction.<br><strong>Data Science</strong>:- “Data Science is the science of collecting, storing, processing, describing and modelling data<em>.” — IIT Madras</em></p><h3>Data collections</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*qROOWiFLos5B_4-uYTwO3A.png" /><figcaption>image from <a href="http://manypixels.co/">manypixels.co</a></figcaption></figure><ol><li>It depended on what question we are trying to answer</li><li>Depends upon which type of environment we are working in like we are working in FAANG like companies that are data rich or are we working in startups where we need to collect data.</li></ol><h4>To better understand this, I will try to explain the various situation you may face as a data scientist:-</h4><p>Recommend a new friend to a user? And we are working in Facebook/LinkedIn companies that have a social network platform.</p><ul><li><em>Here, the company already has a humongous amount of data collected about users it may be stored in a relational database or non-relational database, so all we need to write a script that can acquire data from these sources.</em></li></ul><p>Give user jobs based on interest from various job platforms (Linkedin, indeed, etc)</p><ul><li><em>Now in this case acquiring the API form, these sources are either expensive or don’t have an API. So here we need to write a web scrapping script so to acquire data from these sources and we need to make sure we are legally allowed to use these data.</em></li></ul><p>Predict which party will win the elections.</p><ul><li><em>Now as data scientists, we will be collecting data from users by doing surveys, then people’s sentiment/polarity towards parties by going through various social platforms.</em></li><li><em>Here we need to go out of our comfort zone and look at various ways to acquire data by designing an experiment to collect data that will make sense. Data is not readily available.</em></li><li><em>Here we need statistics to build experiments and get insights from these experiments.</em></li></ul><h3>Storing Data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*lFavp0y6EEW8yuqOS3goKQ.png" /><figcaption>image from <a href="http://manypixels.co/">manypixels.co</a></figcaption></figure><p>When I was in school, the teacher used to take attendance in a tabular format like this:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAQPCrqfjcEooBze7MLanQ.png" /><figcaption>Tabular Data example</figcaption></figure><p>I hope you were not like me!</p><p>And each time a new student joins the class new row is created.</p><p>This is what a relation database looks like a structure of tabular data, and the large amount of data collected in the early days have stored data in this format.</p><p>To access data from the relational databases we use SQL (structured query language)</p><p><strong>Now think about Amazon</strong>, Amazon is an eCommerce platform, Video Streaming platform, Online audio-book platform, Cloud provider, and god know what other area amazon deals in.</p><p>Now, in this case, Amazon can’t store data all consumer data in one relational database, so they will have multiple databases one for each platform.</p><p>Users can have an account in all or one of the services provided by amazon.</p><p>Now, if you are working for amazon, as a data scientist, you need a way by which we can integrate all these separate databases to do analysis, so we gain insight about a user to recommend products or give better offers.</p><p>So to analyze these multiple databases, we need to store them in a <strong>data warehouse</strong> like Amazon Redshift.</p><p>Now when we use a platform like Instagram, we post images, videos, and text (captions) speech, and storing this in a structured format is not possible, so we store this in unstructured or semi-structured format (JSON, XML, etc).</p><p>Now Instagram has a large number of users in billions, and this unstructured data is getting uploaded or generated in high volume, high variety (data in images, videos, speech, images, etc ), and high velocity (at very high-speed data is getting generated).</p><p>Hence, a new term came <strong>BIG DATA</strong></p><p>“<strong><em>Since the evolution of writing the amount of data collected over 5 millennia up to 2003 is estimated at 5 exabytes. Since 2013, humans are generating the same amount of data every day.”</em></strong></p><p>So to store this BIG DATA, we came up with Data Lakes, like Amazon Redshift.</p><p>Some knowledge of Hadoop, when we need to store the file in HDFS.</p><h3>Processing Data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*19vZqDUSkJ5AXuJF3BP0aA.png" /><figcaption>image from <a href="http://manypixels.co/">manypixels.co</a></figcaption></figure><p>Let’s say we are crawling data from various job portals, we wrote a script and it returns a JSON format, now here need to:-</p><h4>ETL</h4><ul><li><strong>E</strong>xtract data from this JSON/CSV.</li><li><strong>T</strong>ransform the data, let’s say the date in JSON is in Unicode format, so we need to transform it into the required format dd-mm-yyyy.</li><li><strong>L</strong>oad, the data in pandas data frame, or some data warehouse</li></ul><h4><strong>Data Cleaning:</strong></h4><ul><li><strong>Missing Values:-</strong> Let’s say for some jobs the salary or date is not given, so we need to handle these missing values. We will use various Imputation methods to fill these missing values.</li><li><strong>Correct Spelling errors</strong></li><li><strong>Find the remove outliers</strong>:- lets day a company has entered its salary of 500,000K when other companies are offering 500K for the same position, then 500,000K is an outlier and we need to handle these.</li></ul><h4><strong>Standardizing and Normalizing</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqljtnl5nnZhleiQEHJgEg.png" /><figcaption>Image by author — Effect of Normalization and Standardization</figcaption></figure><p><strong>Format:- </strong>Some companies have given salaries like 100k and some have given like 100000, so we need to make them on the format.</p><p>We need to make sure all the columns in the datasets must have the same scale, we use <strong>Standardization and Normalization</strong></p><ul><li>Expected year of experience have min value of 0 and a max of 10</li><li>Salary has min value of 100k and max value of 900k</li><li>when we input these values into our algorithm the model will not perform well, so to achieve good performance, we need to make sure all the values must be in the same range.</li><li><strong>Normalization</strong> will ensure all the numerical columns are in the range of 0 and 1.</li><li><strong>Standardization</strong> will ensure all the columns will have zero mean and unit variance.</li></ul><h4><strong>How to process big data?</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*c7XfiyFr9qKy1-pQAdpoFw.png" /><figcaption>image from <a href="http://manypixels.co/">manypixels.co</a></figcaption></figure><p>We need to use <strong>distributed processing</strong>, which means dividing data into smaller chunks and distributing these chunks to various servers/systems for processing each chuck separately and finally combining them. This is where <strong>Hadoop (Map Reduce)</strong> comes into play.</p><h3>Analyzing/Describing data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*zaFeKmu1scQkQusNMS8ZQQ.png" /><figcaption>image from <a href="http://manypixels.co/">manypixels.co</a></figcaption></figure><p>Look at columns in data, compute some statics, and plot data to find out trends or relations and important columns in your data.</p><h4><strong>Data Visualization</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NV25R_oF8pbM088IuzOS-g.png" /><figcaption>Image by author — Examples of plots from synthetics data</figcaption></figure><p>We are crawling data from various job portals.</p><ul><li>Now, what if want to show which sector or which position is getting the most paid?</li><li>Which companies have the highest number of position openings.</li><li>Correlation between salary and experience.</li><li>Job opening last year vs this year</li></ul><h4><strong>Summarizing data</strong></h4><ul><li>What is the typical number of jobs posted on daily basis for a particular position? → We can use <strong>mean, median</strong>, and <strong>mode</strong></li><li>What’s the typical variation in salaries? → We can use <strong>STD Deviation</strong> and <strong>Variance.</strong></li></ul><h3>Building Model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*KLMcMTCpe6Uz7TUicKtnQA.png" /><figcaption>image from <a href="http://manypixels.co/">manypixels.co</a></figcaption></figure><p>There are two ways of building a model from data;-</p><ol><li>Statistical modeling</li><li>Algorithm modeling (Machine Learning &amp; Deep Learning)</li></ol><h4><strong>Statistical modeling</strong></h4><p>Build a very simple Statistical model to conclude from the data</p><blockquote>Most algorithms are designed keeping in mind that the underlying distribution of data follows a normal distribution.</blockquote><p>We are crawling data from various job portals.</p><p>Now as Data scientists, we want to build a model from this data, to answer various questions or come up with new insights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p8l1i8yTlPPfV25aRVb1IA.png" /><figcaption>Image by author — Linear relation between salary &amp; Experience</figcaption></figure><p>Here we have used a simple function<strong><em> y = mx+b</em></strong>. We also found that salary tends to increase linearly as experience increases, so now a data scientist can make a robust statement → <strong><em>I am 99% confident that if a person has an experience of 15+ years he/she can land a job of 100K+.</em></strong></p><p>In building a model we typically find the underlying data distribution, model the underlying relation, and give a robust statistical score. In statistical modelling we care more about why a certain phenomenon is happening.</p><h4><strong>Algorithm modeling (Machine Learning)</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2qGxBG8yUZVmgQd_py13OA.png" /><figcaption>Image by author — Low dimensional input</figcaption></figure><p>If we want to build a very complex model, and our data can’t be represented by a simple straight line, for this, we use an alternate approach called Machine Learning.</p><p>In the previous paragraph, we concluded that a person’s salary only depends on one-factor experience.</p><p>Now, we all know that it’s not true in real life, that salary depends on various factors like job location, company type (FAANG, Startups, etc), company past performance, applicants for a position, economy, job type (remote or in-office) and other various factors.</p><p>To find build a model so to find the relations between this input and output, we need to do something complex.</p><p><strong><em>y = f(x),</em></strong> we need a general flexible function, where we can give any input.</p><p>So what is the end goal of machine learning:- find the function <strong><em>f</em></strong> using data and some optimization techniques.</p><p>After we find the function <strong><em>f</em></strong>, we can just input <strong><em>x</em></strong> to <strong><em>f</em></strong> and get the output <strong><em>y</em></strong>.</p><p>Now for machine learning our main focus, is to try to make out predicted values to be as close to our original values.</p><h4><strong>Algorithm modeling (Deep Learning)</strong></h4><p>When we have very high-dimensional data and we want to learn the very complex relationship between the inputs and the outputs, we typically tend to use Deep learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYsAjW6VOZx5HfGswh6RXQ.png" /><figcaption>Image by author — Image to a vector</figcaption></figure><p>Let’s say we want to find out if a person has breast cancer or not using MRI scans, let’s say the MRI scan is an image of size 1000x1000 pixels, so each image is represented using 1000000 columns (pixels values) and we have thousands of images like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hrx30tqvbDGREhATJ2mwAA.png" /><figcaption>Image by author — Deep learning high dimensional input</figcaption></figure><p>Here out of 1000000 pixels, only 1000 pixels are contributing towards deciding whether cancer is benign or malignant, but we don’t know, so we input all 1000000 pixels input the deep learning model, and the model outputs the cancer is benign or malignant.</p><h4><em>I think I helped you better understand “what is data science ?”</em></h4><blockquote><strong>Data Science is the science of collecting, storing, processing, describing and modelling data<em>.</em></strong></blockquote><h3>Reference</h3><ul><li><a href="https://www.ibm.com/cloud/learn/data-science-introduction">https://www.ibm.com/cloud/learn/data-science-introduction</a></li><li><a href="https://online.hbs.edu/blog/post/what-is-data-science">https://online.hbs.edu/blog/post/what-is-data-science</a></li><li><a href="https://openlearninglibrary.mit.edu/courses/course-v1:MITx+HST.953x+3T2020/courseware">https://openlearninglibrary.mit.edu/courses/course-v1:MITx+HST.953x+3T2020/courseware</a></li></ul><p><em>Originally posted at </em><a href="http://ashishlotake.com/"><em>ashishlotake.com</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6694ce633ddb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/do-you-really-know-what-is-data-science-6694ce633ddb">Do you really know what is data science?</a> was originally published in <a href="https://medium.com/codex">CodeX</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build An Automated Labeling system]]></title>
            <link>https://ashishlotake.medium.com/build-an-automated-labeling-system-f960419e458b?source=rss-5cd5daf4498f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f960419e458b</guid>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[labelling]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ml-so-good]]></category>
            <dc:creator><![CDATA[Ashish lotake]]></dc:creator>
            <pubDate>Thu, 13 Oct 2022 20:09:57 GMT</pubDate>
            <atom:updated>2022-10-15T15:49:56.241Z</atom:updated>
            <content:encoded><![CDATA[<h4>The article walks through the process of how I build an labeling system, go from theory to deployment.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B3jDNcRcyJaNYmHN82CSsg.png" /><figcaption>image from undraw.co</figcaption></figure><h3>Let’s understand why we need Labels</h3><p>Most recent developments in AI, including computer vision, natural language processing, predictive analytics, autonomous systems, and a wide range of applications, are driven by machine learning. We need data so these algorithms can learn from them so can generalize well. Most of the transitional algorithms need label data, to work. When it comes to deep learning, the amount the data requires is humongous, particularly in deep learning neural networks, compared to traditional machine learning algorithms, to build a model that achieves the appropriate levels of accuracy. Therefore, it should go without saying that for the resulting machine-learning models to be accurate, the machine-learning data must be clean, accurate, full, and well-labeled. Whereas it has always been the case that garbage in garbage out, it is especially the case with regard to machine learning data. Around 80% of AI/ML project time is spent on gathering, organizing, and labeling out in computing.</p><blockquote>We can acquire large amount of unlabelled data, but manually labeling is expensive</blockquote><p>I hope now you have a good understanding of the importance of labeled data for our machine learning project.</p><h3>What we will have at then end!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/0*upOH0fH2DIwuK_mf.gif" /><figcaption>Source <a href="https://ashishlotake-active-labelling-system-project-app-14t6bq.streamlitapp.com/">https://ashishlotake-active-labelling-system-project-app-14t6bq.streamlitapp.com/</a></figcaption></figure><p><a href="https://ashishlotake-active-labelling-system-project-app-14t6bq.streamlitapp.com/">Web App</a>, <a href="https://hub.docker.com/r/ashishlotake/active-labelling-system">Docker Image</a> and all IPYNB <a href="https://www.ashishlotake.com/blog/active-labelling-system#all-jupyter-notebooks">Colab Link</a></p><h3>What do we need going forward</h3><p>The irony here is we need labeled data, the reason is simple the model should know what labels are before it can label anything, then it should also need to know which label corresponds to which image.</p><blockquote>It’s like to multiply money we need money</blockquote><ul><li>We will be using deep learning, so GPU is a must, use Google Colab.</li></ul><p>If you have these two things you can follow along can build your labeling system</p><h3>Dataset in hand</h3><p>I will be using the Caltech101 data set, but you can use any other dataset. Let’s briefly go over the Caltech101 dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qNRRtJpijqSP3_VQX9hEEg.png" /><figcaption>Image by Author</figcaption></figure><p>It consists of 9146 images, split unevenly between 101 distinct object categories and a background category. According to the official website, there are about 40 to 800 images per category, additionally, most of the categories have around 50 images in the dataset. Such varying images per category can be a real problem when trying to achieve high accuracy in deep neural network training. The size of each image is roughly 300 x 200 pixels. The format of images is RGB, meaning we have 3 color channels.</p><p>Now let’s look at the class distribution</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MDPxaZCjeV25cMLYBCfoug.png" /><figcaption>Image by Author</figcaption></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F62TTKM9F5B5ni%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F62TTKM9F5B5ni%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F62TTKM9F5B5ni%2F200.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="319" frameborder="0" scrolling="no"><a href="https://medium.com/media/cef39ab877670ffa5018fb41fa02e381/href">https://medium.com/media/cef39ab877670ffa5018fb41fa02e381/href</a></iframe><p>We can see that the airplanes and motorbikes categories have the highest number of images, around 800, and the lowest number of images may be as low as 40 for most of the labels. With such an imbalanced dataset, it will be difficult to get a good performance from the network if we decided to train from scratch.</p><h3>Let’s understand the high-level deployment</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*GoayCwRiuITxsM7-Sv-PZQ.png" /><figcaption>Image by Author</figcaption></figure><p>I think the above layout is self-explanatory. Still, I will explain it in few lines:-</p><ul><li>Divide the dataset into three parts using stratified Sampling</li><li>Train CNN and then evaluate unseen data</li><li>Choose the best model</li><li>Create a stremlit web app</li><li>Wrap the stremlit in a container</li><li>Deploy that container on the cloud</li><li>Wola! Your model is now global,</li><li>If the user wants to train the model, take new data and a portion of old data, combine them and retrain.</li><li>Users can then download labeled data.</li></ul><h3>Let’s dive into the real stuff</h3><p>We will get our hands dirty, by creating a baseline model and training it from scratch, I know I told if we train the model from scratch getting good performance will be difficult, but it won’t hurt us, and I will be implementing Alexnet like architecture from scratch so if we didn’t achieve a satisfactory result, we can still say ‘I implemented Alexnet from starch!</p><p>BTW, in the ImageNet ILSVRC challenge in 2012, it was at this contest that AlexNet showed that deep convolutional neural networks can be used for solving image classification, and this was the beginning of a new era.</p><blockquote>When you look at most of the state of art deep learning model, they were derived by experimental study and most of them even don’t have proper mathematical or statistical explanation like traditional machine learning algorithm</blockquote><h4>AlexNet</h4><p>Before creating Alexnet from scratch, let’s have a high overview of the Convolutional-Neural Network (CNN), so you know what’s going on top of what.</p><p>Convolutional Neural Network is formed with the help of different layers stacked on top of one another to perform the image classification task. The architecture of the CNN contains different layers. The whole network itself is divided into two parts:- the <strong>Convolution base</strong> and the <strong>Classifier</strong>. The features are extracted in the convolution base and the classification is done in the classifier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*rDVZWk5paDz0v8kL5ZhysQ.png" /></figure><h4>Layers in Convolution base:-</h4><ul><li>Input Layer — This input layer, accepts raw images and forwarded them to further layers for extracting features.</li><li>Convolution Layer -In this layer number of filters are applied to images for finding features from images.</li><li>Pooling Layer — This layer captures large images and reduces them, and reduces the parameters to preserve important information. It preserves the maximum value from each window.</li></ul><h4>Layers in Classifier:-</h4><ul><li>Fully connect Layer — This layer takes up high-level filtered images and translates them into labels with.</li><li>Output layer — This layer gives the decimal probabilities to each class. Those decimal probabilities are between 0 and 1.</li></ul><p>This is the simplest CNN you can build.</p><p>Now you know the basics of CNN, let’s look at the structure of AlexNet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*FnkbxNJrJTTfAgFNL8isXQ.png" /><figcaption>Image from <br>Advanced Deep Learning with Python by Ivan Vasilev</figcaption></figure><p>That’s a lot to take in, so let’s briefly go over each unique layer</p><p><em>Convolutional layer</em>:- The mathematical term “convolution” refers to the dot product multiplication of two sets of elements. The convolutional layer’s filters/kernels and an array of image data are affected by the convolution operation in deep learning. A convolutional layer is therefore just a layer that contains the convolution operation that takes place between the filters and the images that are processed by a convolutional neural network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*8-ns9EIDKTpeyeHIcruE4A.png" /><figcaption>Image from Nvidia.com</figcaption></figure><p><em>ReLU Activation Function</em>:- A particular activation process that modifies a neuron’s value output. The transformation imposed by ReLU on values from a neuron is represented by the formula y=max(0,x). Any negative values from the neuron are clamped down to 0 by the ReLU activation function, while positive values are left unaltered. Within a neural network, the outcome of this mathematical transformation is used as the input to the next layer and as the output of the current layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*wd1kiULGfjLzexwj3de1xQ.png" /><figcaption>Image by Hossam H. Sultan from researchgate</figcaption></figure><p><em>Max Pooling</em>:- With max pooling, the output is the highest pixel value of pixels that are contained within a unit’s receptive field within a sub-sampling layer. The max-pooling operation below produces an average of the pixels inside the kernel’s receptive field by sliding across the input data with a 2x2 window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*feJOXYgHeWcM_O3n.png" /><figcaption>Image from wikimedia</figcaption></figure><p><em>Batch Normalisation</em>:- By adding a layer that operates on the inputs from the previous layer, batch normalization is a technique that reduces the impact of unstable gradients within a neural network. The operations first standardize and normalize the input values before scaling and shifting operations transform the input values.</p><p><em>Dropout</em>:- The dropout technique reduces the quantity of interconnecting neurons in a neural network at random. Each neuron has a chance to be dropped from the collated contributions from connected neurons at each training step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/0*2u9rvsjtl5yWGr32.png" /><figcaption>Image by Imad Dabbura</figcaption></figure><p><em>Flatten layer</em>:- Takes an input shape and flattens the input image data into a one-dimensional array.</p><p><em>Flatten layer</em>:- Takes an input shape and flattens the input image data into a one-dimensional array.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/0*yX6sTIgp4t1A6k6p.png" /><figcaption>Image from SuperDataScience</figcaption></figure><p><em>Dense Layer</em>:- A dense layer has an embedded number of arbitrary units/neurons within. Each neuron is a perceptron.</p><p><em>Softmax Activation Function</em>:- A specific kind of activation function used to determine the probability distribution of a group of numbers contained within an input vector. The result of a softmax activation function is a vector whose set of values represents the likelihood that a class or event will occur. The vector’s values add up to 1 in total.</p><h3>Let’s write AlexNet Form scratch</h3><p>Keep this architecture in mind:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*saeb9-ZDjHR8YGxb.png" /></figure><p>Downlaod Data and extract from zip file</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c804e7ca85c4c82ee6ad98678b9436d/href">https://medium.com/media/0c804e7ca85c4c82ee6ad98678b9436d/href</a></iframe><p>Stratified Splitting Data into train, val and test folder</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fbfacf7873ae0796412ca8ae9b94779/href">https://medium.com/media/3fbfacf7873ae0796412ca8ae9b94779/href</a></iframe><p>Load Data</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7796f341fcc41d09c8a57da177b7bfb/href">https://medium.com/media/d7796f341fcc41d09c8a57da177b7bfb/href</a></iframe><p>Model from scratch</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56f50840a04428cc0bad7453bc61750b/href">https://medium.com/media/56f50840a04428cc0bad7453bc61750b/href</a></iframe><p>Training Model</p><pre>history = alexnet_scratch.fit(<br>  train_dataset,<br>  epochs=30,<br>  validation_data=validation_dataset,<br>  )</pre><h3>Performance on training from scratch</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e269ec0fbcf09ba29c69b75ff469a6b/href">https://medium.com/media/6e269ec0fbcf09ba29c69b75ff469a6b/href</a></iframe><pre>plot_performance(history)</pre><h3>Performance on training from scratch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/0*u5pMk2M8PIZ3gV5e.png" /><figcaption>Image by Author</figcaption></figure><p>It’s clear is model is overfitting to our training data.</p><h3>Hyper Parameter Tunning</h3><p>Deep learning relies heavily on hyperparameter optimization. The reason for this is that neural networks are extremely difficult to configure and require a large number of parameters to be set. Furthermore, individual models can be very slow to train. We will try to optimize a few of the important hyper-parameters for CNN</p><ol><li>Optimization Algorithm:- Optimizers are techniques that alter the neural network’s weights and learning rate to minimize losses.</li><li>Learning Rate:- The learning rate controls how much to update the weight at the end of each batch.</li><li>Momentum:- Momentum controls how much to let the previous update of the learning rate influence the current weight update</li></ol><p>I tried out three optimizers RMSProp, Adam, and SGD at various learning rates (0.001, 0.005,0.01, 0.05, 0.1), and the best result was obtained by using SGD at a learning rate of 0.01 and 0.05.</p><h4>Optimizers and Learning Rate</h4><p>The result of using SGD as an optimizer at different learning rates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/0*Y1D4I9oONNyFV-zh.png" /><figcaption>Image by Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/0*EXHA_TVyjcnBNi0K.png" /><figcaption>Image by Author</figcaption></figure><p>The result at learning rates 0.01 and 0.05 looks promising, let’s explore more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*6K6QTBzLYgy2Fsu1m8kXIw.png" /></figure><p>By looking at the plot and table, the learning rate of 0.05 looks very good compared to 0.01, but we need to understand that we need our model to perform well on new/unseen data, even if we don’t have a perfect 99–100% score on training data. Now if we focus on the loss of test data learning rate of 0.01 looks good.</p><blockquote>These results will vary during each run, as we are using SGD, which is stochastic in nature.</blockquote><p>We can say both results are very similar at learning rates 0.05 and 0.01, the difference here is due to the stochastic nature of SGD.</p><h4>Momentum</h4><p>Now we will try out this configuration (optimizer =sgd, learning rate =0.01) at various momentum (0,0.3,0.6,0.8,0.9).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/0*iCuTO89zkvv296Yc.png" /><figcaption>Image by Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/0*WB8zOCvJ0phHM8LN.png" /><figcaption>Image by Author</figcaption></figure><p>Let’s focus on top 3 momentums:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*QsYpNSZSDbMPOTH3ocWtsg.png" /></figure><p>Momentum = 0.3, seems to be the better choice, as it has achieved a good result in far fewer epochs as compared when momentum = 0, and models with momentum =0.3 seems to have good generalization compared to other learning rates.</p><h4>What is achieved up till now</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*TCwY2xq4cNoFGW9e2xwXBA.png" /></figure><p>We can see that we were able to increase the models’ validation and test accuracy by 2%, just by tweaking a few hyper-parameters or maybe due to the stochastic nature of SGD.</p><p>The various plots we saw above show that training a network from scratch with such few samples does not result in a good model that learns well from the training set in addition to being capable of well generalizing on unseen data.</p><blockquote>To summaries, training a network from scratch is a difficult and time-consuming task in the case of small datasets.</blockquote><h3>Data Augmentation</h3><p>Image data augmentation is a method for artificially increasing the size of a training dataset by producing altered versions of the dataset’s images. This is done by applying domain-specific techniques to examples from the training data that create new and different training examples.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff573d2f2f9f4d8722f436a0e0063465/href">https://medium.com/media/ff573d2f2f9f4d8722f436a0e0063465/href</a></iframe><p>The following Augmentation will be used:</p><ul><li>Horizontal Flip Augmentation</li><li>Random Rotation Augmentation</li><li>Random Zoom Augmentation</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*dRHee2XauvnUEG1F.png" /><figcaption>Image by Author</figcaption></figure><p>Result after applying data Data Augmentation:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/0*Bh_UvNqKHVNxYCXN.png" /><figcaption>Image by Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/0*-4CCYn_G3VF16-7y.png" /><figcaption>Image by Author</figcaption></figure><p>It looks like applying data augmentation doesn’t seem to improve model generalization for our models’ architecture and dataset.</p><p>There are many to we can go from here:</p><ol><li>Oversampling and Undersampling</li><li>Add new data</li><li>Transfer Learning</li></ol><blockquote>Spoiler -&gt; Only transfer learning works</blockquote><p>If you still want to check out how I did Oversampling &amp; Undersampling and how to add new data points check out the <a href="https://www.ashishlotake.com/blog/active-labelling-system#all-jupyter-notebooks">Jupyter notebook</a> notebook, the <a href="https://www.kaggle.com/datasets/ashishlotake/extendedcaltech101">extended dataset is hosted on Kaggle</a>.</p><h3>Transfer Learning</h3><p>It’s a common and highly effective approach when doing deep learning on a small image dataset is to use a pretrained model.</p><p>Neural networks typically need huge amounts of data to be operationally effective, in this case for classification. To address the issue of low accuracy in training from scratch, it’s possible to use Transfer Learning which uses weights from a pretrained model on a large dataset, if this original dataset is large enough and general enough, the spatial hierarchy of features learned by the pretrained model can effectively act as a generic model of the visual world, and hence, its features can prove useful for many different computer vision problems, even though these new problems may involve completely different classes than those of the original task and it’s used as starting point for training on our small dataset (i.e. Caltech-101).</p><p>There are two ways to use a pretrained model: feature extraction and fine-tuning. We will be using feature extraction. Contents used for image classification comprise two parts: a series of convolution and pooling layers, and at the end a densely connected classifier, the first part is called the convolutional base of the model.</p><p>Feature extraction consists of taking the convolutional base of a previously trained network, running the new data through it, and training a new classifier on top of the output, because the representations learned by the convolutional base are likely to be more generic and, therefore, more reusable. Whereas the representations learned by the classifier will necessarily be specific to the set of classes on which the model was trained.</p><p><em>This is sample of how to do transfer learning using ResNet50, just change the preprocessing_function base on model you choose and the conv_base_res_net base also.</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf2a791cbe4067194a227a77dae4e799/href">https://medium.com/media/bf2a791cbe4067194a227a77dae4e799/href</a></iframe><p>Before feeding the images to the network we need to preprocess them in the same way the images were preprocessed for the pre-trained model.</p><p>We will be testing out 3 model:</p><ul><li>MobileNet</li><li>ResNet50</li><li>InceptionV3</li></ul><p>For my scenario, MobileNet seems to be performing worse than the baseline model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/0*13cLLenvdHwIpZw5.png" /><figcaption>Image by Author</figcaption></figure><p>Both Resnet50 and Inception have achieved Train and Val accuracy of greater than 90% let’s focus on loss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/0*Di3wZR_SJ8NGEmCa.png" /><figcaption>Image by Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*2CaG9iZH2HmgEWKttQvm6Q.png" /></figure><p>t looks like Resnet with and without data augmentation seems to be performing well, and the size of the model is around ~100 MB</p><h3>Finalizing the model</h3><p>After doing various experiments from hyperparameter tuning, and adding new data to trying out various pretrained models on ImagenNet with and with data augmentation, we decided to go with ResNet50 from keras as the results were great, around 20% improvement from our baseline model on both test and validation set.</p><p>As stated earlier, we need to preprocess images based on the pretrained model we choose, let’s look at preprocessed images from the resnet50 convolutional base:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/0*0zBiESkpL7-CRsRr.png" /><figcaption>Image by Author</figcaption></figure><h3>Retraining</h3><p>For retraining the model we will load the model and continue the model training where it was left, without compiling, so all the weights learned by the classifier will be copied from the previous model and the model will start learning from where it left off.</p><p>We will copy a few data points from the original dataset and then copy new images to that and we will start retraining by combining new and old.</p><h3>Models Interpretability</h3><p>When developing a computer vision application, one of the most fundamental issues is interpretability: why did your classifier think a particular image contained a guitar when all you see is a spanner?</p><p>Deep learning models are frequently referred to as “black boxes” because they learn representations that are difficult to extract and present in a human-readable format. Although this is true for some deep learning models, it is not true for convnets. The representations learned by convnets are highly interpretable.</p><p>We will be focusing on Visualizing heatmaps of class activation in an image. It’s useful for understanding which parts of a given image led a convnet to its final classification decision. This is helpful for “debugging” the decision process of a convnet, particularly in the case of a classification mistake.</p><p>Class activation map (CAM) visualization is a broad family of methods that involves creating heatmaps of class activation over input images. A class activation heatmap is a 2D grid of scores associated with a specific output class, computed for every location in any input image, indicating how important each location is concerning the class under consideration.</p><p>Grad-CAM consists of taking the output feature map of a convolution layer, giving an input image, and weighing every channel in that feature map by the gradient of the class concerning the channel. Intuitively, one way to understand this trick is to imagine that you’re weighting a spatial map of “how intensely the input image activates different channels” by “how important each channel is about the class,” resulting in a spatial map of “how intensely the input image activates the class.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/0*elshUrEDMgV-d2xa.png" /><figcaption>Image by Author</figcaption></figure><p>By looking at the above images, we can say that after the model detected a person and wheel nearby, the model decided it was a wheelchair with 99.64% confidence</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/0*KLLYjT4Qj1grV0BS.png" /><figcaption>Image by Author</figcaption></figure><h3>Building App</h3><p>The model will be used in a real-world scenario, taking continuous raw input from the user and then giving them labeled data as output.</p><p>In this step, a web application was developed using <a href="https://www.ashishlotake.com/blog/streamlit.io">Streamlit</a>. It provides a front-end to the user for uploading multiple images. <a href="https://www.ashishlotake.com/blog/streamlit.io">Streamlit</a> is an open-source python framework for building web apps for Machine Learning and Data Science. It simply converts simple Python scripts to functional, interactive, and shareable web apps within minutes.</p><p>The detailed walk-through on building an app using <a href="https://www.ashishlotake.com/blog/streamlit.io">Streamlit</a> will be covered in a later article.</p><p>The code for the file can be found <a href="https://github.com/ashishlotake/active-labelling-system-project/blob/main/app.py">here</a>.</p><h3>Dockerizing</h3><p>Dockerizing is the process of packing, deploying, and running applications using Docker containers. Docker is an open-source tool that ships your application as a single package with all the necessary functionalities. Docker allows you to pack your application with everything it needs to run (such as libraries) and ship it as a single package — a container. Containers are made up of images that specify their exact contents.</p><p>Reason for creating a docker instead of direct deployment:-</p><ul><li>Easy to use:- Docker simplified the way we deploy applications. You do not distribute the software as source code — you send the binary image of a part of your disk.</li><li>Fast:- Docker containers are just sandboxed environments that run on the kernel. You can create and run the containers in seconds</li><li>Able to create a reproducible environment:- Wrapping everything into containers means that the application you build runs on other devices without friction.</li></ul><h4>Create Dockerfile</h4><p>Create a Dockerfile in the root directory where you have created the Streamlit app:</p><pre>FROM python:3.8-slim<br>EXPOSE 8501<br>WORKDIR /app<br>COPY . .<br>RUN pip3 install -r requirements.txt<br>ENTRYPOINT [&quot;streamlit&quot;, &quot;run&quot;, &quot;app.py&quot;, &quot;--server.port=8501&quot;,&quot;--server.address=0.0.0.0&quot;]</pre><ol><li>Pull python3.8 slim images from docker hub.</li><li>Expose port 8501 to access streamlit from the browser.</li><li>Create a new directory.</li><li>Copy everything from the root directory to the app folder.</li><li>Install the project dependencies.</li><li>Configure a container that will run as an executable.</li></ol><h4>Building image</h4><p>Run this command from the project root directory, where Dockerfile is saved:-</p><pre>docker build -t streamlit:v1 .</pre><p>It will take some time in building images</p><p>After the images are built, run the following command to check images.</p><pre>docker images</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*VLilBXxQjmoyX8rL.png" /><figcaption>Image by Author</figcaption></figure><p>That’s it your docker images it created!</p><h4>Running image</h4><pre>docker run -p 8501:8501 streamlit:v1</pre><p>Now we can access the web app by going to localhost:8501.</p><p>Your streamlit app has been dockerized and now it can be deployed anywhere, and now it can be launched anywhere.</p><h3>Deployment</h3><p>Deployment is the project’s final phase, in which we deploy the entire machine-learning pipeline into a production system, in a real-time scenario. In this final stage, we must deploy this machine learning pipeline to make the research available to end users. The model will be used in a real-world scenario, taking continuous raw input from the user and then giving them labeled data as output.</p><p>I have deployed my app on:-</p><ul><li>Streamlit App</li><li>On AWS EC2</li></ul><p>We will be covering streamlit deployment here, as it’s the fastest and it’s free</p><ol><li>Create a repository on GitHub.</li><li>Push all the code from local to the GitHub repository.</li><li>Now go to <a href="https://www.ashishlotake.com/blog/streamlit.io">Streamlit</a> and create an account.</li><li>Click on New app</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TfmJofuprXeax0PR.png" /><figcaption>Image by Author</figcaption></figure><p>5. Choose the repository where the app is stored and the main file path, where all streamlit code resides, and then press Deploy!.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RcESoruhUjec6b--.png" /><figcaption>Image by Author</figcaption></figure><p>Wola, your app is deployed. Go to the link given by streamlit.</p><h3>Final Thought</h3><p>We have successfully created an active labeling system, using transfer learning which can achieve an accuracy of above 90% on unseen data. Allowing the user to input raw data, label if the model performs poorly and then give the user correctly classified images, by placing them into the correct directory.</p><h3>For all Jupyter Notebook Colab link:</h3><p>IPYNB <a href="https://www.ashishlotake.com/blog/active-labelling-system#all-jupyter-notebooks">Colab Link</a></p><blockquote>This post was originally post <a href="https://www.ashishlotake.com/blog/">here</a></blockquote><h3>References</h3><ol><li><a href="https://www.manning.com/books/deep-learning-with-python">https://www.manning.com/books/deep-learning-with-python</a></li><li><a href="https://machinelearningmastery.com/grid-search-hyperparameters-deep-learning-models-python-keras/">https://machinelearningmastery.com/grid-search-hyperparameters-deep-learning-models-python-keras/</a></li><li><a href="https://keras.io/api/applications/">https://keras.io/api/applications/</a></li><li><a href="https://data.caltech.edu/records/mzrjq-6wc02">https://data.caltech.edu/records/mzrjq-6wc02</a></li></ol><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=f960419e458b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>