<?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 Leon Sick on Medium]]></title>
        <description><![CDATA[Stories by Leon Sick on Medium]]></description>
        <link>https://medium.com/@leon.sick?source=rss-fa7caddf2d75------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ViqkMq-xDLZBaFo0EZI7tQ.jpeg</url>
            <title>Stories by Leon Sick on Medium</title>
            <link>https://medium.com/@leon.sick?source=rss-fa7caddf2d75------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 04 Apr 2026 02:08:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leon.sick/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[Paper explained: Exploring Plain Vision Transformer Backbones for Object Detection]]></title>
            <link>https://medium.com/data-science/paper-explained-exploring-plain-vision-transformer-backbones-for-object-detection-a84483ac83b6?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/a84483ac83b6</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[self-supervised-learning]]></category>
            <category><![CDATA[object-detection]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Sun, 20 Nov 2022 09:29:18 GMT</pubDate>
            <atom:updated>2022-11-21T17:11:00.750Z</atom:updated>
            <content:encoded><![CDATA[<h4>The power of ViTs as object detection backbones</h4><p>In this story, we will take a closer look at a paper published recently by researchers from Meta AI, where the author explore how a standard ViT can be re-purposed to be used as an object detection backbone. In short, their detection architecture is called <strong>ViTDet</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XcZacP2BLipc8sie6RkBPg.png" /><figcaption>A visualization of a feature pyramid network (FPN) used for a plain backbone, like the one in ViTDet, an a “classic” hierarchical backbone, commonly represented as a CNN. Source: [1]</figcaption></figure><h4><strong>Pre-requisite: Object Detection Backbones</strong></h4><p>Previously, backbones for object detectors have profited from a different resolutions at different stages of the network. As displayed in the figure above, the feature map has different resolutions, from which the detection heads performing the actual object detection step greatly benefit. These backbones are commonly called <strong>hierarchical backbones</strong> in scientific literature. Commonly, ResNets or other CNNs are referred to as hierarchical backbones, but also certain ViTs like the Swin Transformer have hierarchical structures. The paper we will take a look at today has to deal with a different backbone structure: Since ViTs are made up of a certain number of transformer block, which all output features in the same dimensionality, it never outputs feature maps of different resolutions naturally. The authors tackle this issue in their paper and explore different strategies to construct a multi-resolution FPN.</p><h4><strong>Generating multi-resolution features from a single resolution backbone</strong></h4><p>Since ViTs naturally only provide one resolution for its feature maps, the authors explore how to convert this map to different resolutions using an FPN. To facilitate memory constraints and add global context to the feature outputs, the authors do not compute the self-attention for all ViT blocks. Instead, they opt to divide the transformer into 4 even sections, e.g. for a ViT-L with 24 blocks, each section makes up 6 blocks. At the end of each section, they compute the global-self attention for the section, whose output is used as a feature map for the FPNs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PUesn506Z0g6lg2aeqifoQ.png" /><figcaption>The different FPNs explored for ViTDet. Source: [1]</figcaption></figure><p>For <strong>approach (a)</strong>, they attempt construct a FPN-like solution by up- or downsampling the 1/16 feature map, using convolutions or deconvolutions, from the individual global-attention outputs of each section. They also add lateral connections, visualized by the arrows connecting the blue blocks.</p><p>For <strong>approach (b)</strong>, they construct the FPN by up- and downscaling only the last feature map from the global self-attention module. This means all features in the FPN are constructed from a single output. Also, they add the lateral connections again.</p><p>For <strong>approach (c)</strong>, they propose a very simple and puristic solution: Up- and downsampling the final global-attention output and not adding any lateral connections. This approach is by far the most minimalistic approach, but as we will see now, it works remarkably well.</p><h4><strong>Performance comparison of different FPN approaches</strong></h4><p>Let’s get right into it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XEYqniYZmLaGT7gL_tYzwg.png" /><figcaption>The results on COCO for different FPNs. Source: [1]</figcaption></figure><p>Remarkably, the <strong>simple FPN, approach (c), work the best</strong>, across two ViT sizes, for bounding box regression and instance segmentation on the MS COCO detection benchmark.</p><p>But why even attempt such a simple solution to enable plain ViTs to be used as detection backbones when there already are ViT-based detection networks? The answer will become apparent now.</p><h4>Comparison against state-of-the-art (SOTA) ViT detection networks</h4><p>Recent research in the field of self-supervised pre-training has started to unlock incredible capabilities in ViTs. One of the most promising tasks in this domain has to challenge a network to reconstruct the masked parts of an object, implement through the Masked Autoencoders (MAE) paper. We have revisited this paper on my blog, feel free to refresh your knowledge <a href="https://medium.com/towards-data-science/paper-explained-masked-autoencoders-are-scalable-vision-learners-9dea5c5c91f0"><strong>here</strong></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MJy5uBb8KrNNH40SBCtQZA.png" /><figcaption>Results on COCO of ViT-Det (the three bottom rows) compared to previous, ViT-based detectors. Source: [1]</figcaption></figure><p>The MAE pre-trains a standard ViT to learn reconstructing the masked parts of an image. This has proven to be a successful strategy for pre-training. To transfer this advantage to object detection, the authors create the ViTDet architecture. This is the entire purpose of the paper: Unlock the power of pre-training ViTs for object detection. And the results tell the story.</p><p>As you can see from the results table, pre-training the backbone with the MAE and then using their simple FPN on top yields SOTA results for ViT-based detection backbones. Since the Swin Transformer and MViT are not compatible with self-supervised pre-training strategies without modifications, they are pre-training supervised on ImageNet. Astonishingly, MAE pre-training unlocks much more performance then standard supervised pre-training. Therefore, the authors hint where future improvements in object detection research will come from: <strong>Not the detection architecture itself, but more powerful pre-training of the backbone in a self-supervised manner.</strong></p><p>In my eyes, this represents a key shift in object detection research. If you would like to read more about the paradigm shift self-supervised pre-training bring to computer vision domain, feel free to reach my story detailing the transition <a href="https://medium.com/towards-data-science/from-supervised-to-unsupervised-learning-a-paradigm-shift-in-computer-vision-ae19ada1064d"><strong>here</strong></a>.</p><h4>Wrapping it up</h4><p>We have explored the ViTDet architecture, a simple yet powerful modification to traditional FPNs, specifically to ViTs, that unlocks the power of self-supervised vision transformers for object detection. Not only that, but this research paves the way for a new direction of object detection research in which the focus is shifted from the architecture to the pre-training technique.</p><p>While I hope this story gave you a good first insight into ViTDet, there is still so much more to discover. Therefore, I would encourage you to read the papers yourself, even if you are new to the field. You’ll have to start somewhere ;)</p><p>If you are interested in more details on the method presented in the paper, feel free to drop me a message on Twitter, my account is linked on my Medium profile.</p><p>I hope you’ve enjoyed this paper explanation. If you have any comments on the article or if you see any errors, feel free to leave a comment.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story here and there and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] Li, Yanghao, et al. “Exploring plain vision transformer backbones for object detection.” <em>arXiv preprint arXiv:2203.16527</em> (2022).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a84483ac83b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/paper-explained-exploring-plain-vision-transformer-backbones-for-object-detection-a84483ac83b6">Paper explained: Exploring Plain Vision Transformer Backbones for Object Detection</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained: Pushing The Limits Of Self-Supervised ResNets: Can We Outperform Supervised…]]></title>
            <link>https://medium.com/data-science/paper-explained-pushing-the-limits-of-self-supervised-resnets-can-we-outperform-supervised-2ba322dd6409?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ba322dd6409</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Sat, 26 Feb 2022 15:37:29 GMT</pubDate>
            <atom:updated>2022-03-09T05:41:05.551Z</atom:updated>
            <content:encoded><![CDATA[<h3>Paper explained: Pushing The Limits Of Self-Supervised ResNets: Can We Outperform Supervised Learning Without Labels On ImageNet?</h3><h4>Exploring the novel approaches in ReLICv2</h4><p>In this story, we will look at a recent paper that pushes the state of self-supervised learning forward, published by DeepMind, and with the nickname ReLICv2.</p><p>In their publication <em>“Pushing the limits of self-supervised ResNets: Can we outperform supervised learning without labels on ImageNet?”</em>, Tomasev et al. present an improvement over their technique presented in the paper behind ReLIC named <em>“Representation learning via invariant causal mechanisms”</em>. At the core of their method stands their addition of a Kullback-Leibler-Divergence loss their that is calculated using a probabilistic formulation of the classical contrastive learning objective. Not only that, but they also use a refined augmentation scheme and learn from the successes of other relevant publications.</p><p>I’ve tried to keep the article simple so that even readers with little prior knowledge can follow along. Without further ado, let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pv8i_1XXjgp-Xg5luFLHDA.png" /><figcaption>An illustration of the ReLIC training pipeline. Source: <a href="https://arxiv.org/pdf/2010.07922.pdf">[1]</a></figcaption></figure><h3>Pre-requisite: Self-supervised &amp; unsupervised pre-training for computer vision</h3><p>Before we go deeper into the paper, it’s worth quickly re-visiting what self-supervised pre-training is all about. <strong>If you have been reading other self-supervised learning stories from me or you are familiar with self-supervised pre-training, feel free to skip this part.</strong></p><p>Traditionally, computer vision models have always been trained using <strong>supervised learning</strong>. That means humans looked at the images and created all sorts of <strong>labels</strong> for them, so that the model could learn the patterns of those labels. For example, a human annotator would assign a class label to an image or draw bounding boxes around objects in the image. But as anyone who has ever been in contact with labeling tasks knows, the effort to create a sufficient training dataset is high.</p><p>In contrast, <strong>self-supervised learning does not require any human-created labels</strong>. As the name suggest, <strong>the model learns to supervise itself</strong>. In computer vision, the most common way to model this self-supervision is to take different crops of an image or apply different augmentations to it and passing the modified inputs through the model. Even though the images contain the same visual information but do not look the same, <strong>we let the model learn that these images still contain the same visual information</strong>, i.e., the same object. <strong>This leads to the model learning a similar latent representation (an output vector) for the same objects.</strong></p><p>We can later apply transfer learning on this pre-trained model. Usually, these models are then trained on 10% of the data with labels to perform downstream tasks such as object detection and semantic segmentation.</p><h3>A combination of novel contributions and learnings</h3><p>Just as it is the case for many other self-supervised pre-training techniques, the first step in the ReLICv2 training process is all about data augmentations. In the paper, the authors first mention the use of previously successful augmentation schemes.</p><p>The first are the augmentations used in SwAV. Contrary to previous work, SwAV not only creates two different crops of the input image, but up to 6 croppings. These can be made in different sizes such as 224x244 and 96x96, the most successful quantity is two large crops and 6 small crops. If you would like to learn more about the augmentation scheme of SwAV, make sure to <a href="https://medium.com/towards-data-science/paper-explained-unsupervised-learning-of-visual-features-by-contrasting-cluster-assignments-f9e87db3cb9b">read my story on it</a>.</p><p>The second set of previously described augmentations come from SimCLR. This scheme is now used by pretty much all papers in this space. The image is manipulated by applying a random horizontal flip, color distortion, a gaussian blur and solarization. If you would like to read more about SimCLR, make sure to <a href="https://medium.com/towards-data-science/paper-explained-a-simple-framework-for-contrastive-learning-of-visual-representations-6a2a63bfa703">take a look at my article</a>.</p><p>But ReLICv2 also uses another augmentation technique: Removing the background from the object in the image. To achieve this, they train a <strong>salient background removal</strong> model on some of the ImageNet data in an unsupervised way. This augmentation has been found to be most effective by the authors when applied with a probability of 10%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JZZ6yW6vGgfXODW6aGkX8g.png" /><figcaption>The salient background removal augmentation using an unsupervised DeepUSPS. Source: <a href="https://arxiv.org/pdf/2201.05119.pdf">[2]</a></figcaption></figure><p>Once the image is augmented and multiple crops are made, the outputs are passed through an encoder network and a target network which output feature vectors of the same dimension. <strong>While the encoder network is updated using backpropagation, the target network receives updates through a momentum calculation</strong> similar to <a href="https://towardsdatascience.com/paper-explained-momentum-contrast-for-unsupervised-visual-representation-learning-ff2b0e08acfb">the MoCo framework</a>.</p><p>The overall goal of ReLICv2 is to learn the encoder network to produce consistent output vectors for the same classes. To achieve this, the authors formulate a novel loss function. They start with the <strong>standard contrastive negative log-likelihood</strong> which at its core has a similarity function that compares the anchor views (the main input image) to the positive examples (augmented versions of the image) and the negative examples (other images in the same batch).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dL5TcDyjC5ciDKFDEYUiow.png" /><figcaption>The ReLICv2 loss function consisting of the negative log likelihood and the Kullback-Leibler divergence of the anchor view and the positive views. Source: <a href="https://arxiv.org/pdf/2201.05119.pdf">[2]</a></figcaption></figure><p>This loss is extended by <strong>a probabilistic formulation of a contrastive objective</strong>: <strong>The Kullback-Leibler divergence between the likelihood of the anchor image and a positive</strong>. This <strong>enforces the network to not learn positives to be close together and negatives to be farer apart, but creates a more balanced landscape between the clusters when extreme clustering that could lead to a collapse in learning is avoided</strong>. Therefore, this additional loss term can be seen similar to a <strong>regulatization</strong>. The two terms are accompanied by an alpha and beta hyperparameter that allow an individual weighting of the two loss terms.</p><p>The addition of all these novelties prove to be successful. To find out in which ways, let’s have a closer look at the results presented in the paper.</p><h3>Results</h3><p><strong>The main point ReLICv2 is trying to prove, as it says in the title of the paper, is that self-supervised pre-training methods are only comparable if they all use the same network architecture for the encoder network.</strong> For their work, they have opted to use the classic ResNet-50.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HP0PtEEfpE2nwosi8EIqMQ.png" /><figcaption>Results of using the different pre-trained ResNet-50 under the ImageNet linear evaluation protocol. Source: <a href="https://arxiv.org/pdf/2201.05119.pdf">[2]</a></figcaption></figure><p>When using the same ResNet-50 and training its linear layer on ImageNet-1K while freezing all other weights, ReLICv2 outperfroms existing methods by a considerable margin. The introduced improvement even lead to a performance advantage versus the original ReLIC paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hbbG2e-gyGEyoZjWUj7WCg.png" /><figcaption>Increase in accuracy versus a supervised pre-trained model on different datasets. Source: <a href="https://arxiv.org/pdf/2201.05119.pdf">[2]</a></figcaption></figure><p>When comparing the transfer learning performance on other datasets, ReLICv2 continues to show impressive performance versus other methods such as NNCLR and BYOL. This further manifests ReLICv2 as a novel state-of-the-art methods for self-supervised pre-training. <strong>Evaluation on other datasets is not often mentioned in other papers.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9aa0GAiQvw4TB_2b_85qA.png" /><figcaption>An illustration of learned clusters by ReLICv2 and BYOL. The more blue the point, the closer it is learned to the corresponding class cluster. Source: <a href="https://arxiv.org/pdf/2201.05119.pdf">[2]</a></figcaption></figure><p>Another telling graphic shows the classes learned by ReLICv2 to be much closer together then they are for other frameworks such as BYOL. This again show that the techniques has the potential to create much more fine grained clusters then other methods.</p><h3>Wrapping it up</h3><p>In this article, you have learned about ReLICv2, a novel method for self-supervised pre-training that has shown promising experimental results.</p><p>By incorporating a probabilistic formulation of the contrastive learning objective and by adding proven augmentation schemes, this technique has been able to push the space of self-supervised pre-training in vision forward.</p><p>While I hope this story gave you a good first insight into ReLICv2, there is still so much more to discover. Therefore, I would encourage you to read the papers yourself, even if you are new to the field. You’ll have to start somewhere ;)</p><p>If you are interested in more details on the method presented in the paper, feel free to drop me a message on Twitter, my account is linked on my Medium profile.</p><p>I hope you’ve enjoyed this paper explanation. If you have any comments on the article or if you see any errors, feel free to leave a comment.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] Mitrovic, Jovana, et al. “Representation learning via invariant causal mechanisms.” <em>arXiv preprint arXiv:2010.07922</em> (2020). <a href="https://arxiv.org/pdf/2010.07922.pdf">https://arxiv.org/pdf/2010.07922.pdf</a></p><p>[2] Tomasev, Nenad, et al. “Pushing the limits of self-supervised ResNets: Can we outperform supervised learning without labels on ImageNet?.” <em>arXiv preprint arXiv:2201.05119</em> (2022). <a href="https://arxiv.org/pdf/2201.05119.pdf">https://arxiv.org/pdf/2201.05119.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ba322dd6409" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/paper-explained-pushing-the-limits-of-self-supervised-resnets-can-we-outperform-supervised-2ba322dd6409">Paper explained: Pushing The Limits Of Self-Supervised ResNets: Can We Outperform Supervised…</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained: Momentum Contrast for Unsupervised Visual Representation Learning]]></title>
            <link>https://medium.com/data-science/paper-explained-momentum-contrast-for-unsupervised-visual-representation-learning-ff2b0e08acfb?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff2b0e08acfb</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[computer-vision]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Mon, 10 Jan 2022 14:21:02 GMT</pubDate>
            <atom:updated>2022-01-10T16:15:19.610Z</atom:updated>
            <content:encoded><![CDATA[<h4>Going over the principles from the MoCo v1 &amp; v2 papers</h4><p>In this story, we will go over the MoCo papers, an unsupervised approach to pre-training computer vision models using Momentum Contrast (MoCo) that has been iteratively improved by the authors, from version one up to version three.</p><p>MoCo was first presented in the paper <a href="https://arxiv.org/pdf/1911.05722.pdf"><em>“Momentum Contrast for Unsupervised Visual Representation Learning”</em></a><em> </em>by He et al. in 2020 and further improved to MoCo v2 in <a href="https://arxiv.org/pdf/2003.04297.pdf"><em>“Improved Baselines with Momentum Contrastive Learning”</em></a><em>. </em>There is another iteration called MoCo v3 in <a href="https://arxiv.org/pdf/2104.02057.pdf">“An Empirical Study of Training Self-Supervised Vision Transformers”</a> by Chen et al. which introduces a fundamental adaptation of training process and model architecture, which we will cover in a future story.</p><p>Since this method has been continuously improved, we will first go over the initial ideas behind the paper, followed by an overview over the improvements introduced with newer version. I’ve tried to keep the article simple so that even readers with little prior knowledge can follow along. Without further ado, let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*AURmxepRI4G6WT0DirxZDw.png" /><figcaption>A simplified illustration of the key idea behind the initial MoCo paper. Source: <a href="https://arxiv.org/pdf/1911.05722.pdf">[1]</a></figcaption></figure><h3>Pre-requisite: Self-supervised &amp; unsupervised pre-training for computer vision</h3><p>Before we go deeper into the MoCo paper, it’s worth quickly re-visiting what self-supervised pre-training is all about. <strong>If you have been reading other self-supervised learning stories from me or you are familiar with self-supervised pre-training, feel free to skip this part.</strong></p><p>Traditionally, computer vision models have always been trained using <strong>supervised learning</strong>. That means humans looked at the images and created all sorts of <strong>labels</strong> for them, so that the model could learn the patterns of those labels. For example, a human annotator would assign a class label to an image or draw bounding boxes around objects in the image. But as anyone who has ever been in contact with labeling tasks knows, the effort to create a sufficient training dataset is high.</p><p>In contrast, <strong>self-supervised learning does not require any human-created labels</strong>. As the name suggest, <strong>the model learns to supervise itself</strong>. In computer vision, the most common way to model this self-supervision is to take different crops of an image or apply different augmentations to it and passing the modified inputs through the model. Even though the images contain the same visual information but do not look the same, <strong>we let the model learn that these images still contain the same visual information</strong>, i.e., the same object. <strong>This leads to the model learning a similar latent representation (an output vector) for the same objects.</strong></p><p>We can later apply transfer learning on this pre-trained model. Usually, these models are then trained on 10% of the data with labels to perform downstream tasks such as object detection and semantic segmentation.</p><h3>Using Momentum Contrast for Unsupervised Learning</h3><p>In the MoCo paper, the unsupervised learning process is framed as a dictionary look-up: <strong>Each view or image is assigned a key</strong>, just like in a dictionary. <strong>This key is generated by encoding each image</strong> using a convolutional neural network, with the output being a vector representation of the image. Now, i<strong>f a query is presented to this dictionary in the form of another image, this query image is also encoded</strong> into a vector representation and <strong>will belong to one of the keys in the dictionary, the one with the lowest distance</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WerzRQgq8gZgo3w-L5oWkg.png" /><figcaption>On the left is the query image and encoder, on the right is the queue of mini-batches of keys and the momentum encoder. Source: <a href="https://arxiv.org/pdf/1911.05722.pdf">[1]</a></figcaption></figure><p>The training process is designed as follows: A query image is selected and processed by the encoder network to compute <em>q</em>, the encoded query image. Since the goal of the model is learn to differentiate between a large number of different images, this query image encoding is not only compared to one mini-batch of encoded key images, but to multiple of them. To achieve that, MoCo forms a queue of mini-batches that are encoded by the momentum encoder network. As a new mini-batch is selected, its encodings are enqueued and the oldest encodings in the data structure are dequeued. <strong>This decouples the dictionary size, represented by the queue, from the batch size and enables a much larger dictionary to query from.</strong></p><p>If the encoding of the query image matches a key in the dictionary, these two views are deemed to be from the same image (e.g. multiple different crops).</p><p>The training object is formulated by the InfoNCE loss function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7gw975iVCkURNV48emKs1g.png" /><figcaption>The InfoNCE contrastive loss function. Source: <a href="https://arxiv.org/pdf/1911.05722.pdf">[1]</a></figcaption></figure><p>This loss function allows the model to learn a smaller distance for views from the same image and a larger distance between different images. To achieve this, the loss resembles a softmax-based classfier loss that aims to classify <em>q</em> as <em>k+</em>. The sum is computed over one positive key and <em>K</em> negative keys for query <em>q</em>.</p><p>Finally,<strong> backpropagation is performed through the encoder network as can be seen in the first illustration but not through the momentum encoder.</strong></p><p>The authors try to achieve a relatively consistent encoding for each image with the momentum encoder. Since keeping the weights frozen would not reflect the progress of learning by the model, <strong>they propose using a momentum update</strong> instead of copying the encoder’s weights to achieve consistent momentum encoder results. To achieve this, to set the momentum encoder network to be updated by a <strong>momentum-based moving average of the query encoder</strong>. This update is performed for every training iteration.</p><h3>Further improvements in MoCo v2</h3><p>In the second version of the model, <strong>MoCo v2</strong>, presented in their paper <a href="https://arxiv.org/pdf/2003.04297.pdf"><em>“Improved Baselines with Momentum Contrastive Learning”</em></a><em>,</em> the authors transfer some of the contributions from the <a href="https://towardsdatascience.com/paper-explained-a-simple-framework-for-contrastive-learning-of-visual-representations-6a2a63bfa703">SimCLR paper</a> to their model. Initially, for training a linear classifier after pre-training MoCo, they added a single linear layer to the model. In MoCo v2, this layer has been replaced by an MLP projection head, leading to better classification performance. Another significant improvement has presented with the introduction of stronger data augmentations, similar to those in SimCLR. They extend the v1 augmentations by adding blur and stronger color distortion.</p><p>The latest version, <strong>MoCo v3</strong>, which was introduced in the <a href="https://arxiv.org/pdf/2104.02057.pdf">“An Empirical Study of Training Self-Supervised Vision Transformers”</a> paper, adapts the model to a different training process. Since these changes are more significant than just a simple extension, we will cover this paper in a future story.</p><h3>Wrapping it up</h3><p>In this article, you have learned about MoCo, a paper that is one of the most popular self-supervised frameworks which paved the way for more promising papers in this space.</p><p><em>Usually in my paper stories, I present the results and performance of the method towards the end. This time, we will skip this part since both methods are not state-of-the-art anymore, but MoCo v3 is. Nevertheless, I found it of great importance the learn the principles behind MoCo as a foundation for the state-of-the-art MoCo v3 paper.</em></p><p>While I hope this story gave you a good first insight into MoCo, there is still so much more to discover. Therefore, I would encourage you to read the papers yourself, even if you are new to the field. You’ll have to start somewhere ;)</p><p>If you are interested in more details on the method presented in the paper, feel free to drop me a message on Twitter, my account is linked on my Medium profile.</p><p>I hope you’ve enjoyed this paper explanation. If you have any comments on the article or if you see any errors, feel free to leave a comment.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] He, Kaiming, et al. “Momentum contrast for unsupervised visual representation learning.” <em>Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition</em>. 2020. <a href="https://arxiv.org/pdf/1911.05722.pdf">https://arxiv.org/pdf/1911.05722.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff2b0e08acfb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/paper-explained-momentum-contrast-for-unsupervised-visual-representation-learning-ff2b0e08acfb">Paper explained: Momentum Contrast for Unsupervised Visual Representation Learning</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Supervised To Unsupervised Learning: A Paradigm Shift In Computer Vision]]></title>
            <link>https://medium.com/data-science/from-supervised-to-unsupervised-learning-a-paradigm-shift-in-computer-vision-ae19ada1064d?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae19ada1064d</guid>
            <category><![CDATA[self-supervised-learning]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[unsupervised-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[research]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Sat, 01 Jan 2022 17:15:24 GMT</pubDate>
            <atom:updated>2022-01-01T17:28:28.838Z</atom:updated>
            <content:encoded><![CDATA[<h4>Slowly removing the injection of human knowledge from the training process</h4><p>Since the inception of modern computer vision methods, success in the application of these techniques could only be seen in the supervised domain. In order to make a model useful for performing tasks such as image recognition, object detection or semantic segmentation, human supervision used to be necessary. In a major shift, the last few years of computer vision research have change the focus of the field: Away from the guaranteed success with human supervision onto new frontiers: Self-supervised and unsupervised learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*cWME7QKVDOzlPaGRRlXGtQ.gif" /><figcaption>An animation of the clustering of different classes in an unsupervised way. Source: <a href="https://ai.facebook.com/blog/dino-paws-computer-vision-with-self-supervised-transformers-and-10x-more-efficient-training/">[1]</a></figcaption></figure><p>Let’s go on a journey towards a new era that has already begun.</p><h3>The success of supervised learning</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K_0xzsEYZjBFMsNyNh_Zlg.png" /><figcaption>An illustration of the original AlexNet architecture. Source: <a href="https://proceedings.neurips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf">[2]</a></figcaption></figure><p>AlexNet marked the first breakthrough in the application of neural networks for image tasks, more specifically the ImageNet challenge. From there, it was game on and the computer vision research community stormed towards perfecting supervised techniques for many kinds of computer vision tasks.</p><p>For image classification, many variations of models have emerged since the original AlexNet paper. ResNet has unarguably become the classic among convolutional neural networks. Efficient architectures such as the EfficientNet have emerged. Even networks optimized for mobile devices such as the MobileNet architecture. More recently, Vision Transformers have gained increasing attention (unintended joke) and have shown to outperform convolutional neural networks under the right settings (lots of data and compute). Originally invented for language tasks, their application for computer vision has been a huge success. Another interesting approach has been to design network design spaces where a quantized linear function defines the network architecture called RegNet.</p><p>The next tasks that was tackled successfully with supervised learning were object detection and semantic segmentation. R-CNNs have made the first big splash in the first domain, followed by many advances in computational efficiency and accuracy. Notable approaches are the Fast, Faster and Mask R-CNN but also the YOLO algorithms and single-shot detectors such as the SSD MobileNet. A milestone in the domain of semantic segmentation was the U-Net architecture.</p><p>Also not to forget are the benchmark datasets that made the supervised techniques more comparable. ImageNet set the standard for image classification and MS COCO is still important for object detection and segmentation tasks.</p><p>All of these techniques have one thing in common: They rely on distilled human knowledge and skill in the form of labeled data to perform well. In fact, they are built around this resource and depend on it.</p><p>In some way, all these techniques employ artificial neural networks that model the biological neural network in humans. But still, these models learn very different to perceive from the way humans learn this. Why only mimic the human brain in its biological form and not the cognitive process behind learning the recognize and classify?</p><p>This is where the next evolution comes in: self-supervised learning.</p><h3>Introducing self-supervision into the process</h3><p>Think about how you have learned to see. How you learn to recognize an apple. When you were younger, you have seen many apple, but not all of them had a sign on them that said “This is an apple” and no one told you it was an apple every time you saw one. The way you learned was by similarity: You have seen this object time and time again, multiple times per week, maybe even per day. You recognized: Hey… this is the same thing!</p><p>Then, one day, someone taught you this is an apple. All of a sudden, this abstract object, this visual representation, it now became know to you as “apple”. This is a similar process used in self-supervised learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFILaYrPribmV3rP-lwA2w.png" /><figcaption>An illustration of the SimCLR training process. Source: <a href="https://arxiv.org/pdf/2002.05709.pdf">[3]</a></figcaption></figure><p>The most state-of-the-art techniques such as <a href="https://towardsdatascience.com/paper-explained-a-simple-framework-for-contrastive-learning-of-visual-representations-6a2a63bfa703">SimCLR</a> or <a href="https://towardsdatascience.com/paper-explained-unsupervised-learning-of-visual-features-by-contrasting-cluster-assignments-f9e87db3cb9b">SwAV</a> copy this process. For pre-training, all labels are discarded, the models train without the use of human knowledge. The models are shown two versions of the same image, may it be cropped or color distorted or rotated, and it starts to learn that despite their differing visual representation, these objects are the same “thing”. In fact, this is visible in their similar latent vector representations (remember this for later). So, the model learn to produce a consistent vector for each class of object.</p><p>Next is the “teaching” step: The pre-trained model is shown some images with labels this time. And it learns much more quickly and effectively to classify different kinds of objects.</p><p>So much of the human knowledge has been removed from the training process, but not all of it. But the next step is just around the corner.</p><h3>Towards unsupervised learning</h3><p>To make a model fully unsupervised, it has to be trained without human supervision (labels) and still be able to achieve the tasks it is expected to do, such as classifying images.</p><p>Remember that the self-supervised models already take a step in this direction: Before they are shown any labels, they are already able to compute consistent vector representations for different objects. This is key to removing all human supervision.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OpMOF2vd3dWikyhUNnzeEw.png" /><figcaption>An illustration of the clustering of different classes in an unsupervised way. Source: <a href="https://ai.facebook.com/blog/dino-paws-computer-vision-with-self-supervised-transformers-and-10x-more-efficient-training/">[1]</a></figcaption></figure><p>What this vector generally represents is an images reduced in its dimensionality. In fact, autoencoders can be trained to recreate the image pixels. Because of its reduced dimension, we can use a technique long ignored (for good reasons) in computer vision: A k-nearest-neighbors classifer. If our vector representations are that good so that only the same objects form a cluster and different objects are clustered far away, we can feed the model a new, unknown image and the model will assign it to the cluster of the correct class. The model will not be able to tell you what the class name is, but what group of images it belongs to. If you assign a class name to this group, all objects in the group can be classified. After all, class names are artificial creations by humans (someone defined that this thing is called apple) and are only assigned meaning by humans.</p><p>Since all labels are removed from the training process and the results in papers like <a href="https://towardsdatascience.com/paper-explained-dino-emerging-properties-in-self-supervised-vision-transformers-f9386df266f1">DINO</a> are quite promising, this is the closest we have come to removing all supervision from the training process of computer vision models.</p><p>But there is still more to come, more room for improvement.</p><h3>Wrapping it up</h3><p>If you have been reading up to this point, I highly appreciate you taking your time. I have purposely not included any images in this story since they divert your attention away from the meaning of this text. I mean, we all want be a good transformer, right? (This time it was intended)</p><p>I sincerely thank you for reading this article. If you are interested in self-supervised learning, have a look at other stories of mine where I try to explain state-of-the-art papers in the space to anyone interestd. <strong>And if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] Meta AI Research Blog Post. <a href="https://ai.facebook.com/blog/dino-paws-computer-vision-with-self-supervised-transformers-and-10x-more-efficient-training/">https://ai.facebook.com/blog/dino-paws-computer-vision-with-self-supervised-transformers-and-10x-more-efficient-training/</a></p><p>[2] Krizhevsky, Alex, Ilya Sutskever, and Geoffrey E. Hinton. “Imagenet classification with deep convolutional neural networks.” <em>Advances in neural information processing systems</em>25 (2012): 1097–1105. <a href="https://proceedings.neurips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf">https://proceedings.neurips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf</a></p><p>[3] Chen, Ting, et al. “A simple framework for contrastive learning of visual representations.” <em>International conference on machine learning</em>. PMLR, 2020. <a href="https://arxiv.org/pdf/2002.05709.pdf">https://arxiv.org/pdf/2002.05709.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae19ada1064d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/from-supervised-to-unsupervised-learning-a-paradigm-shift-in-computer-vision-ae19ada1064d">From Supervised To Unsupervised Learning: A Paradigm Shift In Computer Vision</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained: Masked Autoencoders Are Scalable Vision Learners]]></title>
            <link>https://medium.com/data-science/paper-explained-masked-autoencoders-are-scalable-vision-learners-9dea5c5c91f0?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/9dea5c5c91f0</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Wed, 29 Dec 2021 12:42:05 GMT</pubDate>
            <atom:updated>2021-12-29T14:23:35.141Z</atom:updated>
            <content:encoded><![CDATA[<h4>How reconstructing masked parts of an image can be beneficial</h4><p>Autoencoders have a history of success for Natural Language Processing tasks. The BERT model started masking word in different parts of a sentence and tried to reconstruct the full sentence by predicting the words to be filled into the blanks. Recent work has aimed to transfer this idea to the computer vision domain.</p><p>In this story, we will have a look at the recently published paper <a href="https://arxiv.org/pdf/2111.06377.pdf"><em>“Masked Autoencoders Are Scalable Vision Learners”</em></a> by He et al. from 2021. Kaiming He is one of the most influential researchers in the field of computer visions, having produced breakthroughs such as the ResNet, Faster R-CNN and Mask R-CNN along with other researchers at Meta AI Research. In their latest paper, they presented a novel approach for using autoencoders for self-supervised pre-training of computer vision models, specifically vision transformers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8zPV1sSDmEPbwHTDh5Rzw.png" /><figcaption>A high-level visualization of the masked autoencoder training pipeline. Source: <a href="https://arxiv.org/pdf/2111.06377.pdf">[1]</a></figcaption></figure><p>Before we dive deeper into the method presented by them, it is important that we quickly revisit self-supervised pre-training to set the context right. If you are already familiar with self-supervised pre-training, feel free to skip this part. I’ve tried to keep the article simple so that even readers with little prior knowledge can follow along. Without further ado, let’s dive in!</p><h3>Pre-requisites: Self-supervised pre-training for computer vision</h3><p>Before we go deeper into the paper, it’s worth quickly re-visiting what self-supervised pre-training is all about. If you are familiar with self-supervised pre-training, feel free to skip this part.</p><p>Traditionally, computer vision models have always been trained using <strong>supervised learning</strong>. That means humans looked at the images and created all sorts of <strong>labels</strong> for them, so that the model could learn the patterns of those labels. For example, a human annotator would assign a class label to an image or draw bounding boxes around objects in the image. But as anyone who has ever been in contact with labeling tasks knows, the effort to create a sufficient training dataset is high.</p><p>In contrast, <strong>self-supervised learning does not require any human-created labels</strong>. As the name suggest, <strong>the model learns to supervise itself</strong>. In computer vision, the most common way to model this self-supervision is to take different crops of an image or apply different augmentations to it and passing the modified inputs through the model. Even though the images contain the same visual information but do not look the same, <strong>we let the model learn that these images still contain the same visual information</strong>, i.e., the same object. <strong>This leads to the model learning a similar latent representation (an output vector) for the same objects.</strong></p><p>We can later apply transfer learning on this pre-trained model. Usually, these models are then trained on 10% of the data with labels to perform downstream tasks such as object detection and semantic segmentation.</p><h3>Use masking to make autoencoders understand the visual world</h3><p>A key novelty in this paper is already included in the title: The masking of an image. Before an image is fed into the encoder transformer, a certain set of masks is applied to it. The idea here is to remove pixels from the image and therefore feed the model an incomplete picture. The model’s task is to now learn what the full, original image looked like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*0Vd0bkvc5ta0yQFDOxz19w.png" /><figcaption>On the left, the masked image can be seen. On the right, the original image is displayed. And the center column shows the image reconstructed by the autoencoder. Source: <a href="https://arxiv.org/pdf/2111.06377.pdf">[1]</a></figcaption></figure><p>The authors found a very high masking ratio to be most effective. In these examples, they have covered 75% of the image with masks. This brings along two benefits:</p><ol><li>Training the model is 3x faster since it has to process much fewer image patches</li><li>The accuracy increases since the model has to learn the visual world from the images thoroughly</li></ol><p>The masking is always applied randomly, so multiple versions of the same image can be used as input.</p><p>Now that the images have been pre-processed, let’s have a look at the model architecture. In their paper, He et al. decide on using an asymetric encoder design. That means their encoder can be much deeper and while they opt for a rather lightweight decoder.</p><p>The encoder divides the image into patches that are assigned positional encodings (i.e. the squares in the images above) and only processes the non-masked parts of the image. The output of the encoder is a latent vector representation of the input image patches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*GczhOMZJz0DUHjDvwkpQNw.png" /><figcaption>A visualization of the encoder receiving the non-masked image patches and outputting the latent vector representation. Source: <a href="https://arxiv.org/pdf/2111.06377.pdf">[1]</a></figcaption></figure><p>Following this, the mask tokens are introduced since the next step is for the decoder to reconstruct the initial image. Each mask token is a shared, learned vector that indicates the presence of a missing patch. Positional encodings are again applied to communicate to the decoder where the individual patches are located in the original image.</p><p>The decoder receives the latent representation along with the mask tokens as input and outputs the pixel values for each of the patches, including the masks. From this information, the original image can be pieced together to form the predicted version of the full image from the masked image that served as the input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Z6RqFr6FlGrt06upLgAM8g.png" /><figcaption>The decoding process from the latent representation of the masked input image to the reconstructed target image. Source: <a href="https://arxiv.org/pdf/2111.06377.pdf">[1]</a></figcaption></figure><p>Adding the mask tokens after the computation of the latent vector in blue is an important design decision. It reduces the computational cost of the encoder arriving at the vector output since it has to process less patches. This makes the model faster during training.</p><p>Once the target image has been reconstructed, it’s difference to the original input image is measured and used as the loss.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*Asf08MKwx0suN9luT7cFKA.png" /><figcaption>A comparison of a reconstructed image with the original image. Source: <a href="https://arxiv.org/pdf/2111.06377.pdf">[1]</a></figcaption></figure><p>After the model has been trained, the decoder is discarded and only the encoder, i.e., the vision transformer, is kept for further use. It is now capable of computing latent representations of images for further processing.</p><p>Now that we have gone over the methodology introduced by the paper, let’s look at some results.</p><h3>Results</h3><p>Since the masked autoencoder makes use of transformers, it makes sense for the authors to compare its performance to other transformer-based self-supervised methods. An their improvement show in the first comparison:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*AnmBCsfsP4VL82zEELKgpg.png" /><figcaption>Pre-training with fine-tuning results on ImageNet-1K. Source: <a href="https://arxiv.org/pdf/2111.06377.pdf">[1]</a></figcaption></figure><p>In their comparisons with other methods, when pre-training the model on ImageNet-1K and then fine-tuning it end-to-end, the MAE (masked autoencoder) shows superiors performance compared to other approaches such as <a href="https://towardsdatascience.com/paper-explained-dino-emerging-properties-in-self-supervised-vision-transformers-f9386df266f1">DINO</a>, MoCov3 or BEiT. The improvements stay steady even with increasing model size, performance is the best with a ViT-H (Vision Transformer Huge). MAE achieves an incredible accuracy of 87.8.</p><p>This performance holds true for transfer learning on downstream tasks as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*41zLgru2DgtXdxgHqpPQ3w.png" /><figcaption>Transfer learning applied to differnet transformer-based pre-training methods. These results are for the COCO detection and segmentation dataset. Source: <a href="https://arxiv.org/pdf/2111.06377.pdf">[1]</a></figcaption></figure><p>When using the pre-trained transformer as a backbone for a Mask R-CNN that trained on the MS COCO detection and segmentation dataset, the MAE again outperforms all other transformer-based methods. It achieves an incredible 53.3 AP (average precision) for the boxes. The Mask R-CNN also outputs a segmentation mask of the object. For this evaluation, the MAE again tops all other methods with up to 47.2 AP for the mask. The method even outperforms fully-supervised training of the Mask R-CNN, again showing the benefit of self-supervised pre-training.</p><h3>Wrapping it up</h3><p>In this article, you have learned about masked autoencoders (MAE), a paper that leverages transformers and autoencoders for self-supervised pre-training and adds another simple but effective concept to the self-supervised pre-training toolbox. It even outperforms fully-supervised approaches on some tasks. While I hope this story gave you a good first insight into the paper, there is still so much more to discover. Therefore, I would encourage you to read the paper yourself, even if you are new to the field. You’ll have to start somewhere ;)</p><p>If you are interested in more details on the method presented in the paper, feel free to drop me a message on Twitter, my account is linked on my Medium profile.</p><p>I hope you’ve enjoyed this paper explanation. If you have any comments on the article or if you see any errors, feel free to leave a comment.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] He, Kaiming, et al. “Masked autoencoders are scalable vision learners.” <em>arXiv preprint arXiv:2111.06377</em> (2021). <a href="https://arxiv.org/pdf/2111.06377.pdf">https://arxiv.org/pdf/2111.06377.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dea5c5c91f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/paper-explained-masked-autoencoders-are-scalable-vision-learners-9dea5c5c91f0">Paper explained: Masked Autoencoders Are Scalable Vision Learners</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Simple Ways To Measure Your Model’s Uncertainty]]></title>
            <link>https://medium.com/data-science/2-easy-ways-to-measure-your-image-classification-models-uncertainty-1c489fefaec8?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c489fefaec8</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[research]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Tue, 28 Dec 2021 15:23:46 GMT</pubDate>
            <atom:updated>2021-12-28T18:09:05.921Z</atom:updated>
            <content:encoded><![CDATA[<h4>The key to better understanding your model’s predictions</h4><p>In this article, we will go over 2 methods that allow you to obtain your model’s uncertainty: <strong>Monte Carlo Dropout and Deep Ensembles</strong>. They are applicable for a wide variety of tasks, but in this article, we will show an example for <strong>image classification</strong>. Both of them are relatively easy to understand and implement, both can easy be applied to any existing convolutional neural network architecture (e.g. ResNet, VGG, <a href="https://medium.com/towards-data-science/regnet-the-most-flexible-network-architecture-for-computer-vision-2fd757f9c5cd">RegNet</a>, etc.). To help you with your fast and easy application of these techniques, I will provide the complementary <strong>code for these techniques written in PyTorch</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FYjnwwX-SoNINT7oL8OJUg.png" /><figcaption>Given an image of two cups, how certain is your model of its prediction? Image by Author.</figcaption></figure><p>Before we start, let’s go over what measuring model uncertainty means and how it can be useful for your machine learning project.</p><h3>What is model uncertainty?</h3><p>Just like humans, a machine learning model can display a degree of confidence in its predictions. In general, when talking about model uncertainty, the distinction is made between <strong>epistemic and aleatoric uncertainty</strong>.</p><p><strong>Epistemic uncertainty</strong> is the <strong>uncertainty represented in the model parameters</strong> and captures the ignorance about the models most suitable to explain our data. T<strong>his type of uncertainty can be reduced with additional training data</strong> and therefore carries the alternative name <strong>“reducible uncertainty”</strong>. A model will broadcast high epistemic uncertainty for inputs far away from the training data and low ep- istemic uncertainty for data points near the training data.</p><p><strong>Aleatoric uncertainty</strong> captures <strong>noise inherent to the environment</strong> i.e., the observation. Compared to epistemic uncertainty, this type cannot be reduced with more data but with more precise sensor output.</p><p>The third type is called <strong>predictive uncertainty</strong> which is the conveyed uncertainty in the model’s output. <strong>Predictive uncertainty can combine epistemic and aleatoric uncertainty</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amdgG1leSZZbp7XoORWgFA.png" /><figcaption>An example of a softmax output for a classifier of 4 classes. This value is not suitable for uncertainty estimation. Image by Author.</figcaption></figure><p>If you have already trained simple neural networks yourself, the most intuitive thing to think about is the <strong>softmax output</strong> of your model, i.e., the percentage values you often see displayed as a result of the model’s prediction.</p><p>But using the <strong>softmax output </strong>as a measure of model uncertainty can be misleading and is not very useful. This is because all that the softmax function does is compute a sort of “relation” between the different activation values of the model. So, your model can have<strong> low activation values in all of the neurons of its output layer</strong> and <strong>still arrive at a high softmax value</strong>. This is not what we are aiming for. But thankfully, there are multiple more effective techniques to estimate a model’s uncertainty, such as Monte Carlo Dropout and Deep Ensembles.</p><h3>Why is model uncertainty useful?</h3><p>There are two major aspects that make estimating your model’s uncertainty useful:</p><p>The first is <strong>transparency</strong>. Imagine you are building a machine learning model that is applied in medical image analysis. So, the doctors using your tool heavily depend on its capabilities to make a correct diagnosis. If your model now makes a prediction it is actually highly uncertain about but does communicate this information to the doctor, the consequences for the treatment of the patient can fatal. Therefore, having an estimation of the model’s uncertainty can help the doctor massively when judging the model’s prediction.</p><p>The second is showing <strong>room for improvement</strong>. No machine learning model is perfect. Therefore, knowing the uncertainties and weaknesses of your model can actually inform you what improvements to make to your model. There is actually an entire discipline dedicated to that called <strong>Active Learning</strong>. Let’s say you have trained your ConvNet with 1000 images and 10 classes. But you still have 9000 more images that are not labeled yet. If you now use your trained model to predict which images it is most uncertain about, you can only label those and re-train the model. It has been shown that this type of uncertainty sampling is much more effective for model improvement compared to random sampling of these images.</p><p>Alright, enough of the prerequisites, let’s get to the two techniques.</p><h3>Technique 1: Monte Carlo Dropout</h3><p>Monte Carlo Dropout, or MC Dropout for short, is a technique that uses dropout layers in your model to create variation in the model’s outputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EKI5ufCZNNZvsQKx90hLFA.png" /><figcaption>A simplified visualization of dropout applied to a neural network. Image by Author.</figcaption></figure><p><strong>Dropout layers </strong>are usually used as a r<strong>egularization technique during training</strong>. Some neurons are <strong>randomly dropped out at a certain probability </strong>during a forward pass through the network. This has been shown the make the model more robust against overfitting. Usually, these dropout layers are disabled after training as to not interfere with the forward pass on a new image. So, to use this technique, make sure to have at least one dropout layer implemented in your model. This can look something like this.</p><pre>import torch<br>import torch.nn as nn<br>import torch.nn.functional as F<br><br><br>class Model(nn.Module):<br>    def __init__(self):<br>        super().__init__()<br>        self.conv1 = nn.Conv2d(3, 6, 5)<br>        self.pool = nn.MaxPool2d(2, 2)<br>        self.conv2 = nn.Conv2d(6, 16, 5)<br>        self.fc1 = nn.Linear(16 * 5 * 5, 120)<br>        self.fc2 = nn.Linear(120, 84)<br>        self.fc3 = nn.Linear(84, 10)<br>        <br>        # Dropout layer defined with 0.25 dropout probability<br>        self.dropout = nn.Dropout(0.25)<br><br>    def forward(self, x):<br>        x = self.pool(F.relu(self.conv1(x)))<br>        x = self.pool(F.relu(self.conv2(x)))<br>        x = torch.flatten(x, 1)<br>        x = F.relu(self.fc1(x))<br>        x = F.relu(self.fc2(x))<br>        <br>        # Dropout applied<br>        x = self.dropout(x)<br>        <br>        x = self.fc3(x)<br><br>        return x<br><br><br>model = Model()</pre><p>But for MC Dropout, the dropout layers are still activated, meaning neurons can still randomly drop out. This results in a variation of the softmax results of the model. To turn dropout during the inference or testing, use the following code:</p><pre>for module in model.modules():<br>    if module.__class__.__name__.startswith(&#39;Dropout&#39;):<br>        module.train()</pre><p>Now dropout is still applied since we have put all dropout layers into training mode!</p><p>Let’s say we wanted to obtain the <strong>model’s uncertainty on one image </strong>now. To do this, <strong>we will not only predict on the image once, but multiple times </strong>and<strong> analyze the different outputs generated by the multiple forward passes</strong>. I would recommend to <strong>let the model predict on one image 3 or 5 times</strong>. I will go over how to combine the 3 or 5 outputs at the end of this article.</p><h3>Technique 2: Deep Ensembles</h3><p>The second technique to estimate model uncertainty takes advantage of creating an ensemble of models. <strong>Instead of using one model and predicting 5 times with it, the idea is to use multiple models of the same type, randomly initialize their weights and train them on the same data.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UqepZov8tCAZnRtGYou4gQ.png" /><figcaption>A visualization of an ensemble of multiple neural networks, similar to the deep ensembles approach. Image by Author.</figcaption></figure><p>This will also create a variation in the model parameters. If the model is trained robustly and is certain about an image, it will output similar values for each forward pass. To initialize the models, it is best to save them as a list of of models:</p><pre># How many models do we want to have in our ensemble<br>n_ensemble = 5<br><br># Initialize the ensemble<br>ensemble = [Model() for e_model in range(n_ensemble)]</pre><p>Following the initialization, all models are trained on the same training data. <strong>Just like for MC Dropout, a number of 3 or 5 models is a good choice.</strong> To obtain the model’s uncertainty on a given image, it is passed through each of the models in the ensemble and its predictions are combined for analysis.</p><h3>Combining the model outputs from multiple forward passes</h3><p>Assume we have defined 5 forward passes for MC Dropout and an ensemble size of 5 for the deep ensemble. <strong>We now expect some variation between these outputs that exhibits the model’s uncertainty.</strong> To arrive at a final value for uncertainty, these outputs have to be stacked first. This code is an example of how this can be achieved for MC Dropout:</p><pre>import numpy as np<br><br>fwd_passes = 5<br>predictions = []<br><br>for fwd_pass in range(fwd_passes):<br>    output = model(image)<br><br>    np_output = output.detach().cpu().numpy()<br><br>    if fwd_pass == 0:<br>        predictions = np_output<br>    else:<br>        predictions = np.vstack((predictions, np_output))</pre><p>First, we define the number of forward passes to perform as well as an empty list to save all predictions to. Then we perform 5 forward passes. The first output serves as the initialization of the numpy array of results, all other outputs are stacked on top.</p><p>This is the code for deep ensembles with the same underlying principle:</p><pre>import numpy as np<br><br>predictions = []<br><br>for i_model, model in enumerate(ensemble):<br>    output = model(image)<br><br>    np_output = output.detach().cpu().numpy()<br><br>    if i_model == 0:<br>        predictions = np_output<br>    else:<br>        predictions = np.vstack((predictions, np_output))</pre><p>Now that we have combined all outputs, let’s look at how to calculate the model’s uncertainty from these outputs.</p><h3>Obtaining model uncertainty</h3><p>To keep it simple, we will use the predictive entropy to estimate the uncertainty of the model on a given image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*znjdupGX9HtjxqE-F3drrg.png" /><figcaption>The mathematical formulation of the predictive entropy given y (label), x (input image) Dtrain (training data), c (class), p (probability). Source: <a href="http://mlg.eng.cam.ac.uk/yarin/thesis/thesis.pdf">[1]</a></figcaption></figure><p>In general, t<strong>he predictive uncertainty tells you how “surprised” your model is to see this image</strong>. If the value is low, the model is certain about it’s prediction. If the result is high, the model does not know that is in the image.</p><p>Calculating the predictive uncertainty can be achieved with this piece of code that received the <em>predictions </em>array from earlier as input.</p><pre>import sys<br>import numpy as np<br><br>def predictive_entropy(predictions):<br>    epsilon = sys.float_info.min<br>    predictive_entropy = -np.sum( np.mean(predictions, axis=0) * np.log(np.mean(predictions, axis=0) + epsilon),<br>            axis=-1)<br><br>    return predictive_entropy</pre><p>The epsilon in the equation prevents a division by 0, which is mathematically not defined.</p><p>Alright! Now, you have your uncertainty value for one image. <strong>As previously mentioned, the higher the value, the more uncertain your model is.</strong></p><h3>Wrapping it up</h3><p>In this article, you have learned to estimate your model’s uncertainty. This technique can also be applied to object detection with a couple of tweaks and it is very powerful. While I hope this story gave you a good first insight into the topic, there is still so much more to discover.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] Uncertainty in Deep Learning, Yarin Gal. <a href="http://mlg.eng.cam.ac.uk/yarin/thesis/thesis.pdf">http://mlg.eng.cam.ac.uk/yarin/thesis/thesis.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c489fefaec8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/2-easy-ways-to-measure-your-image-classification-models-uncertainty-1c489fefaec8">Two Simple Ways To Measure Your Model’s Uncertainty</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained: Semi-Supervised Learning of Visual Features by Non-Parametrically Predicting View…]]></title>
            <link>https://medium.com/data-science/paper-explained-semi-supervised-learning-of-visual-features-by-non-parametrically-predicting-view-1fcbf91517a0?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fcbf91517a0</guid>
            <category><![CDATA[research]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Mon, 20 Dec 2021 13:02:05 GMT</pubDate>
            <atom:updated>2022-06-02T08:47:48.468Z</atom:updated>
            <content:encoded><![CDATA[<h3>Paper explained: Semi-Supervised Learning of Visual Features by Non-Parametrically Predicting View Assignments with Support Samples</h3><h4>Taking advantage of labeled support samples for semi-supervised learning</h4><p>In this story, we will have a closer look at PAWS (<strong>p</strong>redicting view <strong>a</strong>ssignments <strong>w</strong>ith <strong>s</strong>upport labels), a novel method for applying semi-supervised learning to computer vision problems.</p><p>This method has been presented as part of the recent paper <a href="https://arxiv.org/pdf/2104.13963.pdf"><em>“Semi-Supervised Learning of Visual Features by Non-Parametrically Predicting View Assignments with Support Samples”</em></a> by Assran et al. at ICCV 2021. In contrast to some of the other papers I have written about, this method allows the limited use of labeled data, only to project this information on a larger pool of unlabeled data to learn from. Therefore, <strong>the labeled data becomes even more valuable than it would be if the model were to be trained fully supervised</strong>. As always, I’ve tried to keep the article simple so that even readers with little prior knowledge can follow along. Without further ado, let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fFPTomfx0V5TL8n_wD66hg.png" /><figcaption>A simplified visualization of the PAWS training process. Most notably, labels are introduced to the training process along with the support samples. Source: <a href="https://github.com/facebookresearch/suncet">[1]</a></figcaption></figure><h3>Pre-requisite: Self-Supervised vs. Semi-Supervised Learning</h3><p>An important distinction to make is the difference between self-supervised and semi-supervised learning.</p><p>When training a model in a self-supervised way, the supervision does not come from labeled data. Rather <strong>the model, as the name suggests, supervises itself</strong>. What might that supervision look like? Simply put, the model can be fed the same image with different data augmentations applied and the goal would be to learn that the image is still the same. In that way, the learning process is guided.</p><p>In contrast, semi-supervised learning does rely on labeled data, but very few of it. When using a traditional supervised training approach, all data has to be labeled. <strong>Semi-supervised models only use a fraction of the labeled data and distill the labels to reason and learn about the unlabeled training data</strong>. This become more clear throughout this article.</p><h3>Learning from few labeled images</h3><p>In the past, supervised computer vision models have always been evaluated on the ImageNet data. To perform the evaluation, the models were trained on the dataset using only labeled images. PAWS only has 1% or 10% of the labels available for training and still achieves incredible performance. Let’s have a look why!</p><p>To start with, each image is randomly augmented to form 2 views: An anchor view and a positive view. While the content of the image is still the same, e.g. it contains a dog, <strong>the augmentations have now distorted the visual representation of it, i.e., they look different</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*rJkAPO8rNDsrnmAvDirxiw.png" /><figcaption>An example of a data augmentation. On the right, the original image, on the left, the augmented image. Source: <a href="https://arxiv.org/pdf/2002.05709.pdf">[2]</a></figcaption></figure><p>These two views of the same image are now encoded using a convolutional neural network, in this case a ResNet-50. This network takes each image as an input and outputs a vector representation of it.<strong> In self-supervised learning, we would now formulate a similarity loss or something similar between the two views of the same image</strong>. But <strong>in semi-supervised learning</strong>, before any loss function is formulated to learn from these outputs, <strong>we can benefit from the labeled images we have available</strong>.</p><p>The labeled images are called support samples in the paper. These labeled support samples are also encoded, using the same ResNet-50 to form a vector representation for each of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sd-qEWdGcZm-dU-reaAS7w.png" /><figcaption>An illustration of the encoder forming vector representations of the input images. Source: <a href="https://arxiv.org/pdf/2104.13963.pdf">[3]</a></figcaption></figure><p>Now that we have the vector representations with their labels available, we can use those to measure their similarity to the anchor and positive image encodings. This is achieved by using a so-called <strong>soft nearest-neighbor strategy</strong>. This means the <strong>anchor and positive view are classified according to their similarity to one of the support samples</strong>, and they are assigned a <strong>soft pseudo-label</strong>, i.e., the label of the support sample with the minimal distance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pcmlq8QFo-vRnfyhnZKBDw.png" /><figcaption>The full training process visualized. The arrows just before the bar charts represent the soft nearest neighbor classifier. Source: <a href="https://arxiv.org/pdf/2104.13963.pdf">[3]</a></figcaption></figure><p>Now that the soft pseudo-labels have been generated for the positive and anchor view, the cross entropy is calculated between them as a formulation of the loss term.</p><p>Note that, in order to prevent the learning from collapse, <strong>temperature parameters are introduced to the nearest neighbor classifier</strong>, but also to the target prediction displayed in the bottom-right corner of the illustration. The temperature parameter act as a sharpening tool in this case. Simply put, <strong>in the output distribution, high values are changed to be even higher and low values are changed to be even lower</strong>, increasing the contrast between them. This makes for a learning target closer to a one-hot encoding (the label is encoded into an array of zeros and a one).</p><p>With that, we will conclude our short overview of the techniques behind the paper. Now, let’s look at some results!</p><h3>Results</h3><p>As previously discussed, compared to self-supervised learning, semi-supervised learning can make use of information in the form of labels to learn to understand the visual world around it. As part of the evaluations, 1% or 10% of ImageNet training data was labeled for PAWS during pre-training.<strong> All methods were trained without supervision and then fine-tuned using 10% of the labeled ImageNet data</strong>. This makes the first advantage of PAWS rather intuitive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T5SwUtQK7QurR-ODE37NaQ.png" /><figcaption>PAWS compared to other pre-training techniques for Top 1 ImageNet classification. Source: <a href="https://arxiv.org/pdf/2104.13963.pdf">[3]</a></figcaption></figure><p>The first chart shows that <strong>PAWS performs much better on this classification benchmark with fewer training since its training data is much more information-rich</strong>. Therefore, using labels during training replaces the need for long training times such as SwAV or SimCLRv2 are requiring. This makes sense since SwAV, a self-supervised method, has to figure out a good model of the visual world without any human help, whereas PAWS, in this case, uses 10% of data with labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*-IOCtYE--0DZCUzjXbshlg.png" /><figcaption>A table comparing PAWS’ performance to other pre-training techniques. All model are using a ResNet-50 and were fine-tuned on other 1 or 10% of the labeled, except for PAWS-NN, which uses nearest neighbor classification on the learned embeddings. Source: <a href="https://arxiv.org/pdf/2104.13963.pdf">[3]</a></figcaption></figure><p><strong>The performance advantage of PAWS hold true when comparing it to other pre-training methods, also state-of-the-art self-supervised pre-training</strong>. With fewer training epochs, PAWS is able outperform all of them by either using 1% or 10% of the labeled ImageNet data as support samples. Even more impressive are the results seen under PAWS-NN. For this, no fine-tuning of PAWS was done and all images were classified based on a nearest neighbor classification of their raw output embeddings. This is remarkable and shows the true potential of semi-supervised training.</p><p>This shows that <strong>distilled human knowledge in the form of labels, when incorporated correctly, can be extremely powerful</strong>. As shown by the lower training times compared to self-supervised learning, by letting the human assist the learning process, information can be apprehended much more efficiently by the artificial neural network. In some sense, it is two neural networks working together. One biological, one artificial.</p><h3>Wrapping it up</h3><p>In this article, you have learned about PAWS, a paper using semi-supervised learning to profit from few labeled images and transfer that knowledge onto all other unlabeled images. This has been shown the exhibit desirable properties such as lower pre-training time and great performance. While I hope this story gave you a good first insight into the paper, there is still so much more to discover. Therefore, I would encourage you to read the paper yourself, even if you are new to the field. You’ll have to start somewhere ;)</p><p>If you are interested in more details on the method presented in the paper, feel free to drop me a message on Twitter, my account is linked on my Medium profile.</p><p>I hope you’ve enjoyed this paper explanation. If you have any comments on the article or if you see any errors, feel free to leave a comment.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] PAWS GitHub Repository: <a href="https://github.com/facebookresearch/suncet">https://github.com/facebookresearch/suncet</a></p><p>[2] Chen, Ting, et al. “A simple framework for contrastive learning of visual representations.” <em>International conference on machine learning</em>. PMLR, 2020. <a href="https://arxiv.org/pdf/2002.05709.pdf">https://arxiv.org/pdf/2002.05709.pdf</a></p><p>[3] Assran, Mahmoud, et al. “Semi-Supervised Learning of Visual Features by Non-Parametrically Predicting View Assignments with Support Samples.” <em>arXiv preprint arXiv:2104.13963</em> (2021). <a href="https://arxiv.org/pdf/2104.13963.pdf">https://arxiv.org/pdf/2104.13963.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fcbf91517a0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/paper-explained-semi-supervised-learning-of-visual-features-by-non-parametrically-predicting-view-1fcbf91517a0">Paper explained: Semi-Supervised Learning of Visual Features by Non-Parametrically Predicting View…</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Well Does Self-Supervised Learning Perform In The Real World?]]></title>
            <link>https://medium.com/data-science/how-well-does-self-supervised-learning-perform-in-the-real-world-ece18b2d45f6?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/ece18b2d45f6</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Wed, 15 Dec 2021 15:36:28 GMT</pubDate>
            <atom:updated>2021-12-15T15:45:36.653Z</atom:updated>
            <content:encoded><![CDATA[<h4>Pre-training a model on random internet images instead of ImageNet</h4><p>If you have been reading recent publications on self-supervised pre-training, you might have noticed that all of the novel methods and techniques were mostly evaluated on ImageNet. The ImageNet dataset is highly diverse, large and contains an enormous number of classes. It has been curated specifically to evaluate the performance of image processing models, so it is unquestionably well suited for this task. <strong>But relatively few emphasis has been put on how these self-supervised techniques perform on other image datasets</strong>. Datasets that are uncurated and contain large amounts of random images. In their paper <em>“Self-supervised Pretraining of Visual Features in the Wild”</em>, Goyal et al. set out to investigate <strong>whether the perceived performances of self-supervised pre-training techniques hold true when trained on a set of random, uncurated images</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-qx84N7ropPj7BQwMtf3cQ.png" /><figcaption>This graph shows SEER, the main model of the paper, outperforming all other architectures. Source: <a href="https://arxiv.org/pdf/2103.01988.pdf">[1]</a></figcaption></figure><h3>Pre-requisites</h3><p>The SEER model introduced in the paper combines multiple recent advances in computer vision.</p><p>First, it takes advantage of a novel and scalable architecture call <strong>RegNet</strong>. A RegNet is defined by a <strong>quantized linear function to form a network of multiple blocks with optimal widths and depths</strong>. RegNet has two variants: RegNetX which uses the residual block from the classic ResNet, and RegNetY which takes advantage of squeeze-and-excite blocks. I’ve written an entire article about the RegNet architecture, feel free to read it <a href="https://towardsdatascience.com/regnet-the-most-flexible-network-architecture-for-computer-vision-2fd757f9c5cd">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7PGJzWFw-A50MUCULP-dwA.png" /><figcaption>An illustration of a RegNet in all its parts. It is composed of a stem, body and a head, as displayed by (a). Illustrations (b) and (c) show a more detailed view of the stages and blocks. Source: <a href="https://arxiv.org/pdf/2003.13678.pdf">[2]</a></figcaption></figure><p>Another important component of the SEER paper is a self-supervised pre-training technique called <strong>SwAV</strong>. This technique is used for the SEER model and to compare against. <strong>SwaV uses data augmentations to form multiple different versions of the same image</strong>. These are then passed through a convolutional neural network to create a latent representation.<strong> This vector is then learned to be assigned to one of <em>K</em> prototype vectors</strong> by formulating a <strong>swapped prediction problem</strong>. If you would like to refresh your knowledge on SwAV, feel free to read my story on the paper <a href="https://medium.com/towards-data-science/paper-explained-unsupervised-learning-of-visual-features-by-contrasting-cluster-assignments-f9e87db3cb9b">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cTlnpvwz2LbdR_NwgPkCwA.png" /><figcaption>An illustration of the SwAV training process. Source: <a href="https://arxiv.org/pdf/2006.09882.pdf">[3]</a></figcaption></figure><p>An last, the SEER paper compares its performance versus <strong>SimCLR</strong>, another technique for self-supervised pre-training. SimCLR, just like SwAV, uses <strong>data augmentations to form pairs of augmented versions of the same image</strong>. These are then passed into a convolutional neural network to form a feature vector. This vector then goes into an MLP to form the final network output. SimCLR uses a novel loss function called <strong>NT-Xent</strong> which seeks attract different representations of the same object. Again, if you would like to dive deeper into SimCLR, I have an article on the paper which you can read <a href="https://medium.com/towards-data-science/paper-explained-a-simple-framework-for-contrastive-learning-of-visual-representations-6a2a63bfa703">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFILaYrPribmV3rP-lwA2w.png" /><figcaption>A figure showing the training process of SimCLR. Source: <a href="https://arxiv.org/pdf/2002.05709.pdf">[4]</a></figcaption></figure><h3>Developing a model that can benefit from large uncurated image datasets</h3><p>Now on to the main contribution of the paper. As mentioned before, <strong>a key goal for this paper was to find out how a large, uncurated image dataset would impact the performance of the self-supervised method</strong>. Also, the authors aimed to develop a method for outperforming other current state-of-the-art techniques.</p><p>To achieve this, <strong>they used the SwAV technique</strong> to define the pre-training process. More specifically, they created pairs of images of resolutions of 2 x 224 and 4 x 96 with many different data augmentations to pass into the model. They also defined SwAV to have 16K prototype vectors, an important hyperparameter to set for this technique.</p><p>For the model architecture, they opted for the before-mentioned <strong>RegNet</strong>, specifically they experiment with a range of networks, namely <strong>RegNetY-{8, 16, 32, 64, 128, 256}GF</strong> that uses the <strong>Squeeze-and-excite blocks</strong> mentioned earlier. This range of specifications is only enabled by the great flexibility of the RegNet architecture. On top of this RegNet, they defined a 3-layer MLP projection head to form an output vector of 256-D.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wq-V9-g5FAft60QJT7qUQg.png" /><figcaption>“SEER combines a recent architecture family, RegNet, with an online self-supervised training to scale pretraining to billion parameters on billions of random images.”. Source: <a href="https://ai.facebook.com/blog/seer-the-start-of-a-more-powerful-flexible-and-accessible-era-for-computer-vision/">[5]</a></figcaption></figure><p>The entire SEER model (SwAV with RegNet) was trained on <strong>multiple different datasets</strong> to which we will get in the “Results” section, <strong>the most notable one is one billion uncurated images from Instagram</strong>. To train the model, the authors used a stunning <strong>512 NVIDIA V100 32GB GPUs</strong> and training for 122K iterations. Now, let’s see how the SEER model measures against other techniques and for different datasets.</p><h3>Results</h3><p>There’s a lot to unpack here. Let’s start with the classical evaluation for a self-supervised learning model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wDfnO5m0BlmWIi7BGGF9iA.png" /><figcaption>A table of results for different self-supervised pre-training methods when pre-trained on different datasets and finetuned on ImageNet. Source: <a href="https://arxiv.org/pdf/2103.01988.pdf">[1]</a></figcaption></figure><p>As part of the first experiment, <strong>SEER was pre-trained on one billion random images from Instagram and then fine-tuned on ImageNet</strong>. Incredibly,<strong> SEER is able to outperform all other methods in ImageNet top-1 accuracy</strong>. Notably, it can outperform the original SwAV paper even-though it uses its self-supervised pre-training technique, just with a different network architecture. Also, <strong>it outperforms the SimCLRv2 model which has an increased parameter size over its predecessor</strong>. There also seems to be a correlation between top-1 accuracy and parameter count: The larger the model, the better it perfroms. <strong>It is also interesting that SEER outperforms all other methods even-though it is the only method pre-trained on random images</strong>. SimCLRv2 was even pre-trained on ImageNet, which was later used for evaluation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*noWXeCq0feX5ele8874_Uw.png" /><figcaption>A table showing results on a low-shot learning scenario. Source: <a href="https://arxiv.org/pdf/2103.01988.pdf">[1]</a></figcaption></figure><p>The authors also defined a so-called low-shot learning scenario, i.e., following the pre-training, <strong>the model was only fine-tuned using 1% or 10% of the ImageNet dataset</strong> (compared to 100% for the first evaluation). While SimCLRv2 seems to be the best performing model, being pre-trained on ImageNet, <strong>SEER is able to almost match its performance despite not having seen any images from ImageNet before (pre-training on random images)</strong>. This again shows that SEER is able to learn enough about the visual world it has seen during pre-training to transfer its knowledge well enough to the ImageNet classification task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*h51r1IbF2h2TvI9krMdeNQ.png" /><figcaption>A graph showing the RegNetY classification accuracy plotted against the number of parameters in the model. Source: <a href="https://arxiv.org/pdf/2103.01988.pdf">[1]</a></figcaption></figure><p>Another highly relevant finding from paper is that, <strong>as the number of parameters in the RegNet increases, the advantage of a pre-trained model versus a RegNet trained from scratch increases dramatically</strong>. In other words, if you are training a very large model, it is more likely to benefit from (self-supervised) pre-training compared to a smaller model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*AMUdvX9zP2I2iVIFcEa4aw.png" /><figcaption>A table showing the performance of pre-training with SEER for downstream tasks such as object detection and semantic segmentation. Source: <a href="https://arxiv.org/pdf/2103.01988.pdf">[1]</a></figcaption></figure><p>And last but not least, let’s have a look at <strong>SEER’s impact on downstream tasks</strong>. The authors also trained a <strong>Mask R-CNN with a pre-trained RegNet backbone on the MS COCO dataset for object detection and semantic segmentation</strong>. They show that, in comparison to training the model from scratch with labels, <strong>a model using the SEER RegNet backbone</strong> that was pre-trained on random internet images <strong>leads to increased performance for both downstream tasks</strong>.</p><h3>Wrapping it up</h3><p>In this article, you have learned about SEER and how self-supervised pre-training can be effective even when it is not used in combination with a curated dataset. The implications of this are quite profound: <strong>We could be one step closer to completely unsupervised training of image models</strong>. While I hope this story gave you a good first insight into the paper, there is still so much more to discover, especially in terms of the results and the ablation studies. Therefore, I would encourage you to read the paper yourself, even if you are new to the field. You’ll have to start somewhere ;)</p><p>If you are interested in more details on the method presented in the paper, feel free to drop me a message on Twitter, my account is linked on my Medium profile.</p><p>I hope you’ve enjoyed this paper explanation. If you have any comments on the article or if you see any errors, feel free to leave a comment.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] Goyal, Priya, et al. “Self-supervised pretraining of visual features in the wild.” <em>arXiv preprint arXiv:2103.01988</em> (2021). <a href="https://arxiv.org/pdf/2103.01988.pdf">https://arxiv.org/pdf/2103.01988.pdf</a></p><p>[2] Radosavovic, Ilija, et al. “Designing network design spaces.” <em>Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition</em>. 2020. <a href="https://arxiv.org/pdf/2003.13678.pdf">https://arxiv.org/pdf/2003.13678.pdf</a></p><p>[3] Caron, Mathilde, et al. “Unsupervised learning of visual features by contrasting cluster assignments.” <em>arXiv preprint arXiv:2006.09882</em> (2020). <a href="https://arxiv.org/pdf/2006.09882.pdf">https://arxiv.org/pdf/2006.09882.pdf</a></p><p>[4] Chen, Ting, et al. “A simple framework for contrastive learning of visual representations.” <em>International conference on machine learning</em>. PMLR, 2020. <a href="https://arxiv.org/pdf/2002.05709.pdf">https://arxiv.org/pdf/2002.05709.pdf</a></p><p>[5] Facebook AI Research Blog Post: SEER: The start of a more powerful, flexible, and accessible era for computer vision. <a href="https://ai.facebook.com/blog/seer-the-start-of-a-more-powerful-flexible-and-accessible-era-for-computer-vision/">https://ai.facebook.com/blog/seer-the-start-of-a-more-powerful-flexible-and-accessible-era-for-computer-vision/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ece18b2d45f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/how-well-does-self-supervised-learning-perform-in-the-real-world-ece18b2d45f6">How Well Does Self-Supervised Learning Perform In The Real World?</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RegNet: The Most Flexible Network Architecture For Computer Vision]]></title>
            <link>https://medium.com/data-science/regnet-the-most-flexible-network-architecture-for-computer-vision-2fd757f9c5cd?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fd757f9c5cd</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[research]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Mon, 13 Dec 2021 08:43:35 GMT</pubDate>
            <atom:updated>2021-12-13T13:30:36.457Z</atom:updated>
            <content:encoded><![CDATA[<h4>A model design that scales for high-efficiency or high-accuracy</h4><p>Traditionally, convolutional neural network architectures have been designed and optimized for one specific purpose. For example, the ResNet model family was optimized for the highest accuracy on ImageNet at the time of its initial release. MobileNets, as the name suggests, are optimized to run on mobile devices. An last, EfficientNet was designed to be highly efficient for visual recognition tasks.</p><p>In their paper “Designing Network Design Spaces”, Radosavovic et al. decided to set a very unusual but highly interesting goal: They set out to explore and design a highly flexible network architecture. One that can be adapted to be highly efficient or run on mobile devices, but also be highly accurate when adapted for the best classification performance. This adaptation is supposed to be c<strong>ontrolled by setting the right parameters in a quantized linear function </strong>(a set of formulas that have specific paramters) to <strong>determine width and depth of the network</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-tWyCOuvO5dFeVVGeasckw.png" /><figcaption>A visualization of network design spaces. The space is constantly optimized to arrive at a smaller design space with the best models. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>The approach they took was also very non-traditional: Instead of hand-crafting the model architecture, they set up what they call <strong>Network Design Spaces</strong>.</p><h3><strong>Deriving the RegNet model from network design spaces</strong></h3><p>If you have only here to see a description of the RegNet model, feel free to skip this part. I highly recommend you though the read the full article since it is difficult to understand RegNet without an understanding of network design space. <strong>In the end, RegNet is actually not an architecture, but a network design space</strong>.</p><p>A <strong>network design space</strong> is not only, as the name might suggest, made up of different model architectures, but of <strong>different parameters that define a space of possible model architectures</strong>. This is different from neural architecture search, where all you do is try different architectures and search the most suitable one. Such parameters can be the width, depth, groups, etc. of the network. RegNet also uses only one type of network block out of the many different architectures already available, e.g. the bottleneck block.</p><p>To arrive at the final RegNet design space, the authors first define a space of all possible models which they call <strong>AnyNet.</strong> This space creates all kinds of models from all kinds of combinations of the different parameters. All of these models are trained and evaluated on the ImageNet dataset using a consistent training regime (epochs, optimizer, weight decay, learning rate scheduler).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*muYLEc49TIeSYPnJmlMpmg.png" /><figcaption>Statistics for the AnyNet design space, W4 stands for the width of the network at stage 4. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>From this AnyNet space, <strong>they create progressively simplified versions of the initial AnyNet design space</strong> by analyzing what parameters are responsible for the good performance of the best models in the AnyNet design space.<strong> Basically, they are experimenting with the importance of different parameters to narrow down the design space to only the good models.</strong></p><p>These improvements from a current design space to a narrower design space include setting a shared bottleneck ratio and a shared group width, parameterizing the width and depth to increase with later stages.</p><p>Finally, they arrive at the optimized <strong>RegNet design space </strong>that contains only good models and also the quantize linear function necessary to define the models!</p><h3>The RegNet design space</h3><p>The network is composed of multiple stage consisting of multiple blocks, forming a stem (start), body (main part) and head (end).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7PGJzWFw-A50MUCULP-dwA.png" /><figcaption>The RegNet is composed of a stem, body and head. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>Inside the body, multiple stages are defined, and each of the stages is composed of multiple blocks. As mention before, there is only one type of block used in the RegNet which is the standard residual bottleneck block with group convolution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S2dQ6kYfshd5r7P-wBiFNg.png" /><figcaption>The residual bottleneck block with group convolution. On the right, a stride of 2 is applied. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>As mentioned above, the design of the RegNet model is not defined by fixed parameters such as depth and width, but rather a <strong>quantized linear function controlled with the chosen parameters. </strong>Following the optimizations, the <strong>block widths</strong> are calculates as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j5Bd4FvPxY0FBc9C4i3Crw.png" /><figcaption>uj is the block width at stage j, w0 the initial width and wa the slope parameter. j starts at 0 and ends at the depth of the network. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>It is notable that the width for each block is increasing by a factor of <em>wa </em>for each additional block.<br>The authors then introduce an additional parameter <em>wm</em> (this can be set by you) and calculate <em>sj</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cFhbA0431Tqq58nY6koBbA.png" /><figcaption>The formula necessary to calculate sj with the introduction of <em>wm</em>. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>Finally, to quantize <em>uj</em>, the authors round <em>sj</em> and compute the quantized per-block widths:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jL9Y-BV_vWn3c9EKBEFdSA.png" /><figcaption>Per-block widths computed using the inital width and wm to the power of sj. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>Now that the per-block width has been computed, let’s move to the stage level. To arrive at the width for each stage <em>i</em>, all blocks with the same width are simply counted to form one stage since all blocks in once should be of the same width.</p><p>To now create a RegNet out of the RegNet design space, the parameters <em>d</em> (depth), <em>w0</em> (inital width), <em>wa</em> (slope), <em>wm</em> (width parameter), <em>b</em> (bottleneck) and <em>g</em> (group) have to be set.</p><p>The authors now set these parameters differently to obtain different RegNets with different properties:</p><ul><li>A RegNet optimized for mobile use</li><li>An efficient RegNet</li><li>A highly-accurate RegNet</li></ul><p>Let’s how well these network perform compared to other architectures.</p><h3>Results</h3><p>First, let’s examine RegNet’s mobile performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OcUjyC37voJ_jXkE2UI_lg.png" /><figcaption>RegNets compared to other architectures. The X or Y stand for residual block or squeeze-and-exite block, the rest represents the FLOPS required for the network. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>At the same number of FLOPS required, both RegNets outperform the other mobile-optimized nets or show similar performance. But it does not stop there.</p><p>As mentioned in the introduction, <strong>the RegNet was designed to be highly flexible</strong>. This is shown perfectly is the next two evaluations.</p><p>First, RegNets efficient performance versus the EfficientNet architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pKBw2ox6UT86t1tyn5lViQ.png" /><figcaption>RegNet versus EfficientNet. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>Impressively, for all comparisons, RegNet has an advantage. <strong>Either is has similar accuracy at much higher training and inference speeds or it is more accuracy AND faster, especially towards the lower end. </strong>Additionally, the authors claim that <strong>RegNetX-F8000 is about <em>5</em>× <em>faster </em>than EfficientNet-B5</strong>. This is an incredible leap!</p><p>When RegNet is configured for high accuracy, the results also look good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sZ19tRvffjJ-k1KSNAAYhA.png" /><figcaption>RegNet compared to ResNet and ResNe(X)t. Source: <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">[1]</a></figcaption></figure><p>This again shows the flexibility of RegNet: <strong>The model can be specified to be highly efficient and fast or highly accurate.</strong> This has been possible in a single architecture before.</p><h3>Wrapping it up</h3><p>In this article, you have learned about RegNet, a model design space that is highly flexible and takes a very different approach. RegNet is not a single architecture, it is a design space defined by a quantized linear function. While I hope this story gave you a good first insight into the paper, there is still so much more to discover. Therefore, I would encourage you to read the paper yourself, even if you are new to the field. You’ll have to start somewhere ;)</p><p>If you are interested in more details on the method presented in the paper, feel free to drop me a message on Twitter, my account is linked on my Medium profile.</p><p>I hope you’ve enjoyed this paper explanation. If you have any comments on the article or if you see any errors, feel free to leave a comment.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] Radosavovic, Ilija, et al. “Designing network design spaces.” <em>Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition</em>. 2020. <a href="https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf">https://openaccess.thecvf.com/content_CVPR_2020/papers/Radosavovic_Designing_Network_Design_Spaces_CVPR_2020_paper.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fd757f9c5cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/regnet-the-most-flexible-network-architecture-for-computer-vision-2fd757f9c5cd">RegNet: The Most Flexible Network Architecture For Computer Vision</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained: A Simple Framework for Contrastive Learning of Visual Representations]]></title>
            <link>https://medium.com/data-science/paper-explained-a-simple-framework-for-contrastive-learning-of-visual-representations-6a2a63bfa703?source=rss-fa7caddf2d75------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a2a63bfa703</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[towards-data-science]]></category>
            <dc:creator><![CDATA[Leon Sick]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 10:33:39 GMT</pubDate>
            <atom:updated>2021-12-09T14:03:32.443Z</atom:updated>
            <content:encoded><![CDATA[<h4>Going over the ideas presented in the SimCLR paper</h4><p>In this story, we will take a look at SimCLR: The architecture that led the computer vision research community to new heights in self-supervised pre-training for vision tasks.</p><p>SimCLR was presented in the Paper <a href="https://arxiv.org/pdf/2002.05709.pdf"><em>“A Simple Framework for Contrastive Learning of Visual Representations”</em></a> by Chen et al. from Google Research in 2020. The ideas in this paper are relatively simple and intuitive, but there is also a novel loss function that is key for achieve great performance for self-supervised pre-training. I’ve tried to keep the article simple so that even readers with little prior knowledge can follow along. Without further ado, let’s dive in!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NjdVYtL4C2HmV1r22XIweg.png" /><figcaption>An illustration of the SimCLR training procedure. Source: <a href="https://github.com/google-research/simclr">[1]</a></figcaption></figure><h3>Pre-requisite: Self-supervised pre-training for computer vision</h3><p>Before we go deeper into the SimCLR paper, it’s worth quickly re-visiting what self-supervised pre-training is all about. <strong>If you have been reading other self-supervised learning stories from me or you are familiar with self-supervised pre-training, feel free to skip this part.</strong></p><p>Traditionally, computer vision models have always been trained using <strong>supervised learning</strong>. That means humans looked at the images and created all sorts of <strong>labels</strong> for them, so that the model could learn the patterns of those labels. For example, a human annotator would assign a class label to an image or draw bounding boxes around objects in the image. But as anyone who has ever been in contact with labeling tasks knows, the effort to create a sufficient training dataset is high.</p><p>In contrast, <strong>self-supervised learning does not require any human-created labels</strong>. As the name suggest, <strong>the model learns to supervise itself</strong>. In computer vision, the most common way to model this self-supervision is to take different crops of an image or apply different augmentations to it and passing the modified inputs through the model. Even though the images contain the same visual information but do not look the same, <strong>we let the model learn that these images still contain the same visual information</strong>, i.e., the same object. <strong>This leads to the model learning a similar latent representation (an output vector) for the same objects.</strong></p><p>We can later apply transfer learning on this pre-trained model. Usually, these models are then trained on 10% of the data with labels to perform downstream tasks such as object detection and semantic segmentation.</p><h3>Learning image similarity with SimCLR</h3><p>A key contribution by the paper is the use of <strong>data augmentations</strong>. SimCLR creates pairs of images to learn the similarity from. If we would input the same image twice, there would be no learning effect. Therefore, each pair of images is created by applying <strong>augmentations or transformations to the image.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Um_2B7Nh4Pq-bykxqfGKJQ.png" /><figcaption>Different data augmentations applied to an image of a dog. Source: <a href="https://arxiv.org/pdf/2002.05709.pdf">[2]</a></figcaption></figure><p>As can be seen in this excerpt from the paper, the authors apply different augmentations such as resizing, color distortion, blurring, noising and much more. They also take crops from different parts of the image which is important for the model to learn a consistent representation. The image can be cropped into a global and local view (full image and cropped part of the image) or adjacent views can be used (two crops from different parts of the image). Each pair is formulated as a <strong>positive pair, </strong>i.e., both augmented images contains the same object.</p><p>Next, these pairs are passed into a <strong>convolutional neural network </strong>to create a feature representation for each of the images. In the paper, the authors opted to use the popular <strong>ResNet architecture</strong> for their experiments. The pairs of images are always fed to the model in batches. A special emphasis is put on the size of the batch which the authors vary from 256 to 8192. From this batch, the data augmentations are applied, leading to the batch doubling size, so from 512 to 16382 input images.</p><p>Once the vector representation for an input image is computed by the ResNet, this output is being passed to a <strong>projection head </strong>for further processing. In the paper, this projection head is an <strong>MLP </strong>(Multi Layer Perceptron) with <strong>one hidden layer</strong>. This MLP is only used during training and further refining the feature representation of the input images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*DjfAT0CBvObo49ckZzdiXg.png" /><figcaption>The SimCLR training process from the raw input image to the representation computed by the MLP. Source: <a href="https://github.com/google-research/simclr">[1]</a></figcaption></figure><p>Once the MLP computation is completed, the result reserves as the input into the loss function. <strong>The learning goal of SimCLR is maximize agreement between different augmentations of the same image</strong>. That means the model tried to <strong>minimize the distance between images that contain the same object</strong> and<strong> maximize the distance between images that contain vastly different object</strong>. This mechanism is also called <strong>contrastive learning</strong>.</p><p>One major contribution by the SimCLR paper the formulation of its <strong>NT-Xent loss</strong>. NT-Xent stands for normalized temperature-scaled cross entropy loss. This novel loss function has a property that is especially desirable: <strong>Different examples are weighted effectively</strong> allowing the model to <strong>learn much more effectively from vector representations that are far away from each other</strong> even though their origin is the same image. These examples the model perceives to be very different from each other are called <strong>hard negatives</strong>.</p><p>This loss effectively achieves an attraction of similar images, i.e., similar images are learned to be mapped closer together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RFILaYrPribmV3rP-lwA2w.png" /><figcaption>Similar images are attracted to each other. Source: <a href="https://github.com/google-research/simclr">[1]</a></figcaption></figure><h3>Results</h3><p>Once the network is fully trained, the MLP projection head is discarded and only the convolutional neural network is used for evaluation. In their paper, the authors performed different evaluations:</p><p>First, they measure the performance of SimCLR as a linear classifier on the ImageNet dataset. Their results show <strong>SimCLR performing all other self-supervised methods</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_C0on6-VkZQ8ZzPDoaapvQ.png" /><figcaption>Results of SimCLR and other self-supervised methods on ImageNet linear classification. Source: <a href="https://arxiv.org/pdf/2002.05709.pdf">[2]</a></figcaption></figure><p>Please bear in mind that these results are not up-to-date anymore, since novel methods with better performance have come along. Feel free to read my other articles where I go over other self-supervised pre-training models.</p><p>Second, they evaluated the <strong>performance of SimCLR on different image datasets versus training the same ResNet with labels</strong>, i.e., with a supervised learning. Again, <strong>SimCLR performs very well, beating the supervised training method on many datasets</strong>. In the same table, they also looked at results from fine-tuning the self-supervised model with labeled data. In this row, they show that <strong>SimCLR outperforms the supervised training approach on almost all datasets</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hoHoiiNkCnf3SfJlN8T4DQ.png" /><figcaption>Evaluation of SimCLR vs. supervised training of the ResNet. Source: <a href="https://arxiv.org/pdf/2002.05709.pdf">[2]</a></figcaption></figure><h3>Wrapping it up</h3><p>In this article, you have learned about SimCLR, a paper that is one of the most popular self-supervised frameworks with a simple concept and promising results. SimCLR is constantly improved and there is even a second version of this architecture. While I hope this story gave you a good first insight into the paper, there is still so much more to discover. Therefore, I would encourage you to read the paper yourself, even if you are new to the field. You’ll have to start somewhere ;)</p><p>If you are interested in more details on the method presented in the paper, feel free to drop me a message on Twitter, my account is linked on my Medium profile.</p><p>I hope you’ve enjoyed this paper explanation. If you have any comments on the article or if you see any errors, feel free to leave a comment.</p><p><strong>And last but not least, if you would like to dive deeper in the field of advanced computer vision, consider becoming a follower of mine</strong>. I try to post a story once a week and and keep you and anyone else interested up-to-date on what’s new in computer vision research!</p><p>References:</p><p>[1] SimCLR GitHub Implementation: <a href="https://github.com/google-research/simclr">https://github.com/google-research/simclr</a></p><p>[2] Chen, Ting, et al. “A simple framework for contrastive learning of visual representations.” <em>International conference on machine learning</em>. PMLR, 2020. <a href="https://arxiv.org/pdf/2002.05709.pdf">https://arxiv.org/pdf/2002.05709.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a2a63bfa703" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/paper-explained-a-simple-framework-for-contrastive-learning-of-visual-representations-6a2a63bfa703">Paper explained: A Simple Framework for Contrastive Learning of Visual Representations</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>