<?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 Manish Gupta on Medium]]></title>
        <description><![CDATA[Stories by Manish Gupta on Medium]]></description>
        <link>https://medium.com/@manish15gupta03?source=rss-a8616086ecdc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HP9Zr4CWAemxtprgLGW0Jg.jpeg</url>
            <title>Stories by Manish Gupta on Medium</title>
            <link>https://medium.com/@manish15gupta03?source=rss-a8616086ecdc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:18:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manish15gupta03/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[DeepSeek Models — the “aha” moment of AI world]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://generativeai.pub/deepseek-models-the-aha-moment-of-ai-world-dce5020c1624?source=rss-a8616086ecdc------2"><img src="https://cdn-images-1.medium.com/max/1640/1*o9fDpkp1VvQdikh1Ar3rMA.png" width="1640"></a></p><p class="medium-feed-snippet">Diving deep into DeepSeek Models performance and understanding the reason behind it.</p><p class="medium-feed-link"><a href="https://generativeai.pub/deepseek-models-the-aha-moment-of-ai-world-dce5020c1624?source=rss-a8616086ecdc------2">Continue reading on Generative AI »</a></p></div>]]></description>
            <link>https://generativeai.pub/deepseek-models-the-aha-moment-of-ai-world-dce5020c1624?source=rss-a8616086ecdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/dce5020c1624</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[reinforcement-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[deepseek]]></category>
            <dc:creator><![CDATA[Manish Gupta]]></dc:creator>
            <pubDate>Wed, 29 Jan 2025 06:26:55 GMT</pubDate>
            <atom:updated>2025-02-06T14:29:04.439Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Understanding Diffusion Models]]></title>
            <link>https://blog.cubed.run/understanding-diffusion-models-634b13dc611e?source=rss-a8616086ecdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/634b13dc611e</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[stable-diffusion]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Manish Gupta]]></dc:creator>
            <pubDate>Sat, 30 Nov 2024 07:43:27 GMT</pubDate>
            <atom:updated>2024-12-06T06:10:05.111Z</atom:updated>
            <content:encoded><![CDATA[<h4>An Illustrated Dive into Their Process and Design</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vcoIMPDh-RcQx9Tt" /><figcaption>Photo by <a href="https://unsplash.com/@beingabstrac?utm_source=medium&amp;utm_medium=referral">rishi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The idea of diffusion is not a new one, in fact almost every one has studied it in their high school. There was rather a big mammoth everyone feared in Physics whom we called <strong><em>“Thermodynamics”</em></strong>. Diffusion processes are a part of that.</p><p>Thermodynamics gives us the principles related to how all matter interacts with heat and energy, in other words:</p><blockquote>“Thermodynamics governs how energy moves and changes in the universe.”</blockquote><p>Phew! quite a bigwig if you ask me.</p><p>The non-equilibrium framework of this clossal gives us a sneak peak at the original diffusion process and what does it mean. Here’s an example to illustrate it further:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9N3uGwgJXevPnT8FnMWV3g.png" /><figcaption>Process of Diffusion: A stable system (left) transitioning into an un-stable system(right)</figcaption></figure><p>By definition, diffusion is a process of scattering or spreading out. Things like molecules, colours, or energy move from a place where they are crowded (like the left side of the jellybean jar) to a place where they are less crowded, all by themselves, or to put it in other words:</p><blockquote>Diffusion is the process of the molecules scattering from a stable system to an un-stable system by the gradual addition of randomness in them.</blockquote><p>Till now you might have connected some dots, we’re seeing some familiar terms now: diffusion, randomness, scattering, etc. Well, then you’re on the right track because this is where the concepts build upon.</p><p>We’re close to uncover the original idea, we just need one more fundamental to crack it. <strong><em>The idea of a machine (in our case an Image) going from a stable state (original image) to an un-stable state (filled with noise) </em></strong>sounds simple enough but it’s in-fact a very complex process and largely non-differential in manner. We need some way to break it down to be able to understand (ideally differentiate and calculate) and predict it → here comes the other fundamental: <strong>Markov property</strong>.</p><p>Remember, for diffusion to work in our case we need it to be reversible too i.e. given any state at time t, we need to be able to predict/calculate the state of the system at that time (which in-turn gives us the ability to calculate it for t+1 and similarly at time t-1). This imposes a unique challenge with the system but opens us up to a very intricate concept in physics i.e. the Markov property or the Markov rule.</p><blockquote>The <em>Markov property</em> states that the next state of a system only depends on the current state and not on any earlier states.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*-zqMR3o6-RCrJ_jGk0zIKQ.png" /><figcaption>A diagram representing a two-state Markov process. The numbers are the probability of changing from one state to another state.</figcaption></figure><p>Read it again, it only depends on the current state and not on any of the other states!! By adding this rule to the hypothesis, the whole diffusion process can now be modelled using a single noise function (<em>in reality there’s a ton of maths involved but don’t worry we’ll get into that in the later part</em>) and voila!</p><p>Now that we have all the pieces we need to build the concept, let’s dive right into the Diffusion models from a Machine Learning perspective and get to understand it better.</p><h3>Diffusion Models</h3><p>Diffusion models come from a class of <strong><em>generative models</em></strong> like <strong>VAEs</strong>, <strong>GANs</strong> and <strong>Flow based</strong> models. Each of them have shows great progress in generating some high quality samples, but they also come with their own limitations.</p><p>GAN models face challenges like unstable training and limited diversity in generation, stemming from their adversarial training approach. VAEs have a tendency to use a surrogate loss function for optimisation. Flow models, on the other hand, require specialised architectures for them to be reversible transformations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7FgoPaa8KhsrrRS8MLAd4A.png" /><figcaption>Overview of different kinds of generative models.</figcaption></figure><p>Diffusion models are different however, the principles that we just discussed above: non-equilibrium thermodynamics combined with Markov property to slowly add random noise to a data until we reach at pure noise. To do this a fix procedure (we’ll call it a <strong><em>schedule</em></strong>) is used along with high dimensional latent variables (dimensionally equivalent to the original data). All this makes them better at generation w.r.t the other models in the category.</p><p>Let’s look at it more clearly:</p><h4>Forward Diffusion process</h4><p>The original concept that we saw earlier is defined as the forward diffusion process i.e. we take an image (left) and slowly convert it to pure noise (right) by destroying the structure of the underlying data distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6LoFjUzRMsq5SxRna8zC8g.png" /><figcaption>Left: Original Image; Right: Pure Noise</figcaption></figure><p>How? you might ask. We take the original image and gradually add some noise to it, we keep on repeating the process until we reach to the point where the image is just pure noise. An illustration of this is shown below, here we’ve used a linear schedule and you can see that how quickly the information residing in the image is lost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDO6xDY2cmZmV6gtFsk6FQ.png" /></figure><p>We can represent this process mathematically as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/0*JJFcWWZjPZUpvyhu.png" /><figcaption>equation 1</figcaption></figure><p>where <strong><em>q</em></strong> represents the forward process and terms <strong><em>x_t</em></strong> and <strong><em>x_t-1</em></strong> are outputs of the forward process at times <strong><em>t</em></strong> and <strong><em>t-1</em></strong> respectively.</p><p>The equation describes a Normal (<strong><em>N</em></strong>) distribution dependant on it’s mean</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/117/0*G2perpq2sV8rqu3p.png" /></figure><p>and variance <strong><em>β_t</em>​<em>I</em></strong><em> </em>terms.</p><p>The beta (<strong>β</strong>) here is referred to as the schedule. It controls the rate at which we add noise to our image, generally the overall value ranges from 0 to 1 but there can be variations in the mathematical functions used to compute it. The authors of the paper [1] experimented with three different types of schedules being constant, linear and quadratic but then choose to apply linear over a total timestamp of T = 1000 steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DcEgBFNIkzE3aDHIURHDmg.png" /><figcaption>Comparison of linear schedule (top) with cosine schedule (bottom) from [2]</figcaption></figure><p>Authors of paper [2] at OpenAI dug a little bit deeper to understand the effect of these schedules. As you can see the linear schedule images are mostly pure noise in the right quadrant, instead the cosine schedule adds the noise much more smoothly thus helping the model to learn the process better. This also helped them reduce the no of steps from T=1000 to T=50 to achieve the required results.</p><p>Now that we know about the schedule, let’s look ahead at how it is used in forward process.</p><p>As you can see, adding noise to each image step by step is a rather slow and compute intensive process, training a model this way could take a large amount of time and the distribution learned by it wouldn’t be robust so instead of going through each of the T=1000 or T=50 time steps for each image, the model learns the <strong>noise distribution of any arbitrary time step t. </strong>What does it mean? It means to arrive at a time step t; instead of going a total of 1,2,3,…,t-1 steps we just do a single step.</p><p>Let’s understand this with the help of a little math:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*L982pfbS6dq1pbTs-WEz7Q.png" /><figcaption>equation 2</figcaption></figure><p>Here the equation represents the total noise added in T time steps. Now, we already know that diffusion models work with Markov property i.e. the output of current step depends only on the last step thus the output at time step T depends only on output at time step T-1, and so on and we can write this as a function composition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*1S9umgmAZv9EqKvMm8yzZQ.png" /><figcaption>equation 3</figcaption></figure><p>Following until now? Great! Now each of these terms can be represented as a Normal distribution (similar to equation 1)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*ZmfVuhn2R1k6WKSEN3IWUA.png" /><figcaption>equation 4</figcaption></figure><p>where x0 is the initial term (original image) samples from a data distribution, x1 is the term we get by adding a noise to that. Similarly for each time step t we can formulate a similar equation to derive it’s value.</p><p>Now this is okay, we got an idea of how we can calculate the output at any arbitrary time step t, but do you see a problem here? No, let me explain. This notion of Normal distribution is good for theoretical concepts but mathematically we need a way to differentiate it and how do you differentiate a random process like choosing a value from a distribution? The answer is simple: Reparameterization trick</p><p>It’s a mathematical way to modify the sampling process such that we don’t disturb the distribution but at the same time we shift the randomness to a variable ∊, see below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*u3bwFrPUbd2nlk8VzVug0Q.png" /></figure><p>Thus now we can still sample out variable (in this case z) while keeping the randomess in play and being able to differentiate it. Hold this thought — (1)</p><p>Another thing to note in equation 4 is that the mean term is only dependant on the time step t, thus authors rewrote the equation to ease the calculations by substituting the below symbols</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/1*VmhjbtWOF3U7g9RwlsmFOg.png" /></figure><p>Thus, the equation at 4 becomes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*QQSagXl5W9bsZj9SYotbgA.png" /></figure><p>and since mean is the only term that changes, to compute the total noise we can calculate</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TB4iOW3Jsfa5jJ10eyMI0w.png" /></figure><p>giving us the equation 5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*K9fPrwNyq5TAphjEzCXA3g.png" /><figcaption>equation 5</figcaption></figure><p>Adding the reparameterization trick from (1) we get the final equation as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lebp7dhdvXVXCxoqgffyLQ.png" /></figure><p>Using that equation, we can directly compute the noise at any specific step t without needing to follow the entire process.</p><h4>Reverse Diffusion process</h4><p>As the name suggests, reverse diffusion is the process of converting pure noise to an image. The idea is to use a neural architecture to process this noise into an image. You might remember the GAN architecture, it uses a similar method of starting from a random noise distribution and converting it to generate images → the concept is same but with a very big improvement: unlike GANs, we don’t try to do it all in one step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zxwNdWxQWb0S78h9h03Xfw.png" /><figcaption>Diffusion process as represented in [1]</figcaption></figure><p>Now, there’s a very common misconception about what exactly the neural architecture (diffusion model) does i.e it is removing noise from an input image or predicting the noise to be removed from an input but both are incorrect. <strong>Diffusion models predict the entire noise to be removed for any time step t </strong>i.e consider an example as below:</p><p>You trained your model with T=1000 time steps and now you’re doing inference with the same model. Let’s consider the no of steps is specified as 10 (to ease the calculation) so what the model does is:</p><p>— At Step 1, the model takes a pure noise sample as input and predicts the total noise to remove to arrive at t=0 step from t=1000 and then we subtract the noise from t=1000 to t=900 (see the output equation 6 below) to get the image at time step t=900.</p><p>This goes on for each step we mentioned, at step 2, it’ll predict the noise to go from t=900 to t=0 and using our output equation we’ll create the input image for t=800 and so on.</p><p>Taking the equation from the paper:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*6JJ17CPvBPUipbB0HC5dHQ.png" /></figure><p>where <strong><em>p𝛉</em></strong> is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*-E_c3MbiXlGSAjvVAPR9mg.png" /></figure><p>Although this might seem complex, it essentially states that <strong><em>p𝛉</em></strong> (the diffusion process) is a sequence of Gaussian transitions. It begins with <strong><em>p(x_T)</em></strong> and iterates <strong><em>T</em></strong> times using the equation for a single diffusion step, <strong><em>p𝛉(x_{t-1}/x_t)</em></strong>.</p><p>Looking at it, we know we’re dealing with a Normal distribution which has a mean and a variance. Here you’ll notice that along with mean, the variance is also time dependent but the Authors of the 2020 paper [1] decided to set the second part <strong>to be time-dependent but not trainable. </strong>It’s not set to be constant but rather set to equal <strong><em>β_t​I.</em></strong></p><p>Next coming to the mean term, it becomes (for interested readers the full derivation is <a href="https://lilianweng.github.io/posts/2021-07-11-diffusion-models/#reverse-diffusion-process">here</a>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*YCrqjLnZdmqRNFEbUdilHw.png" /></figure><p>which gives us</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*Ty7OPD_NgeCqPEvuI586fw.png" /></figure><p>which we can use to calculate the output value for a given timestep t</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*Styx4j8agiuok6uIFGfJhg.png" /><figcaption>equation 6</figcaption></figure><p>where the <strong>∈ term</strong> is the model’s predicted noise.</p><p>Thus, when model predicts the total noise present in the current noisy image <strong><em>x_t​</em></strong>, instead of removing all of it in one step, we discount it based on the current noise schedule <strong><em>β_t</em></strong>​.</p><p>Due to this we get the flexibility in choosing the schedule during the inference time as well. For instance, you could train with a linear schedule but switch to a cosine schedule for inference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*N0fHVprJAmPL_x-b.gif" /></figure><p>This article dives deep into the core concepts and theory behind diffusion models — their origins, the complex math involved, and how they work at a fundamental level. I’ve kept it concise and beginner-friendly to ensure you grasp the essence without feeling overwhelmed.</p><p>We’ve focused on the early diffusion models here, but there’s so much more to explore! Future articles will delve into advanced topics like Classifier-Free Guidance, Classifier-Guided Diffusion, Latent Consistent Models, sLoRAs, ControlNets, and detailed architecture breakdowns.</p><p>If you enjoyed this post, stay tuned for more in-depth explorations! And feel free to connect with me on <a href="https://www.linkedin.com/in/manish-gupta15/">LinkedIn</a> — I’d love to hear your thoughts or chat more about AI and image generation.</p><p>References:</p><ol><li><a href="https://arxiv.org/pdf/2006.11239">https://arxiv.org/pdf/2006.11239</a></li><li><a href="https://arxiv.org/pdf/2102.09672">https://arxiv.org/pdf/2102.09672</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=634b13dc611e" width="1" height="1" alt=""><hr><p><a href="https://blog.cubed.run/understanding-diffusion-models-634b13dc611e">Understanding Diffusion Models</a> was originally published in <a href="https://blog.cubed.run/">Cubed</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Capsule Networks: Everything You See Is Not True]]></title>
            <link>https://pub.towardsai.net/capsule-networks-everything-you-see-is-not-true-ae9bdba902a5?source=rss-a8616086ecdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae9bdba902a5</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Manish Gupta]]></dc:creator>
            <pubDate>Fri, 24 Jun 2022 12:03:19 GMT</pubDate>
            <atom:updated>2022-06-24T12:03:19.984Z</atom:updated>
            <content:encoded><![CDATA[<h4>Expensive alternative to Convolutional Neural Networks (CNNs)</h4><p>Today when we talk about data, we’re no longer confined to the traditional columnar or CSV-type data sources. There has been a rise in data of all formats and types ranging from sound to image data, from cross-sectional to time-series format due to better availability of data structures and methods to retrieve and store different kinds of data.</p><figure><img alt="Wrapper Image" src="https://cdn-images-1.medium.com/max/1024/0*lwHWldzBTP0IcAVI" /><figcaption>Photo by <a href="https://unsplash.com/@swimstaralex?utm_source=medium&amp;utm_medium=referral">Alexander Sinn</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article is rather focused on one such type of data, Visual data to be precise, and its context with Machine Learning. The foremost approach earlier to deal with Image data was to flatten the data into a vector and pass them into a Neural Network or some other Machine Learning algorithms for different purposes. With the development of Deep Learning, things took a drastic turn, and the world was introduced to <strong>Convolution Neural Networks (CNNs) by Yann LeCun in the late 80s</strong>. CNNs have proven to be the current state-of-the-art (SOTA) methodology for working with Visual data of all kinds ranging from images to continuous data like Video clips.</p><p>In the case of CNNs we just load the data and train the network to identify features in the 2D space which get tangled when flattened. With successive layers building up the network, the field of view of later layers keeps on increasing making it possible to learn more complex features. Yann LeCun demonstrated this concept by training a five-layer model on the MNIST dataset and classifying the digits with a 98.49% accuracy.</p><p>Despite being the game-changer in the field of Deep Learning, CNNs have inherent disadvantages that most people are unaware of. We’ll explore them now and that will help us build a base for the main topic of this blog: CapsuleNets.</p><h4><strong>Disadvantage #1</strong></h4><p>Due to their nature of capturing feature information for higher-level tasks such as classification, segmentation, object location, etc. they have been agnostic to the position and/or the orientation of those features. When we hope for them to learn the distribution of a dataset, they rather focus on the training images supplied to them.</p><h4>Disadvantage #2</h4><p>Given the above limitation, CNNs are however agnostic to the relative positions of these features also. While moving upward in the layers, they only capture what features are present in the image to perform their task. This limitation arises due to the structural issues in any CNN architecture.</p><p>In CNNs, we often use pooling layers to reduce the image size or to cut down the computational burden, but what we don’t think is that by averaging or taking the pixel with the highest values we’re losing a lot of positional information about that feature. Also, by choosing the one with the highest value, we’re basically sub-sampling the features from the image.</p><p>Focus on the image below to better understand these two disadvantages:</p><figure><img alt="Limitation of ConvNets while recognizing a face." src="https://cdn-images-1.medium.com/max/1024/1*wYXgdq31b6-5hs4R5Nq9sg.png" /><figcaption>Source: <a href="https://www.spiria.com/en/blog/artificial-intelligence/deep-learning-capsule-network-revolution/">Spiria</a></figcaption></figure><p>Take the left-most image as the reference image, we have trained our current ConvNet on it. Now, as per the 1st disadvantage, when we rotate the image, the filters extracting the important information such as eyes, nose, and mouth may not be aligned with their position in the right-most image. And as the network has not seen any image like that in its training, it hasn’t generalized well so it makes a wrong prediction.</p><p>Now for the 2nd disadvantage, consider the image in the middle. The overall orientation of the face is similar but we’ve swapped the locations of some of the features. Here, the network is able to recognize some of the features, if not all, with the respective filters placed in its space, and thus it classifies it as a face.</p><h4>Disadvantage #3</h4><p>The third and final flaw is again due to the design of these ConvNets. The way they route information to the higher layers creates a broader receptive field for these upper layers. Instead of routing all the information through all the layers, networks can be made selective so as to pass the required information to the respective layer.</p><p>Our brain functions in a similar manner, we have different lobes that have their own specific function at which they are good. Similarly, routing the feature of an eye only to the part that detects face is much more intuitive rather than sending it to the filter detecting animals, chairs, etc.</p><p>CapsuleNets are inspired by this phenomenon, like our brain it works using the concept of <strong><em>‘inverse graphics’</em></strong>. Let’s understand the working of CapsuleNets using an example. The overall architecture is divided into three sub-parts:</p><ol><li>Primary Capsules</li><li>Higher Layer Capsules</li><li>Loss calculation</li></ol><p>We’ll see the usage of each of the sub-part in the example.</p><p>Before we begin, we will learn about the basic building block of CapsuleNets, i.e. the Capsule, and how it is different from a neuron. For all other networks, we have a concept of a neuron that resembles the one found in our brain. It takes a set of inputs, weighs them using its learned weights, and then applies an activation function on top of it to build complexity into the model.</p><p>Capsule does similar things, but the main difference lies in the output of both the blocks. Capsule outputs a vector instead of a scalar quantity like neurons. This vector carries information about the orientation of the object inside the image. If you rotate the object and/or the image, this vector representation would be simultaneously affected it.</p><h4><strong>Primary Capsules</strong></h4><figure><img alt="Images of a home and a boat created by two basic building blocks." src="https://cdn-images-1.medium.com/max/1000/1*N5H1A-I_ssbClJZLwy8a6g.png" /><figcaption>Source: Image by the author.</figcaption></figure><p>Consider the image above. We can say that the above images are made up of two fundamental parts, a triangle, and a rectangle. Now suppose that we initialize the Primary Capsule layer with 200 capsules, 100 representing the rectangle and the other 100 for the triangle.</p><p>They are distributed such that they cover the whole image. The output of each of these capsules is represented using arrows in the below image; black arrows represent the rectangle’s output and the blue ones for a triangle. To decide if a particular object is present or not, we focus on the length of those arrows while their pose gives us information about the orientation of that particular object (position, scale, rotation, and so on).</p><figure><img alt="Visualization of vector outputs by the Capsules at Primary Capsule Layer." src="https://cdn-images-1.medium.com/max/1000/1*S6YCYRfvanQfvimrL_bleg.png" /><figcaption>Visualization of vector outputs by the Capsules at Primary Capsule Layer. Source: Image by the author.</figcaption></figure><p>These capsules also follow the property of equivariance, i.e. for a slight change in the position/orientation of the object, we’ll see a corresponding change in the arrows representing these objects. This helps CapsuleNet to locate the object in the image and have precise information regarding the pose parameters.</p><figure><img alt="Effect of changing orientation of the Object inside the image." src="https://cdn-images-1.medium.com/max/1000/1*VIunwfFuT54Zy7ZsFUdv2Q.png" /><figcaption>Effect of changing the orientation of the object inside the image. Source: Image by the author.</figcaption></figure><p>To achieve this, the Primary Capsule layer goes through three different phases:</p><p>i) Convolution</p><p>ii) Reshape</p><p>iii) Squash function</p><p>We take the image and process it through Convolution layers to get output feature maps. We then reshape those feature maps.</p><p>In our example, let’s consider we got 50 feature maps as output, we reshape them to two vectors of 25 dimensions (50 = 25*2) for every location in the image. Each vector represents one of the two fundamental shapes. These values now can be inferred as the probability of each of the fundamental shapes present or not at a particular location in the image, but to do so they must have their lengths between 0 to 1. To achieve this, we apply the <strong><em>squash function</em></strong>. It basically takes the vector and applies the norm and then a non-linear function to maintain its length between 0 and 1.</p><figure><img alt="Overall process of Primary Capsule layer." src="https://cdn-images-1.medium.com/max/1000/1*hKgDQwtiomYTdr1hGjps4A.png" /><figcaption>The overall process of the Primary Capsule layer. Source: Image by the author.</figcaption></figure><p>So, till now we have the information about the presence of the fundamental shapes in the image. We now need to take this information and infer if it’s a boat or a house. For that, we move to the next layer in CapsuleNet — Higher Layers.</p><h3>Higher Layers</h3><p>The next step is the function of Higher layers. But before we jump into them, primary layers have one more function to do. After the squash output, the primary layers also try to predict the output of each of the higher layers. We had 100 capsules for rectangles and 100 for triangles which will give some predictions, supposing that the higher layer has two capsules, one for house and one for boat, these predictions are made w.r.t and the orientation of the shapes found.</p><p>Due to the extra information on the pose, the capsules will be able to get to a consensus that the object present can be a boat. This is called <strong><em>routing by agreement</em></strong>. Due to this, the signals are now only sent to the higher level capsule representing the boat and not the other one.</p><p>Now, the work of the higher layer begins, even though the primary layers predicted some output for the higher layer, it still needs to predict its own output and validate the same. Initially, the higher layers set the <em>routing weights</em> which are used by the lower layers to route the image signal. It does so by calculating its own output and then validates the output by the lower layers. Based on the similarity of both the predictions, the weights are updated.</p><p>Also, after we get the output from the higher layers, we can add a third layer on top of the higher layer which will be a layer of neurons to classify the image based on the vector output it’ll receive.</p><h4>Wrap Up!</h4><p>In the article, we saw the working of a CapsuleNet and the intuition that gave birth to this concept. Starting from the drawbacks of CNNs, we built towards their solutions and how CapsuleNets can be a viable alternative for them.</p><p>Although intuition and algorithms seem to do well it had their own cons when it comes to reality.</p><ul><li>Due to the dynamic routing and a large number of capsules, the computation becomes heavy and demands a higher computational resource.</li><li>It also suffers from the problem of crowding when two objects of the same type are placed close to one another.</li></ul><p>Despite these, CapsuleNets serve as a promising approach for the community and thus can be further improved upon.</p><p>Hope the article was able to clearly shed some light on the overall concept and helped you gain a deeper understanding of CapsuleNets. Stay tuned for more such pieces in the future. Au Revoir!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae9bdba902a5" width="1" height="1" alt=""><hr><p><a href="https://pub.towardsai.net/capsule-networks-everything-you-see-is-not-true-ae9bdba902a5">Capsule Networks: Everything You See Is Not True</a> was originally published in <a href="https://pub.towardsai.net/">Towards AI</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[YOLO — You Only Look Once]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/data-science/yolo-you-only-look-once-3dbdbb608ec4?source=rss-a8616086ecdc------2"><img src="https://cdn-images-1.medium.com/max/2600/1*SxUACIk1b_5kSXrdby2Zpg.jpeg" width="5184"></a></p><p class="medium-feed-snippet">A State of the Art Algorithm for Real-Time Object Detection System</p><p class="medium-feed-link"><a href="https://medium.com/data-science/yolo-you-only-look-once-3dbdbb608ec4?source=rss-a8616086ecdc------2">Continue reading on TDS Archive »</a></p></div>]]></description>
            <link>https://medium.com/data-science/yolo-you-only-look-once-3dbdbb608ec4?source=rss-a8616086ecdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dbdbb608ec4</guid>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[yolo]]></category>
            <dc:creator><![CDATA[Manish Gupta]]></dc:creator>
            <pubDate>Sat, 30 May 2020 15:49:27 GMT</pubDate>
            <atom:updated>2020-05-30T17:16:07.379Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[NST — Creating Artworks with the help of machine]]></title>
            <link>https://medium.com/analytics-vidhya/nst-creating-artworks-with-the-help-of-machine-56ebd3eb780c?source=rss-a8616086ecdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/56ebd3eb780c</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[neural-style-transfer]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Manish Gupta]]></dc:creator>
            <pubDate>Mon, 04 May 2020 18:10:00 GMT</pubDate>
            <atom:updated>2020-05-07T17:08:53.041Z</atom:updated>
            <content:encoded><![CDATA[<h3>NST — Creating Artworks with the help of machine</h3><h4>Generating new arts by manipulating a base image to adopt an appearance of a different image</h4><p>Many of us know how hard is to create an outstanding piece of art and the effort and experience that goes in while creating it is just commendable. While it seems like a patient and hard-to-acquire skill, you can actually create impressive artworks with just the help of a Deep Learning Algorithm.</p><p><strong>Neural Style Transfer (NST)</strong> is a Deep Learning Algorithm which helps us create astounding artworks with no prior knowledge in art particularly. The basic idea of this algorithm is to take a base image which we classify as a <strong>Content Image</strong> and then try and manipulate its pixels to overlay another image called <strong>Style Image</strong> to produce the desired Art!</p><p>While as deceptive as it seems it’s true and the method actually works. Take a look at the images created by using this Algorithm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9vNRUqLMKe_L-7hNmkuJfA.png" /><figcaption>Left: <a href="https://commons.wikimedia.org/wiki/File:YellowLabradorLooking_new.jpg">Yellow Labrador Looking</a>, from Wikimedia Commons; Middle: <a href="https://commons.wikimedia.org/wiki/File:Vassily_Kandinsky,_1913_-_Composition_7.jpg">Kandinsky’s Painting</a>; Right: Image output by the Model</figcaption></figure><p>The <strong>Content Image</strong> in this context is the one in the left and the one in the middle is the <strong>Style Image</strong> and the one to the right is the <strong>Target Image</strong>, we’ll address them with with the above terminologies throughout the read.</p><p>Before indulging into the technicalities of the work, I will first try and establish the intuition behind it. Whenever we think of an image editing, what really comes to our mind is the different combinations of pixel values spanned across the three channels of color namely RGB. So, think of NST as taking the Content image and just putting the Style image on top of it as a new layer like applying a filter over an image, the only difference behind it is that it’s actually no applied directly over the pixels however, it is learned with the help of various image feature combinations.</p><p>If you’re from the ML/DL community you might know that there’s no better algorithm than CNN (Convolution Neural Network) to extract rich features from an Image. Using deep enough CNN we can extract the high level features we require for NST. To do our task we need CNN to find <strong>“what is in an image?”</strong> for us so that we can use it to create the Target image. As the layers of the CNN gets deeper and deeper they learn many complex functions which can tell us what actually an image is made up of.</p><p>We feed our <strong>Content Image</strong> and <strong>Style Image</strong> to a <strong>CNN network</strong>. Once it has learned the features of the image, we compute the <strong>Total Loss function</strong>. This loss function is the weighted average of two losses namely <strong>Content Loss</strong> and <strong>Style Loss</strong>. Intuitively, we are iteratively updating our output image in such a way that it minimizes our total loss by bringing the output as close as possible to the content of the target image and the style of the reference image.</p><p><strong>Content Loss:</strong> The Content loss is defined as the L2 distance between the intermediate content representations, taken from higher layers of a pre-trained neural network, for an input image and the target image. As a higher level layer produces filters that possess complex raw information for the input image, this is a suitable approximation for judging similarity in terms of content. The equation is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9OPlsoJamM3ccG2dZfRiWg.png" /><figcaption>Equation for the Content Loss, defined as the squared-error loss between the two feature representations of the target and output images in a particular layer L</figcaption></figure><p><strong>Style Loss: </strong>Similarly, we define the style loss as the L2 distance between the gram matrices of the intermediate style representations for the style image (taken from lower layers of a pre-trained neural network) and the output images. The lower level layers capture more simple image features which best encode the concept of style. Also, by the use of the Gram Matrix, we distribute and delocalize spatial information in an image and approximate the <strong>style </strong>of an image. Mathematically, it’s just the matrix multiplication of the image matrix and its transpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*8dku-tGVqNieEnEKXTUT7A.png" /><figcaption>Equation for the Gram Matrix. G is the inner product between the vectorized feature maps i and j in a particular layer L</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mjnYfBShodiH2-N3DQFESQ.png" /><figcaption>Equation for the Style Loss, defined as the squared-loss error between the gram matrices of the style reference and the output image, over a subset of particular layers.</figcaption></figure><p>Finally, we add these two losses together into the Total Loss and train the network to minimize the loss.</p><h4>Implementation</h4><p>Now, after grasping the main elements of the network, we’ll move towards the implementation of NST with the help of <strong>Tensorflow.</strong></p><p>First of all we’ll load all the packages we need for the implementation</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a159cbd104a7f6be78208dd7d2dd89e/href">https://medium.com/media/5a159cbd104a7f6be78208dd7d2dd89e/href</a></iframe><p>In the next step, you will write a helper function which will load the two images in arrays of numbers (because computers understand only numbers) and reshape them for making them compatible with the model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59a2595bf704ad988bfa32989b05aa6b/href">https://medium.com/media/59a2595bf704ad988bfa32989b05aa6b/href</a></iframe><p>Now use the above created function and load our <strong>Content</strong> and <strong>Style</strong> Images</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2039ff397266bcc7c32699078f9ce061/href">https://medium.com/media/2039ff397266bcc7c32699078f9ce061/href</a></iframe><p>The images are reshaped. Now, you will load a pre-trained VGG19 model for extracting the features. As you will be using the model for extracting features, you will not need the classifier part of the model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/215e8ec6eef70cc57e0ee8d14e9dffe0/href">https://medium.com/media/215e8ec6eef70cc57e0ee8d14e9dffe0/href</a></iframe><p>We’ll take a look at the VGG19 model you just loaded and print the names of all the layers present in the network.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0771263a468d52ce0e2d553c801aa23/href">https://medium.com/media/e0771263a468d52ce0e2d553c801aa23/href</a></iframe><p>You are interested in the following ones for getting the style features, however:</p><ul><li>‘conv1_1’</li><li>‘conv2_1’</li><li>‘conv3_1’</li><li>‘conv4_1’</li><li>‘conv5_1’</li></ul><p>For content features, you will need conv4_2. You will store these in variables accordingly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/28c6d190b5fe9079e19d87408d9a1d5e/href">https://medium.com/media/28c6d190b5fe9079e19d87408d9a1d5e/href</a></iframe><p>Now create a custom VGG model which will be composed of the specified layers. This will help you run forward passes on the images and extract the necessary features along the way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76e3b02b66ea87ec4361148194d79d26/href">https://medium.com/media/76e3b02b66ea87ec4361148194d79d26/href</a></iframe><p>Defining a gram matrix is super easy in TensorFlow, and you can do it in the following way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c85af90331745c417c43b2f666c0273/href">https://medium.com/media/2c85af90331745c417c43b2f666c0273/href</a></iframe><p>We will now define a custom model using the mini_model() function. This will be used for returning the content and style features from the respective images.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b71eaec2b6c0b4bcaccb5fd4a32e52e/href">https://medium.com/media/5b71eaec2b6c0b4bcaccb5fd4a32e52e/href</a></iframe><p>Now that we have defined the custom model let’s use it on the images to get the content and style features accordingly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ba2dc58517b0d07dba22645eb372248/href">https://medium.com/media/9ba2dc58517b0d07dba22645eb372248/href</a></iframe><p>We’ll load the optimizer function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf3fb0068392d3b947d37a24e4fc7712/href">https://medium.com/media/bf3fb0068392d3b947d37a24e4fc7712/href</a></iframe><p>Let’s now define the overall content and style weights and also the weights for each of the style representations as discussed earlier. Note that these are hyperparameters and are something you should play with.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26515efaf43a17ba958a7e5d424a915c/href">https://medium.com/media/26515efaf43a17ba958a7e5d424a915c/href</a></iframe><p>Now comes the most crucial part, which makes the process of neural style transfer a lot more fun — the loss function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a2be32eaae3c5101ec18d8eaeb9e532/href">https://medium.com/media/6a2be32eaae3c5101ec18d8eaeb9e532/href</a></iframe><p>You will now write another function which will:</p><ul><li>Calculate the gradients of the loss function you just defined.</li><li>Use these gradients to update the target image.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/556e40ead02a7b7b021a3a6dde18472a/href">https://medium.com/media/556e40ead02a7b7b021a3a6dde18472a/href</a></iframe><p>We’ll set the target image to the content image at the beginning. And then we’re ready to train out model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1667096a354dcf98f0bff71d47a81a1c/href">https://medium.com/media/1667096a354dcf98f0bff71d47a81a1c/href</a></iframe><p>Hurray! All our work here is done. In just some minutes you created a brand new artwork of your own and that too without any prior knowledge in it.</p><p>That’s the power which Machine Learning gives in your hand. Embrace it! Enhance it! and Explore it! Give this article an clap if you like it. Happy Learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56ebd3eb780c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/nst-creating-artworks-with-the-help-of-machine-56ebd3eb780c">NST — Creating Artworks with the help of machine</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding ResNet and its Variants]]></title>
            <link>https://medium.com/data-science/understanding-resnet-and-its-variants-719e5b8d2298?source=rss-a8616086ecdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/719e5b8d2298</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[resnet]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Manish Gupta]]></dc:creator>
            <pubDate>Thu, 09 Apr 2020 15:22:10 GMT</pubDate>
            <atom:updated>2020-04-12T15:51:22.360Z</atom:updated>
            <content:encoded><![CDATA[<h4>Overview of the most groundbreaking work in the computer vision/deep learning community — ResNets</h4><p>Since the availability of high computation units, the machine learning community has witnessed a paradigm shift towards the deep learning practices to achieve better results, especially in the Computer Vision domain. One promising approach is the Convolution Neural Network. CNN is an improved version of traditional Neural Networks which keeps the spatial dimension intact.</p><p>CNN has outperformed various other frameworks for Image classification, Object detection, etc. and thus is of keen interest to the researchers. In an effort to make this learning more and more accurate, researches have started implementing deeper and deeper Convolution networks.</p><p>The topic of selecting the right number of layers for training has been in discussion for a long time and as it turns out making a much deeper Network doesn’t improve the accuracy but rather degrades it. Yes, you heard it right as you stack more and more units in the network, the network’s learning capacity gets saturated and after a threshold, it falls down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*BwyYzWBlaLd22OaaXAF5AA.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1512.03385.pdf">Deep residual learning for image recognition</a>, Test and Train errors for “plain” networks</figcaption></figure><p>The two basic reasons why the accuracy falls for such networks instead of going up are :</p><ol><li>Vanishing/ Exploding Gradients</li><li>Degradation Problem</li></ol><p>However, the 1st problem is been taken care of by normalized initialization and intermediate normalization layers, which enable networks with tens of layers to start converging for stochastic gradient descent (SGD) with backpropagation.</p><p>But when the deeper networks start converging, they observe the Degradation problem. With the network depth increasing, accuracy gets saturated and then degrades rapidly. One method to help remove this degradation problem is to add the additional layers with an identity mapping.</p><p><strong>ResNet</strong>[1] introduces these <strong>“Identity mapping”</strong> or <strong>“skip connections”</strong> that skips one or more layers as shown in the figure :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*NaydVEFR5aM8hh_Ry1FJcw.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1512.03385.pdf">Deep residual learning for image recognition</a>, A residual block with an identity mapping</figcaption></figure><p>The idea is that instead of just stacking additional layers into the network, we add them as residual blocks (having identity mappings). To achieve the results in this scheme, the authors of the work have tweaked the underlying mapping and make the non-linear layers learn the mapping :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/1*nvPrWs70SEtY-Fi6wnd2DA.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1512.03385.pdf">Deep residual learning for image recognition</a></figcaption></figure><p>instead of the conventional mapping H(x) and the original mapping is recast to :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/101/1*pc2rPhswP3qCiITJIiypuQ.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1512.03385.pdf">Deep residual learning for image recognition</a></figcaption></figure><p>Another benefit of introducing these shortcut connections is that they do not add any extra parameters nor increase the computational complexity as they are employed as identity mappings. However, they ensure that the deeper networks perform as good as it’s shallower counterparts.</p><p>The originally proposed ResNet structure is presented below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*lFnm5i-oYWIs3WW4pxg47Q.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1512.03385.pdf">Deep residual learning for image recognition</a>, Originally proposed ResNet</figcaption></figure><p>One thing to notice here is those dotted lines, which denotes a linear projection. Ideally, to perform the identity mapping, dimensions of both F(x) and X must be the same, but when this is not the case we use a projection vector Ws to help match the dimensions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/289/1*OjWBnE_QqNw77CpfAMQpVg.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1512.03385.pdf">Deep residual learning for image recognition</a></figcaption></figure><p>Another study was carried out to determine exactly when these “skip connections” should be introduced!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HSBsh3KM_l9enDJemfRatw.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1603.05027.pdf">Identity Mappings in Deep Residual Networks</a>, Various flavors of ResNet blocks</figcaption></figure><p>Every possible combination was tested and tried before coming to the final version of the residual block having full pre-activation i.e. (e) in the above figure.</p><p>Because of its compelling results, ResNet quickly became one of the most popular architectures in various computer vision tasks.</p><h3><strong>Popular Variants of ResNets</strong></h3><p>As the popularity of ResNets grew, it’s architecture was heavily studied and researchers came up with different variants of the originally proposed work.</p><h4>ResNeXt</h4><p>Based on the original work, an alternative called <strong>ResNeXt</strong> [2] was proposed with the following building block :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*Xbr3QLvoqQICmAzsM8SFYw.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1611.05431.pdf">Aggregated Residual Transformations for Deep Neural Networks</a></figcaption></figure><p>This model adopts the strategy of ResNets of repeating layers while incorporating the split-transform-merge strategy in an easy, extensible way. The block may look similar to the Inception network [3] where we perform various different transformations (1x1 Conv, 3x3 Conv, 5x5 Conv, MaxPooling ) and stack them together, whereas here we merge the different transformations by adding them together.</p><p>This type of block introduces one more dimension <strong>cardinality</strong> — the number of independent paths, along with the existing height and depth dimensions. The significance of this dimension was experimentally proved by its authors that “increasing cardinality is a more effective way of gaining accuracy than going deeper or wider,” especially when depth and width starts to give diminishing returns for existing models.</p><p>The proposed building block has three possible variations :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-E9Exz2mewmYKdnHf8axA.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1611.05431.pdf">Aggregated Residual Transformations for Deep Neural Networks</a>, Equivalent blocks of ResNeXt</figcaption></figure><p>Authors also state that the model is easy to train rather than the Inception [3] network over different datasets, as it has only one hyperparameter to be adjusted unlike in Inception where we have more hyperparameters to adjust.</p><h4>DenseNet</h4><p>Another popular variation of the ResNet is <strong>DenseNet</strong> [4] where the authors have tried to solve the problem of vanishing gradients by making extra connections. In DenseNet, they ensure maximum information flow between the layers in the network by connecting all layers directly with each other. To preserve the feed-forward nature, each layer obtains additional inputs from all preceding layers and passes on its own feature-maps to all subsequent layers. The model is shown below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*2MDMWFm9v-8werzhdn3cQA.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1608.06993.pdf">Densely Connected Convolutional Networks</a>, DenseNet Layers connected with each other</figcaption></figure><p>Along with tackling the vanishing gradients, the authors also argue that this implementation enables feature reuse, making the network highly parameter efficient. In the traditional models, each layer acts as a state, it reads from a previous state and writes to the subsequent layer. It changes the state but also passes on information that needs to be preserved.</p><p>The DenseNet architecture explicitly differentiates between information that is added to the network and information that is preserved and the final classifier makes a decision based on all feature-maps in the network. Along with better parameter efficiency, DenseNet also provides an improved flow of information and gradients through the network, which makes it easy to train.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3Feq_pw2i5S_kyD5Qq1Ng.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1608.06993.pdf">Densely Connected Convolutional Networks</a>, A deep DenseNet with three Dense blocks.</figcaption></figure><p>The <em>l</em>th layer receives the feature maps from all of its preceding layers as inputs :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*XnqXc9onRrXuZxxVgfvHxA.png" /><figcaption>src: <a href="https://arxiv.org/pdf/1608.06993.pdf">Densely Connected Convolutional Networks</a></figcaption></figure><p>where [ .. ] signifies the concatenation operation. To facilitate downsampling in the network, it is divided into parts as shown above with transition layers in between. The transition layers consist of the batch normalization layer, convolution layer, and max-pooling layer.</p><p>Because of their compact internal representations and reduced feature redundancy, DenseNets may be good feature extractors for various computer vision tasks that build on convolutional features.</p><p>I hope it helps the readers to strengthen their understandings of this groundbreaking work.</p><p>All the figures of the article were taken from the original papers in the references.</p><h3>References :</h3><p>[1]. K. He, X. Zhang, S. Ren, and J. Sun. Deep residual learning for image recognition. arXiv preprint arXiv:1512.03385,2015.</p><p>[2]. S. Xie, R. Girshick, P. Dollar, Z. Tu and K. He. Aggregated Residual Transformations for Deep Neural Networks. arXiv preprint arXiv:1611.05431v1,2016.</p><p>[3]. C. Szegedy, W. Liu, Y. Jia, P. Sermanet, S. Reed, D. Anguelov, D. Erhan, V. Vanhoucke, and A. Rabinovich. Going deeper with convolutions. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 1–9,2015.</p><p>[4]. G. Huang, Z. Liu, K. Q. Weinberger, and L. Maaten. Densely Connected Convolutional Networks. arXiv:1608.06993v3,2016.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=719e5b8d2298" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/understanding-resnet-and-its-variants-719e5b8d2298">Understanding ResNet and its Variants</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>