<?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 Pooja Mahajan on Medium]]></title>
        <description><![CDATA[Stories by Pooja Mahajan on Medium]]></description>
        <link>https://medium.com/@poojamahajan5131?source=rss-ffddfb0b773f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yJ8Wzf2w9jgrTJl1irw1lw.jpeg</url>
            <title>Stories by Pooja Mahajan on Medium</title>
            <link>https://medium.com/@poojamahajan5131?source=rss-ffddfb0b773f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 30 May 2026 17:16:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@poojamahajan5131/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[Quantization]]></title>
            <link>https://poojamahajan5131.medium.com/quantization-4e4171c9ae46?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e4171c9ae46</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[quantization]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Wed, 19 Feb 2025 17:22:04 GMT</pubDate>
            <atom:updated>2025-02-19T17:22:04.379Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z4Cjxjj7SdoZ8RXB" /><figcaption>Photo by <a href="https://unsplash.com/@kommumikation?utm_source=medium&amp;utm_medium=referral">Mika Baumeister</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Model compression techniques play a crucial role in optimizing deep learning models for deployment, especially in edge computing, real-time applications and especially in the era of LLMs. By reducing model size and improving inference efficiency, these techniques ensure that even complex models like LLMs can be deployed effectively without compromising performance.</p><p>Among these techniques, Quantization stands out as a popular and effective approach to <strong>reducing inference latency</strong>. The key idea is to <strong>reduce model size by using fewer bits to represent the model parameters</strong>. It is easy to implement, requires no special architectural modifications, and can generalize across different model architectures.</p><p>Before delving into quantization, let’s understand few more details about the popular datatypes used in this scenario.</p><h4>Floating-Point Precision and Quantization Shifts</h4><ul><li>FP32–1 sign bit, 8 exponent, 23 fraction</li><li>FP16–1 sign bit, 5 exponent, 10 fraction</li><li>BF16–1 sign bit, 8 exponent, 7 fraction (stands for brain float, this is quite popular choice!)</li></ul><p><em>Key point in this comparison to note is BF16 has a bigger range than FP16 although precision is lesser compared to FP16.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gbaMgGlpyd19ZuBN92eVgw.png" /><figcaption>Comparison of Float datatypes</figcaption></figure><p>Common lower precision datatypes <em>—</em> FP16, BF16, INT16, INT8.</p><p>Common quantization scenarios:- FP32 -&gt; FP16 , FP32 -&gt; BF16, FP32 -&gt; INT8</p><h4>Pros and Cons of Model Quantization</h4><p><strong>Pros</strong></p><ul><li>Ease of implementation</li><li>Reduced memory footprint</li><li>Faster training</li><li>Faster inferencing</li></ul><p><strong>Cons</strong></p><ul><li>Rounding due to reduced number scale can lead to model performance challenges.</li><li>Overflow and underflow can be marked as 0 leading to different understanding.</li></ul><h4><strong>Types of Quantization</strong></h4><ul><li><strong>Quantization Aware Training </strong>— Models are trained in lower precision itself. You can use less memory for each parameter, which allows you to train larger models on the same hardware.</li><li><strong>Post-training Quantization </strong>— Quantization is applied after model training, at inference to optimize efficiency without retraining.</li></ul><p>In this post, we will delve more into post training quantization approaches.</p><h4>Approaches to Post-Training Quantization :-</h4><p><strong>Approach 1 — Downcasting</strong></p><ul><li>Downcasting involves converting a model’s parameters to a more compact data type, such as BF16, to reduce memory usage. During inference, computations are performed in this lower-precision format.</li><li>While downcasting generally works well with BF16, using smaller data types may lead to performance degradation. Notably, converting the model to an integer type like INT8 will likely cause incompatibility issues.</li></ul><p><strong>Model Casting</strong></p><ul><li>model.to(DATATYPE): Converts the model&#39;s parameters to the specified datatype.</li><li>model.half() : Converts the model’s parameters to FP16(half precision).</li><li>model.bfloat16(): Converts the model’s parameters to BF16 precision.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1z76SVRRFZtwKtm6vTB5vw.png" /><figcaption>Example using “to” method</figcaption></figure><p><strong>Approach 2 — Linear quantization</strong></p><ul><li>Linear quantization reduces the model size by storing only the quantized weights along with the scale and zero-point values required for transformation process.</li><li>It enables the quantized model to maintain performance much closer to the original model by converting from the compressed data type back to the original data type(FP32) during inference, helping to maintain performance while optimizing memory usage.</li><li>So when the model makes a prediction, it is performing the matrix multiplications in FP32, and the activations are in FP32. This enables you to quantize the model in data types smaller than BF16, such as INT8, as well.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*Gkxm0fJD5Bou63NY_l-rLg.png" /><figcaption>Image from — Deeplearning.ai</figcaption></figure><p>As per the above image, during linear quantization FP32 values will be mapped to INT8 and scale and zero parameters will be saved. Dequantization (i.e. mapping back to FP32) can be performed using these linear mappings (scale and zero). While mapping back to FP32, we might not get exactly the same tensors though, as linear quantization will result in the loss of some information known as quantization error.</p><p>For more details and practical implementation refer the code repo <a href="https://github.com/poojamahajan0712/AI_ML_concepts/blob/main/Quantization/Quantization_NB1_pytorch_huggingface.ipynb">here</a>.</p><p>So finally we have made to the end of this blog, and this is just the tip of the quantization iceberg !</p><p><strong>References</strong>:-</p><ul><li><a href="https://learn.deeplearning.ai/courses/quantization-fundamentals/lesson/1/introduction">https://learn.deeplearning.ai/courses/quantization-fundamentals</a></li><li><a href="https://www.amazon.in/Designing-Machine-Learning-Systems-Production-Ready/dp/1098107969">https://www.amazon.in/Designing-Machine-Learning-Systems-Production-Ready/dp/1098107969</a></li><li><a href="https://huggingface.co/docs/optimum/en/concept_guides/quantization">https://huggingface.co/docs/optimum/en/concept_guides/quantization</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e4171c9ae46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Batch vs Online Prediction]]></title>
            <link>https://poojamahajan5131.medium.com/batch-vs-online-prediction-e82a3eade253?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e82a3eade253</guid>
            <category><![CDATA[ml-model-deployment]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Mon, 11 Nov 2024 13:19:54 GMT</pubDate>
            <atom:updated>2024-11-11T13:19:54.448Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will discuss one of the key aspects of the model deployment phase i.e. determining the prediction strategy— Online or Batch. While this depends on factors such as latency requirements, prediction frequency, error tolerance, type of use case and end user requirements, we will explore the key differences between both and outline when each is most appropriate.</p><p>This blog is in continuation of my previous blog <a href="https://poojamahajan5131.medium.com/scratching-the-surface-of-ml-deployment-3948f7532237">Scratching deployment surface</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UiuCa7uUnESN7J4GVj8TtQ.png" /><figcaption>AI Generated Image from Pixlr.com</figcaption></figure><h3><strong>Batch Prediction</strong></h3><p>In Batch prediction, predictions are computed for multiple data samples all at once in a scheduled manner, then stored in a database and retrieved as per request. While computation, prediction requests can be sent directly to the model resource without deploying it on an endpoint. Also known as asynchronous prediction, as predictions are generated independently of the requests and precomputed in advance.</p><p><strong>Pros</strong></p><ul><li>Primarily optimized on throughput (i.e. processing large volumes of data in single run).</li><li>Generates multiple predictions at once and can make use of distributed computing (e.g. Spark)</li><li>Can be scheduled at off-peak hours for efficient resource usage.</li></ul><p><strong>Cons</strong></p><ul><li>Generates predictions even for those users or queries that might not be requested ever, resulting in unnecessary compute and storage usage.</li></ul><p><strong>When to use Batch Prediction?</strong></p><ul><li>Ideal scenario to use when immediate results are not required as in use cases like recommender system, customer segmentation, etc. where predictions are needed at some interval (daily, weekly, monthly).</li><li>Batch prediction is useful when input queries are known in advance, allowing predictions to be generated all at once. For example, predicting which customers will buy a product can be run for your entire customer base. However, in cases like language translation, chatbots, or virtual assistants, where queries are unpredictable, batch prediction is not feasible.</li></ul><p><strong>Companies using Batch Prediction- </strong>Netflix uses batch prediction for recommendations, Doordash uses batch prediction for recommending restaurants.</p><h3><strong>Online Prediction</strong></h3><p>Online Prediction also known on-demand predictions where predictions are generated as and when the request comes. Prediction is performed on a single observation of data rather than a batch. It is also called synchronous prediction as predictions are generated in sync with requests. Plus, it can be done at any time of the day in real -time basis rather than scheduled as in batch prediction.</p><p><strong>Pros</strong></p><ul><li>Optimized for low latency(i.e. quickly processes and return predictions almost instantly after receiving input.)</li><li>Predicts only for the required requests unlike batch prediction where predictions are made for all users who might not even require the predictions.</li></ul><p><strong>Cons</strong></p><ul><li>Online prediction requires significant computational resources to handle real-time requests like dynamic scaling leading to higher operational costs.</li><li>It requires constant monitoring and maintenance to ensure optimal performance and quick issue resolution.</li></ul><p><strong>When to use Online Prediction? — </strong>When predictions are needed immediately as in real-time use cases like fraud detection, machine failure detection, self driving vehicles, etc. where there is lower error tolerance. Online predictions are more suited to models with fast inference times i.e. less complex in nature or if they are complex they need to be optimized.</p><p><strong>Companies using Online Prediction — </strong>You tube uses online prediction for video recommendation based on viewing history, Amazon uses online prediction to recommend products to users in real-time.</p><h4><strong>How about combining both ?</strong></h4><p>While both online and batch prediction has advantages and disadvantages, combining both the types of prediction is practical in many scenarios. For e.g. in Ad Targeting and Personalization use cases, online prediction can be used for predicting which ad to show to a user based on their most recent behavior considering searches, clicks, etc. and batch prediction can be used to periodically update user profiles and segmentation by analyzing their historic browsing habits and purchase history.</p><p>So that’s all folks!</p><p>We have made to the end of this article. I hope this article helped you grasp the key differences between the two prediction strategies and will be useful in guiding your decisions for future use cases.</p><p><strong>References </strong>:-</p><ul><li><a href="https://www.oreilly.com/library/view/designing-machine-learning/9781098107956/">https://www.oreilly.com/library/view/designing-machine-learning/9781098107956/</a></li><li><a href="https://cris.brighton.ac.uk/ws/portalfiles/portal/453691/offline_vs_online1.pdf">https://cris.brighton.ac.uk/ws/portalfiles/portal/453691/offline_vs_online1.pdf</a></li><li><a href="https://cloud.google.com/vertex-ai/docs/predictions/get-predictions">https://cloud.google.com/vertex-ai/docs/predictions/get-predictions</a></li><li><a href="https://www.greenbook.org/market-research-firms/predictive-markets">https://www.greenbook.org/market-research-firms/predictive-markets</a></li><li><a href="https://docs.aws.amazon.com/machine-learning/latest/dg/about-batch-predictions.html">https://docs.aws.amazon.com/machine-learning/latest/dg/about-batch-predictions.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e82a3eade253" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scratching the surface of ML Deployment]]></title>
            <link>https://medium.com/swlh/scratching-the-surface-of-ml-deployment-3948f7532237?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3948f7532237</guid>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Sat, 14 Aug 2021 13:19:23 GMT</pubDate>
            <atom:updated>2021-08-14T13:19:23.893Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article we will be discussing some of the deployment considerations and patterns. Deployment being the last step of machine learning cycle has gained lot of traction recently, so let’s try to get hang of some of the concepts.</p><p>We will be discussing some of the common deployment patterns i.e. how to start consuming your new algorithm in production. Apart from this, we will touch some of the concepts related to changing data distributions that affect model predictions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*UCn8FxS3UAufYUYUVJJ7wA.jpeg" /><figcaption>Image Courtesy — <a href="https://unsplash.com/s/photos/data-prediction">Unsplash</a></figcaption></figure><h3>Deployment Patterns</h3><p>By deployment pattern we mean how to start consuming your new algorithm in production. It can be a replacement of an old algorithm, or replacement of old methods(manual/conventional),etc.</p><p><strong>A) Shadow deployment :</strong></p><ul><li>The aim of shadow deployment is to deploy and evaluate new algorithm’s performance but not to use it for real-time predictions.</li><li>Currently used method is utilized for actual predictions and performance comparison is done (e.g. comparison with another deployed model or conventional methods using human predictions, etc.).</li><li>It’s a decent way to judge a new model and risk free.</li><li>No impact on current production and new algorithm can be tested with production load.</li></ul><p><strong>B) Canary</strong> <strong>deployment:</strong></p><ul><li>The<strong> </strong>main idea of canary deployment is to roll out predictions for a small proportion of traffic using new algorithm and evaluate performance.</li><li>It helps to monitor and spot problems early, if any.</li><li>It can be ramped up gradually (i.e. incremental increase in the traffic proportion for newer algorithm).</li></ul><p><strong>C) Blue green deployment:</strong></p><ul><li>Here blue signifies current prediction service and green as new prediction service.</li><li>We can set up new prediction service separately without stopping current one and can shift to the new prediction service. If it doesn’t go well, we can point to blue again.</li><li>Easier to rollback and no downtime while cost and operational overheads will be there.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*Z49PB1CNKx8YkwyO2gCjFw.png" /><figcaption>Image — by Author</figcaption></figure><h3>Deployment considerations</h3><p>Once the model is deployed it is important to understand changes in statistical distribution of the data being used. There are two aspects that should be considered.</p><p><strong>A) Data drift</strong></p><ul><li>It arises when there are changes in distribution of underlying variables which results in degrading model predictions, or in simple terms when distribution of independent variables change.</li><li>This drift can arise from changes in underlying business logics, data quality challenges, etc. E.g. in case of image recognition data drift can arise due to setup changes like lighting, device, etc. , or in speech recognition systems due to upgradation of microphone.</li></ul><p><strong>B) Concept drift</strong></p><ul><li>It arises when relation between predictor and target variables has changed resulting in model prediction degradation, or simply put when relation of x -&gt; y changes (x being independent variable and y being dependent variable).</li><li>A common example of concept drift can be online shopping patterns of customers before and after COVID as there has been lot of changes in consumer buying behavior. Another example can be a price prediction model where the target variable relation(price) has changed due to inflation.</li></ul><p>So that’s it, we have made to the end of this article. It’s just the tip of the deployment iceberg, there is a lot underneath!</p><h4>References</h4><ul><li><a href="https://cloud.google.com/architecture/application-deployment-and-testing-strategies">https://cloud.google.com/architecture/application-deployment-and-testing-strategies</a></li><li><a href="https://docs.microsoft.com/en-us/azure/machine-learning/how-to-monitor-datasets?tabs=python">https://docs.microsoft.com/en-us/azure/machine-learning/how-to-monitor-datasets?tabs=python</a></li><li><a href="https://www.coursera.org/learn/introduction-to-machine-learning-in-production/lecture/DugTF/deployment-patterns">https://www.coursera.org/learn/introduction-to-machine-learning-in-production/lecture/DugTF/deployment-patterns</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3948f7532237" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/scratching-the-surface-of-ml-deployment-3948f7532237">Scratching the surface of ML Deployment</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Avoid for loops with Vectorization]]></title>
            <link>https://poojamahajan5131.medium.com/avoid-for-loops-with-vectorization-ce43f2a172f0?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce43f2a172f0</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Fri, 30 Jul 2021 13:25:00 GMT</pubDate>
            <atom:updated>2021-07-30T13:27:45.832Z</atom:updated>
            <content:encoded><![CDATA[<h4>Vectorization in Python</h4><p>In this article, we will discuss about how to speed up your code by using NumPy’s feature of Vectorization.</p><p>Python’s NumPy arrays enable us to express batch operations on data without writing any explicit for loops, referred as Vectorization. This is one of the key features of optimization using NumPy apart from <a href="https://poojamahajan5131.medium.com/broadcasting-in-python-b98ea517c51d"><strong>broadcasting</strong>.</a></p><p>Let’s dig deep into vectorization!</p><blockquote>Vectorized array operations execute faster than their python equivalents and thus have a high impact in numerical computations. The reason why NumPy is efficient because it’s operations are mapped to highly optimized C codes.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GO5XXRB5X4CUX04gutlTkA.jpeg" /><figcaption>Image — Unsplash.com</figcaption></figure><p>In deep learning practice, we often train on relatively large data sets, so it’s important that our code should be optimized to execute fast. In these scenarios vectorization is quite useful, it enables us to take much better advantage of parallelism and to do our computations much faster on CPUs and GPUs as well.</p><h4>Examples to showcase impact of Vectorization</h4><p><strong>Example 1 — </strong>Dot product operation</p><p>Approach 1 — Using for Loop</p><pre><strong># Import libraries<br>import numpy as np<br>import time<br>import math</strong></pre><pre><strong>#1. Using for loop<br>n = 1000000<br>arr1 = np.random.rand(n)<br>arr2 = np.random.rand(n)</strong></pre><pre><strong># dot product using for loop<br>start_time_1 = time.time()<br>output=0<br>for i in range(n):<br>    output += arr1[i]*arr2[i]</strong></pre><pre><strong>print(&quot;time taken using for loop approach &quot;,\<br>        time.time()- start_time_1,&#39;ms&#39;)<br>print(&#39;Output&#39;,output)</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*xL8Q55heH6HXZWl3IEaa9A.png" /></figure><p>Approach 2 — Using NumPy</p><pre><strong>## 2. using vectorization<br>start_time_2 = time.time()<br>output1 = np.dot(arr1,arr2)<br>print(&quot;time taken using vectorization&quot;,\<br>      time.time() - start_time_2,&#39;ms&#39;)<br>print(&#39;Output&#39;,output1)</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*fPJxNV7BkVI7Uxwhvi9NFQ.png" /></figure><p>In the above example, dot product operation has been performed and it is clearly visible that for the same operation ‘for’ loop takes 0.6ms while vectorization takes merely 0.003ms.</p><p><strong>Example 2 :</strong> Exponent operation</p><pre><strong>n = 100000000<br>arr1 = np.random.rand(n)<br>output = np.zeros((n,1))</strong></pre><pre><strong>## Approach 1<br>print(&quot;Using for loop&quot;)<br>start_time = time.time()<br>for i in range(n):<br>    output[i] = math.exp(arr1[i])</strong></pre><pre><strong>print(&quot;time taken &quot;,time.time()- start_time,&#39;ms&#39;)<br>print(&#39;Output - first 3 values&#39;,output[:3])</strong></pre><pre><strong>## Approach 2<br>print(&quot;Numpy implementation&quot;)<br>start_time = time.time()<br>output1 = np.exp(arr1)<br>print(&quot;time taken &quot;,time.time()- start_time,&#39;ms&#39;)<br>print(&#39;Output - first 3 values&#39;,output1[:3])</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*nWPwQ2RZztr2HRo3yPVn_A.png" /><figcaption>Time taken for ‘for’ loop is way higher than vectorization</figcaption></figure><p>From the above example it may feel like 70 ms is way small even using ‘for’ loop but vectorization showcases its core strength while working with big datasets and creates magic by executing computations at a much faster speed!</p><p><strong>References:</strong></p><ul><li><a href="https://www.oreilly.com/library/view/applied-text-analysis/9781491963036/ch04.html">https://www.oreilly.com/library/view/applied-text-analysis/9781491963036/ch04.html</a></li><li><a href="https://www.coursera.org/learn/neural-networks-deep-learning/lecture/NYnog/vectorization">https://www.coursera.org/learn/neural-networks-deep-learning/lecture/NYnog/vectorization</a></li><li><a href="https://www.coursera.org/learn/neural-networks-deep-learning/lecture/ZPlX9/more-vectorization-examples">https://www.coursera.org/learn/neural-networks-deep-learning/lecture/ZPlX9/more-vectorization-examples</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce43f2a172f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Avoidable Bias!]]></title>
            <link>https://poojamahajan5131.medium.com/understanding-avoidable-bias-60b639c1e59e?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/60b639c1e59e</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[bias]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Tue, 18 May 2021 11:52:26 GMT</pubDate>
            <atom:updated>2021-05-18T13:52:30.998Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will discuss comparing our model accuracy with human-level performance and discuss the concepts like avoidable bias and how to tackle it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*XwJQEoLYU78i4EWRPvtm6Q.png" /><figcaption>Image <a href="https://scott.ai/2019-08-06-memeified-ng/">Source</a></figcaption></figure><h4>What is avoidable bias?</h4><p>The difference between human error (approximation of Bayes error) and the training error is termed avoidable bias.</p><p>The perfect level of accuracy may not be always 100% and Bayes optimal error is the very best theoretical function that can never be surpassed(best possible error).</p><h4>Comparison with human-level performance</h4><p>As long as our model is doing worse than humans we can use some tactics for improving our model. Although knowing about bias and variance helps and it turns out that knowing how well humans can do on a task can help us understand better how much we should try to reduce bias!</p><p><strong>Scenario 1</strong>- You have built a cat classifier and you got error percentages for training and dev sets as 8% and 10% respectively. Plus let’s say human error is 0.5% for this dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*84kMwltG3T77EfgmBBK3kg.png" /></figure><p>In this example:-</p><ul><li>Avoidable Bias is 7.5% and variance is 2%.</li><li>The next steps should focus on reducing the avoidable bias.</li></ul><p><strong>How to reduce Avoidable bias?</strong></p><ul><li>Train a bigger neural model.</li><li>Train longer or with better optimization algorithms.</li><li>Finding better neural network architecture.</li></ul><p><strong>Scenario 2 -</strong>You have built a cat classifier and you got error percentages for training and dev sets as 8% and 10% respectively and human error for this dataset is 7.2% (images were of poor quality s.that it is difficult for human eyes also to classify a cat in the image).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*CRf3LUNdt-vQ3G7fJi50Xg.png" /></figure><p>In this example:-</p><ul><li>Avoidable Bias is 0.8% and variance is 2%.</li><li>The next steps should focus on reducing the variance.</li></ul><p><strong>How to reduce Variance?</strong></p><ul><li>Get more training data.</li><li>Regularisation (Dropout, L2 regularisation, Batch Normalisation, etc.)</li><li>Data Augmentation</li><li>Early stopping</li><li>Finding better neural network architecture.</li></ul><p>If you want to read more about these pointers mentioned above refer to my previous <a href="https://medium.com/analytics-vidhya/understanding-regularization-with-pytorch-26a838d94058">post</a>.</p><p>So that’s it! You have made it to the end of the post. For more information about these concepts check out the references below!</p><h4>References:-</h4><ul><li><a href="https://www.coursera.org/learn/machine-learning-projects/lecture/LG12R/avoidable-bias">https://www.coursera.org/learn/machine-learning-projects/lecture/LG12R/avoidable-bias</a></li><li><a href="https://www.coursera.org/learn/machine-learning-projects/lecture/FWkpo/why-human-level-performance">https://www.coursera.org/learn/machine-learning-projects/lecture/FWkpo/why-human-level-performance</a></li><li><a href="https://www.coursera.org/learn/machine-learning-projects/lecture/4IPD6/improving-your-model-performance">https://www.coursera.org/learn/machine-learning-projects/lecture/4IPD6/improving-your-model-performance</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60b639c1e59e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AI in Healthcare -Closer Look!]]></title>
            <link>https://medium.com/codex/ai-in-healthcare-closer-look-86dadb1fbfc2?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/86dadb1fbfc2</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[healthcare]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[challenge]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Wed, 07 Apr 2021 15:58:35 GMT</pubDate>
            <atom:updated>2021-04-12T08:31:53.748Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d326kDW7mNVDFrQt" /><figcaption>Photo by <a href="https://unsplash.com/@hikendal?utm_source=medium&amp;utm_medium=referral">Kendal</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I will be taking you through some of the practical considerations and challenges of using AI in Medical diagnosis. The criticality involved in this domain makes it important to pay heed to these challenges apart from the core AI/ML practices.</p><h4><strong>Dataset considerations</strong></h4><ol><li><strong>Imbalanced dataset </strong>—The presence of a higher number of data samples <strong>without disease</strong> rather than <strong>with disease</strong> results in imbalanced datasets and thus poses issues in training algorithms for medical analysis.</li></ol><p><strong>Solution:</strong></p><p>a) Resampling data (Oversampling, Undersampling, etc.)</p><p>b) Modifying loss function i.e. using weighted loss to incorporate the effect of imbalanced classes.</p><p>2.<strong> Small training dataset</strong> — Absence of labeled dataset or small training data availability especially for Image analysis tasks like thoracic disease detection using Chest-Xray, Brain Tumor detection using MRI Scans, etc.</p><p><strong>Solution</strong>:</p><p>a) Transfer Learning- Transfer learning implies adapting a network trained for one problem to a different problem. With transfer learning, we can build good classifiers with a few hundred images. Find more info on transfer learning <a href="https://towardsdev.com/transfer-learning-using-pytorch-cbf61b91486e">here</a>.</p><p>b) Data Augmentation- We can use different transformations on the data to increase the breadth of training data. The only thing we need to be careful in the case of medical image data transformations is to choose transformations keeping in mind that post-transformation Y-label(Ground truth) remains true.</p><p>For eg. If on a chest X-ray, a horizontal flip is used that will cause the heart to appear on a different side implies a separate kind of medical problem. Find more info on data augmentation <a href="https://medium.com/analytics-vidhya/transforming-data-in-pytorch-741fab9e008c">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*b90j7CNK5Z-jS4_JOZWlVg.png" /><figcaption>Image <a href="https://singularityhub.com/2019/02/20/the-pediatric-ai-that-outperformed-junior-doctors/">Source</a></figcaption></figure><h4><strong>Model Testing considerations</strong></h4><ul><li><strong>Patient overlap</strong>- While creating training, validation and test set it should be made sure that there is no patient overlap among these sets as this issue can result in over-optimistic test results due to the same patients present in training and test sets. <em>Splits should happen based on patients to resolve this issue.</em></li><li><strong>Deciding ground truth</strong>- To decide on ground truth for a sample is a different challenge that may arise due to interobserver disagreement where one practitioner&#39;s opinion may differ from another and is quite common in the medicine domain. <em>Consensus voting where a group of human experts is considered to determine the ground truth can be a way to tackle this issue.</em></li></ul><h4>Practical Considerations</h4><ul><li><strong>Different populations’ characteristics</strong>— Achieving reliable generalization is a challenge for AI models using medical data. For e.g. Chest X-ray data for India may look quite different from the US so a model built on US patient’s data may not be very effective for other geographies.</li><li><strong>External validation </strong>— While the AI models are built on historical data but how it works on real-world data marks whether the AI model can be directly used or it needs to be fine-tuned as per new data. However, to understand the utility of AI models in the real world, these need to be applied to real-world data(prospective data).</li></ul><p>So, we have reached the end of this post and learned about dataset challenges, model testing, and practical implementation challenges that can be examined for healthcare use cases.</p><p><strong>References</strong> :</p><ul><li><a href="https://www.coursera.org/learn/ai-for-medical-diagnosis/ungradedLab/gjDcc/counting-labels-and-weighted-loss-function">https://www.coursera.org/learn/ai-for-medical-diagnosis/ungradedLab/gjDcc/counting-labels-and-weighted-loss-function</a></li><li><a href="https://www.coursera.org/learn/ai-for-medical-diagnosis/lecture/VNkO2/multi-task-loss-dataset-size-and-cnn-architectures">https://www.coursera.org/learn/ai-for-medical-diagnosis/lecture/VNkO2/multi-task-loss-dataset-size-and-cnn-architectures</a></li><li><a href="https://www.coursera.org/learn/ai-for-medical-diagnosis/lecture/RVBZK/measuring-patient-outcomes">https://www.coursera.org/learn/ai-for-medical-diagnosis/lecture/RVBZK/measuring-patient-outcomes</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=86dadb1fbfc2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codex/ai-in-healthcare-closer-look-86dadb1fbfc2">AI in Healthcare -Closer Look!</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[Transfer Learning using PyTorch]]></title>
            <link>https://towardsdev.com/transfer-learning-using-pytorch-cbf61b91486e?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbf61b91486e</guid>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[transfer-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[image-classification]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 16:51:09 GMT</pubDate>
            <atom:updated>2021-03-18T07:16:00.853Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CRSR0_f_1F1qvyZnRgbjaA.png" /><figcaption>Image <a href="https://line.17qq.com/articles/chcponcov.html">Source</a></figcaption></figure><p>Transfer learning implies adapting a network trained for one problem to a different problem. It is common to pre-train a CNN on a very large dataset (e.g. ImageNet, which contains 1.2 million images with 1000 categories), and then use that either as an initialization or a fixed feature extractor for the task of interest.</p><h4>Why use Transfer Learning?</h4><ul><li>Using large networks that were trained with vast datasets for our new tasks reduces time and computation requirements.</li><li>It is relatively rare to have a dataset of sufficient size. With transfer learning, we can build good classifiers with a few hundred images.</li></ul><h4>Types of Transfer Learning:</h4><ul><li><strong>Finetuning — </strong>Starting with a pre-trained model and updating all of the model’s parameters for the new task and thus retraining the whole model.</li><li><strong>Feature Extraction — </strong>Starting with a pre-trained model and only updating the final layer weights from which predictions will be derived. Pre-trained CNN is used as a fixed feature-extractor, hence the name.</li></ul><h4>Transfer learning using the pre-trained model</h4><p>PyTorch’s torchvision.models have been pre-trained on the 1000-class Imagenet dataset. In the example below, I have implemented feature extraction transfer learning where we will load the pre-trained model and update the final layer. I am using the CIFAR-10 dataset and Resnet18 pre-trained model.</p><ul><li>All pre-trained models expect input images normalized in the same way, i.e. mini-batches of 3-channel RGB images of shape (3 x H x W), where H and W are expected to be at least 224.</li><li>The images have to be loaded into a range of [0, 1] and then normalized using mean = [0.485, 0.456, 0.406] and std = [0.229, 0.224, 0.225]</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_kzkmAqijoPvg6zs1mQh3Q.png" /><figcaption>Code snippet showcasing Image resize to (224,224) and Normalisation using suggested values</figcaption></figure><ul><li>Instancing a pre-trained model will download its weights to a cache directory. After that, we are freezing model weights by setting requires_grad to False.</li></ul><p>When we print the model, we see that the last layer is a fully connected layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_tSlCIhwCRpoRTH1G15PA.png" /></figure><p>So we are reinitializing model.fc such that it has 10 output features at the end(corresponding to our task).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*59s7aBu_01IN4jqoA4nJOg.png" /></figure><ul><li>A glimpse of model summary (last few layers) — We can see the last layer has 10 output features as updated in the previous step.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgslmUYebc9Y7smYPRF5Zg.png" /></figure><ul><li>Model Training — In few epochs only, you can see the train and test accuracies have reached 80%.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PqEWB_GNdt3jwKtWaWGNtA.png" /></figure><p>You can find the source code for the example shown <a href="https://github.com/poojamahajan0712/medium_blog/blob/master/TransferLearning/PretrainedModel_example.ipynb">here</a>.</p><p>You can find more about some common rules of thumb for when and how to finetune <a href="https://cs231n.github.io/transfer-learning/">here</a>.</p><h4>References:</h4><ul><li><a href="https://pytorch.org/vision/stable/models.html">https://pytorch.org/vision/stable/models.html</a></li><li><a href="https://pytorch.org/tutorials/beginner/finetuning_torchvision_models_tutorial.html">https://pytorch.org/tutorials/beginner/finetuning_torchvision_models_tutorial.html</a></li><li><a href="https://cs231n.github.io/transfer-learning/">https://cs231n.github.io/transfer-learning/</a></li><li><a href="https://learning.oreilly.com/library/view/programming-pytorch-for/9781492045342/ch04.html#transfer-learning-and-other-tricks">https://learning.oreilly.com/library/view/programming-pytorch-for/9781492045342/ch04.html#transfer-learning-and-other-tricks</a></li><li><a href="https://www.youtube.com/watch?v=yofjFQddwHE">https://www.youtube.com/watch?v=yofjFQddwHE</a></li><li><a href="https://www.youtube.com/watch?v=mPFq5KMxKVw">https://www.youtube.com/watch?v=mPFq5KMxKVw</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbf61b91486e" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/transfer-learning-using-pytorch-cbf61b91486e">Transfer Learning using PyTorch</a> was originally published in <a href="https://towardsdev.com">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Broadcasting in Python]]></title>
            <link>https://poojamahajan5131.medium.com/broadcasting-in-python-b98ea517c51d?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b98ea517c51d</guid>
            <category><![CDATA[broadcasting]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[vectorization]]></category>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[neural-networks]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Wed, 18 Nov 2020 13:25:51 GMT</pubDate>
            <atom:updated>2020-11-18T13:25:51.944Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, we will discuss ‘Broadcasting’ using NumPy. It is also used while implementing neural networks as these operations are memory and computationally efficient.</p><p>So let’s understand what Broadcasting means followed by a few examples!</p><p>Broadcasting describes the way numpy treats arrays with different shapes for arithmetic operations. The smaller array is broadcasted across the larger array so that they have compatible shapes. It provides a way to vectorize array operations thus leading to efficient implementations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*R1JhHKFkC9wlADEKBIzOVQ.png" /><figcaption>Broadcasting Examples- <a href="https://jakevdp.github.io/PythonDataScienceHandbook/02.05-computation-on-arrays-broadcasting.html">Image Source</a></figcaption></figure><p>The light bordered boxes represent the broadcasted values, this extra memory is not actually allocated during the operation, but can be useful conceptually to imagine that it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*xB5Zz8g43anwyt91NxxBeQ.png" /><figcaption>Normal arithmetic operation and broadcasting comparison</figcaption></figure><p>In the above example for both cases output is same while the second case uses the concept of broadcasting and is more efficient. NumPy is elegant enough to use the original scalar value without actually making copies making broadcasting operations more efficient.</p><h3>More Broadcasting examples</h3><ul><li><strong>Example 1- </strong>Arithmetic operation between two arrays where the first array has shape (m,n) and the second array with shape (m,1).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*747-I6CP0kD41bEI2h8qzg.png" /></figure><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HLRRmaC-KIT0PmNWnL-vEg.png" /><figcaption>Final Output shape is (2,3) corresponding to ‘a’</figcaption></figure><ul><li><strong>Example 2- </strong>Arithmetic operation between two arrays where the first array has shape (m,n) and the second array with shape (1,n).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ISCUlWJZcmXtBM9dNQVBXQ.png" /></figure><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XANS8p_8m1S0d21mu-XvAw.png" /><figcaption>Final Output shape is (2,3) corresponding to ‘a’</figcaption></figure><ul><li><strong>Example 3- </strong>Arithmetic operation between an array and scalar value where the array has shape (1,n)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UP64CBcpVDCd1nND_Bj-4Q.png" /></figure><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-7aOddxfrS6Z10GD-1Hjg.png" /><figcaption>Final Output shape is (1,4) corresponding to ‘a’</figcaption></figure><ul><li><strong>Example 4- </strong>Arithmetic operation between an array and scalar value where the array has shape<strong> </strong>(m,1).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_aZykMSdYaWTfHwPjyT45A.png" /></figure><p><strong>Output:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QOsG82OW6yIZD9CinEsbKA.png" /><figcaption>Final Output shape is (4,1) corresponding to ‘a’</figcaption></figure><p>In the examples above I have used ‘+’ arithmetic operation to demonstrate Broadcasting, it can be replicated for other arithmetic operators too in a similar fashion.</p><p>So that&#39;s it! You have made it to the end of this quick demo of Broadcasting in Python.</p><p><strong>References:</strong></p><ul><li><a href="https://numpy.org/doc/stable/user/basics.broadcasting.html">https://numpy.org/doc/stable/user/basics.broadcasting.html</a></li><li><a href="https://jakevdp.github.io/PythonDataScienceHandbook/02.05-computation-on-arrays-broadcasting.html">https://jakevdp.github.io/PythonDataScienceHandbook/02.05-computation-on-arrays-broadcasting.html</a></li><li><a href="https://www.coursera.org/learn/neural-networks-deep-learning/lecture/uBuTv/broadcasting-in-python">https://www.coursera.org/learn/neural-networks-deep-learning/lecture/uBuTv/broadcasting-in-python</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b98ea517c51d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Filters with Convolutions]]></title>
            <link>https://poojamahajan5131.medium.com/image-filters-with-convolutions-9104bba1ce12?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9104bba1ce12</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[scipy]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Thu, 12 Nov 2020 12:25:56 GMT</pubDate>
            <atom:updated>2020-11-12T17:00:49.299Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong>Using </strong>Python’s <strong>scipy library for implementation</strong></h4><p>In this post, I will discuss about Convolutions and how they act as image filters by implementing convolution operation using a few edge detection kernels.</p><p>So let’s start!</p><h4>What are Convolutions?</h4><p>Convolutions are mathematical operation on two functions that produces a third function that expresses how one is modified by the other.</p><p>To give an example, the first function can be the image and the second function is a matrix sliding over the image(kernel) that results in transforming the input image. Kernel works by multiplying the patch of the image corresponding to the kernel’s size and summing up the result obtained and then sliding over the image to perform the same process again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*L4KMcxLyaio3ognG-Xwj2w.png" /><figcaption>Image <a href="http://d2l.ai/chapter_convolutional-neural-networks/conv-layer.html">Source</a></figcaption></figure><p>Thus, Convolution operation can help in extracting features from images with the help of kernels. For more details on Convolutions and Kernels, please refer to my previous blog <a href="https://poojamahajan5131.medium.com/getting-started-with-deep-learning-359fa9801b86">here</a>.</p><h4>Image Filters with Convolutions</h4><p>In order to demonstrate how convolution operation can be used as Image Filters, I have used <strong>signal.convolve2d </strong>function from<strong> </strong>the<strong> scipy </strong>library of Python that outputs convolution result for two 2D arrays<strong>.</strong></p><ul><li><strong>Importing required libraries</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*mE8kjVVi5joL3DB1VH1uVA.png" /></figure><ul><li><strong>Loading and displaying images</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*uCp7JA4M7QyWMkkT9NhtfQ.png" /></figure><ul><li><strong>Defining a function to detect features from the image using specified kernel</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yDsMFF3cZPZFk5exrZ0fyw.png" /></figure><ul><li><strong>Detecting horizontal edges</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*o0VZTE7QM_Llj-04mhvGHA.png" /><figcaption><strong>Transformed image after convolution operation using a horizontal edge detector kernel</strong></figcaption></figure><ul><li><strong>Detecting vertical edges</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*VBhzhtqcJ7CbU7DbilSobQ.png" /><figcaption><strong>Transformed image after convolution operation using a vertical edge detector kernel</strong></figcaption></figure><ul><li><strong>Detecting diagonal edges</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*WAygXABWFfWEyRwdxO0J-Q.png" /><figcaption><strong>Transformed image after convolution operation using a diagonal detector kernel</strong></figcaption></figure><p>This was a quick demo to show when a kernel convolves over an image it can act as a filter to extract a particular feature from it.</p><p>You can find the corresponding codes <a href="https://github.com/poojamahajan0712/medium_blog/blob/master/Convolutions/ConvolutionsAsImageFilters.ipynb">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9104bba1ce12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fully Connected vs Convolutional Neural Networks]]></title>
            <link>https://medium.com/swlh/fully-connected-vs-convolutional-neural-networks-813ca7bc6ee5?source=rss-ffddfb0b773f------2</link>
            <guid isPermaLink="false">https://medium.com/p/813ca7bc6ee5</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Pooja Mahajan]]></dc:creator>
            <pubDate>Fri, 23 Oct 2020 05:45:12 GMT</pubDate>
            <atom:updated>2020-10-23T14:09:56.518Z</atom:updated>
            <content:encoded><![CDATA[<h4>Implementation using Keras</h4><p>In this post, we will cover the differences between a Fully connected neural network and a Convolutional neural network. We will focus on understanding the differences in terms of the model architecture and results obtained on the MNIST dataset.</p><h4>Fully connected neural network</h4><ul><li>A fully<strong> </strong>connected neural network consists of a series of fully<strong> </strong>connected layers that connect every neuron in one layer to every neuron in the other layer.</li><li>The major advantage of fully connected networks is that they are “structure agnostic” i.e. there are no special assumptions needed to be made about the input.</li><li>While being structure agnostic makes fully connected networks very broadly applicable, such networks do tend to have weaker performance than special-purpose networks tuned to the structure of a problem space.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*VHOUViL8dHGfvxCsswPv-Q.png" /><figcaption>Multilayer Deep Fully Connected Network, <a href="https://www.oreilly.com/library/view/tensorflow-for-deep/9781491980446/ch04.html">Image Source</a></figcaption></figure><h4>Convolutional Neural Network</h4><ul><li>CNN architectures make the explicit assumption that the <strong>inputs are images</strong>, which allows encoding certain properties into the model architecture.</li><li>A simple CNN is a sequence of layers, and every layer of a CNN transforms one volume of activations to another through a differentiable function. Three main types of layers are used to build CNN architecture: Convolutional Layer, Pooling Layer, and Fully-Connected Layer.</li></ul><p>To know more about the basic fundamentals related to CNN, check out my earlier blogs on <a href="https://medium.com/@poojamahajan5131/getting-started-with-deep-learning-359fa9801b86">Convolutions</a> and <a href="https://medium.com/@poojamahajan5131/max-pooling-210fc94c4f11">Pooling</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ryCcZ8Omeo3dD1QNmMHoqA.png" /><figcaption>Simple Convolutional architecture, <a href="https://learning.oreilly.com/library/view/tensorflow-for-deep/9781491980446/ch06.html">Image Source</a></figcaption></figure><h4><strong>Dataset Used</strong></h4><ul><li>MNIST (Modified National Institute of Standards and Technology database) dataset of 60,000 28x28 grayscale images of the 10 digits, along with a test set of 10,000 images.</li><li>It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image.</li><li>It is a good database for people who want to try learning techniques and pattern recognition methods on real-world data while spending minimal efforts on preprocessing and formatting.</li></ul><h4><strong>Model Implementation</strong></h4><p><strong>A) Using Fully Connected Neural Network Architecture</strong></p><ul><li><strong>Model Architecture</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hU88rWPzZMhWD-evsTpcJw.png" /></figure><p>For the fully-connected architecture, I have used a total of three hidden layers with ‘relu’ activation function apart from input and output layers.</p><ul><li><strong>Model Summary</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UEakCjv3HFCaat0ShkKdow.png" /></figure><p>The total number of trainable <strong>parameters</strong> is around <strong>0.3 million</strong>. In a fully-connected<strong> </strong>layer, for n inputs and m outputs, the number of weights is n*m. Additionally, you have a bias for each output node, so total (n+1)*m parameters.</p><ul><li><strong>Model Accuracy</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*CC9Dh1sRLwb5sY3m1N3TGA.png" /></figure><p>On training the fully connected model for five epochs<strong> </strong>with<strong> </strong>a<strong> </strong>batch size of 128, and validation split value set to 0.3 we got <strong>training accuracy of 98.6%</strong> and <strong>validation accuracy of 96.07%. </strong>Moreover, after 2nd epoch, we can visualize how train and validation accuracy tends to move wide apart.</p><ul><li><strong>Accuracy on Test data</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fPmaHaJ49fNSdmBJ-iUkMQ.png" /></figure><p>On test data with 10,000 images accuracy for the fully connected neural network is <strong>96%</strong>.</p><p><strong>B) Using Convolutional Neural Network Architecture</strong></p><ul><li><strong>Model Architecture</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZ-r9UMYgSNXoa2SF57mQA.png" /></figure><p>For Convolutional Neural network architecture, we added 3 convolutional layers with activation as ‘relu’ and a max pool layer after the first convolutional layer.</p><ul><li><strong>Model Summary</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VFGvduBP53sbTVKKLDYLDg.png" /></figure><p>With CNN the differences you can notice in summary are Output shape and number of parameters. As compared to the fully connected neural network model the total number of parameters is too less i.e. 0.1 million.</p><ul><li><strong>Model Accuracy</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*KwBi3ET3rEpsJYr5KxbQkA.png" /></figure><p>On training, CNN for five epochs for a batch size of 128, and validation split value set to 0.3 we got <strong>training accuracy </strong>of<strong> 99.19%</strong> and <strong>validation accuracy </strong>of<strong> 99.63%. </strong>Moreover, unlike the fully connected model, we can visualize train and validation accuracy do not tend to move as wide apart.</p><ul><li><strong>Accuracy on the Test dataset</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MUbDv6azjKCxtVbLXYCC2Q.png" /></figure><p>On test data with 10,000 images, accuracy for the fully connected neural network is <strong>98.9</strong>%.</p><p><strong>Final Thoughts</strong></p><p>Although fully connected networks make no assumptions about the input they tend to perform less and aren’t good for feature extraction. Plus they have a higher number of weights to train that results in high training time while on the other hand CNNs are trained to identify and extract the best features from the images for the problem at hand with relatively fewer parameters to train.</p><p>Please find the relevant codes used in this blog <a href="https://github.com/poojamahajan0712/medium_blog/blob/master/Fully_connected_NNvsCNN/MNIST_Keras_Fully_Connected_vs_Convolutional.ipynb">here</a>. On similar lines, you can find the implementation of CNNs on the FMNIST dataset using PyTorch <a href="https://medium.com/analytics-vidhya/my-first-deep-learning-model-using-pytorch-406caa278df6">here</a>.</p><h4><strong>References </strong>:</h4><ul><li><a href="https://www.oreilly.com/library/view/tensorflow-for-deep/9781491980446/ch04.html">https://www.oreilly.com/library/view/tensorflow-for-deep/9781491980446/ch04.html</a></li><li><a href="https://cs231n.github.io/convolutional-networks/#overview">https://cs231n.github.io/convolutional-networks/#overview</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=813ca7bc6ee5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/fully-connected-vs-convolutional-neural-networks-813ca7bc6ee5">Fully Connected vs Convolutional Neural Networks</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>