<?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 Nazim Bendib on Medium]]></title>
        <description><![CDATA[Stories by Nazim Bendib on Medium]]></description>
        <link>https://medium.com/@nazimbendib?source=rss-a0d407bce97c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*H9xxVwfhA2Ect7TUTfcBIA.jpeg</url>
            <title>Stories by Nazim Bendib on Medium</title>
            <link>https://medium.com/@nazimbendib?source=rss-a0d407bce97c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:14:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nazimbendib/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 — Bootstrap Your Own Latent A New Approach to Self-Supervised Learning [ BYOL]]]></title>
            <link>https://medium.com/@nazimbendib/paper-explained-bootstrap-your-own-latent-a-new-approach-to-self-supervised-learning-byol-3c02881f38fe?source=rss-a0d407bce97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c02881f38fe</guid>
            <category><![CDATA[self-supervised-learning]]></category>
            <category><![CDATA[byol]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[contrastive-learning]]></category>
            <dc:creator><![CDATA[Nazim Bendib]]></dc:creator>
            <pubDate>Wed, 14 Sep 2022 00:03:07 GMT</pubDate>
            <atom:updated>2022-09-14T08:55:17.410Z</atom:updated>
            <content:encoded><![CDATA[<h3>Paper explained — Bootstrap Your Own Latent A New Approach to Self-Supervised Learning [ BYOL]</h3><blockquote>BYOL has first appeared in the paper: Bootstrap Your Own Latent<br>A New Approach to Self-Supervised Learning by Grill, Jean-Bastien, et al. in 2020.</blockquote><p>One of the most successful approaches to self supervised learning in computer vision is to learn representations that are invariant to image distortions. However, a recurrent issue with these methods is the existence of trivial constant solutions, which we call a collapse. To prevent such problems, researchers tend to use <strong>negative samples</strong> ( like in SimCLR ) in order to minimize the distance between the representations’ projections of positive pairs ( views of the same image ) and maximize it between negative pairs ( views from different images ).</p><p>In this paper, the authors propose a new approach to self-supervised image representation learning called <strong>BYOL</strong> that doesn’t require memory banks, specialized architectures and interestingly <strong>no negative samples</strong>.</p><h3>Method:</h3><p>In this method we use:</p><ul><li><strong>Two encoders</strong> that take an image as input and output its representation. These two models are referred to as <em>Online encoder</em> and <em>Target encoder</em>. Both encoders share the same architecture: a ResNet-50.</li><li><strong>Two projector</strong> networks that project the representations of the encoders into a lower dimensional projection space. They are also referred to as <em>Online</em> and <em>Target projectors</em>.</li><li><strong>A predictor</strong> model that takes an online projection as an input and tries to predict the target projection.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V0pZsYjFLRYKffxpbCCJ9g.png" /><figcaption>BYOL sketch summarizing the method by emphasizing the neural architecture.</figcaption></figure><p>We first start by uniformly sampling a batch of images from the dataset denoted <strong><em>x</em></strong> upon which we create two randomly augmented views using a random transformation function, let’s call these views <strong><em>v</em></strong> and <strong><em>v’</em></strong>.</p><p>The views <strong><em>v</em></strong> and <strong><em>v’</em></strong> are passed into the online encoder <strong><em>fθ</em></strong> and target encoder <strong><em>fϵ</em></strong> respectively that will output the representations <strong><em>yθ </em>= <em>fθ</em>(<em>v</em>)</strong> and <strong><em>y</em></strong>’<strong><em>ϵ </em>= <em>fϵ</em>(<em>v’</em>)</strong>. These representations will be then passed to the online projector <strong><em>gθ</em></strong> and the target projector <strong><em>gϵ</em></strong> to output the projections <strong>z<em>θ</em> = <em>gθ</em>(<em>yθ</em>)</strong> and <strong>z</strong><em>’</em><strong><em>ϵ</em> = <em>gϵ</em>(<em>y</em></strong>’<strong><em>ϵ</em>)</strong>.</p><p>Finally, the online projection <strong>z<em>θ</em></strong> is passed to the predictor <strong><em>qθ</em></strong> in order to predict the target projection <strong>z</strong><em>’</em><strong><em>ϵ</em></strong> and we <strong><em>L2-normalize</em></strong> both <strong>z</strong><em>’</em><strong><em>ϵ</em></strong> and <strong><em>qθ</em>(z<em>θ</em>)</strong>: the goal is to make <strong><em>qθ</em>(z<em>θ</em>)</strong> as close as possible to <strong>z</strong><em>’</em><strong><em>ϵ</em></strong> following the <strong>mean squared error</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lEZ9cJqWvJYKTgwMp9vbFQ.png" /><figcaption>BYOL Loss function — Mean Squared Error</figcaption></figure><p>Note that:</p><ul><li>The predictor is only applied to the online network: we only want to predict the target projection based on the online projection and not the opposite. In fact, this is one of the main reasons why this method doesn’t collapse even without the use of negative views.</li><li>The loss should be symmetric by also separately passing <strong><em>v’</em></strong> to the online network <strong>&lt;<em>fθ</em>, <em>gθ</em>, <em>qθ</em>&gt;</strong> and <strong><em>v</em></strong> to the target network <strong>&lt;<em>fϵ</em>, <em>gϵ</em>&gt;</strong>, the loss becomes the sum of both losses:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*fLpkfgPNh5_-ja8JgWqapA.png" /></figure><ul><li>At each training step, we perform a stochastic optimization with respect to the online network only. The parameters of the target network are instead updated with the exponential moving average of the parameters of the online network:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZqdUyARFoY5g0_XXYgDpdw.png" /><figcaption>The exponential moving average of the online network</figcaption></figure><h3>Batch size:</h3><p>The self-supervised image representation learning methods that use negative views suffer from performance drop when using small batch sizes likely due to the decrease in the number of negative examples. BYOL on the other hand doesn’t depend on negative sampling which makes its performance stable with batch sizes from 256 to 4096.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*RXEv82NVXbG5sGPLLcKFdw.png" /><figcaption>Impact of batch size</figcaption></figure><h3>Image augmentation:</h3><p>Contrastive methods like simCLR have shown that they are very sensitive to the choice of image augmentations. For instance, simCLR behaves badly when removing the color distortion from the image augmentations set and only using image crops, in this case, the contrastive task is mostly solved by focusing on color histograms.</p><p>The performance of BYOL on the other hand is much less affected than the performance of SimCLR when removing the color distortions from the set of image augmentations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*nGrpLdjI-EqnHEdZ2d7kpg.png" /><figcaption>Impact of progressively removing transformations</figcaption></figure><h3>Target decay rate:</h3><p>The parameters of the target network are the exponential moving average of the online network, which makes it a more stable version of the online network:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*qXzNPDVhuy5rQ7D_shIdZA.png" /></figure><ul><li><strong>If <em>decay_rate</em> = 0</strong>: the target network is instantaneously updated with the parameters of the online network, this destabilizes the training.</li><li><strong>If <em>decay_rate</em> = 1</strong>: the target network will never be updated, and therefore it will keep its initial random state, this makes the training stable but with no performance improvement.</li></ul><p>The following table shows how the performance changes with different target decay rates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*89ybWj-cqFNKA-4FtDQkNA.png" /><figcaption>Results for different target modes</figcaption></figure><p>All values of decay_rate between 0.99 and 0.999 yields performance above 68.4% top-1 accuracy at 300 epochs.</p><h3>The importance of the predictor:</h3><p>The authors showed that by adding a target network to SimCLR its performance improved (+1.6 points) which proves the efficiency of the target network in such methods. The performance still increases a little bit if we use both a target network and a predictor in SimCLR which is basically <strong>BYOL + negative sample.</strong></p><p>Please note that:</p><ul><li>BYOL with negative samples performs worse the original BYOL without negative sample !!</li><li><strong>If we remove either the target network or the predictor, BYOL results in a collapsed solution.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*XfAbIfy4KQ0gWd791utgUQ.png" /><figcaption>Intermediate variants between BYOL and SimCLR.</figcaption></figure><h3>References:</h3><p><strong>[BYOL</strong>] [<a href="https://arxiv.org/abs/2006.07733">Bootstrap your own latent: A new approach to self-supervised Learning</a>]</p><p>[SimCLR] [<a href="https://arxiv.org/abs/2002.05709">A Simple Framework for Contrastive Learning of Visual Representations</a>]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c02881f38fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained — Barlow Twins: Self-Supervised Learning via Redundancy Reduction [ Barlow Twins]]]></title>
            <link>https://medium.com/@nazimbendib/paper-explained-barlow-twins-self-supervised-learning-via-redundancy-reduction-barlow-twins-92c90b49b21e?source=rss-a0d407bce97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/92c90b49b21e</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[barlow-twins]]></category>
            <category><![CDATA[representation-learning]]></category>
            <category><![CDATA[contrastive-learning]]></category>
            <category><![CDATA[self-supervised-learning]]></category>
            <dc:creator><![CDATA[Nazim Bendib]]></dc:creator>
            <pubDate>Sun, 07 Aug 2022 16:57:13 GMT</pubDate>
            <atom:updated>2022-09-14T17:45:35.310Z</atom:updated>
            <content:encoded><![CDATA[<h3>Paper explained — Barlow Twins: Self-Supervised Learning via Redundancy Reduction [ Barlow Twins]</h3><blockquote>Barlow Twins has first appeared in the paper: Barlow Twins: Self-Supervised Learning via Redundancy Reduction by Zbontar et al. in 2021.</blockquote><p>One of the most successful approaches to self supervised learning in computer vision is visual representation learning : it consists in learning representations that are invariant to image distortions. However, a recurrent issue with these methods is the existence of trivial constant solutions, which we call a <strong>collapse</strong>. To prevent such problems, researchers tend to be extremely careful in the implementation, by introducing some delicate architectures like momentum encoder or stop gradient.</p><p>In this paper, the authors propose a novel way of doing visual representation learning by introducing a new objective function that naturally avoids collapse by calculating the cross correlation matrix between the outputs of two identical networks fed with the distorted views of a sample, and making it as close to the identity matrix as possible. This causes the embedding vectors of distorted views of a sample to be close while minimizing the redundancy between the components of these vectors.</p><p>Barlow Twins doesn’t not require:</p><ul><li>Large batches.</li><li>Gradient stopping.</li><li>Momentum encoders ( moving average ).</li><li>Predictor networks.</li></ul><h3>Method:</h3><p>In this method, we use an encoder model <strong><em>f(.)</em></strong> that takes an image as input and outputs its representation. The encoder model consists of a ResNet-50 followed by a projection head that is composed of 3 linear layers of 8192 units each. The first two layers are followed by a batch normalization and a ReLU.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZP3g7049XokH6GEp5pcrw.png" /></figure><p>We first start by uniformly sampling a batch of images from the dataset denoted <strong><em>x</em></strong>, from which we create two randomly augmented views using a transformation function. Let’s call these views <strong><em>x1</em></strong> and <strong><em>x2</em></strong>. Both <strong><em>x1</em></strong> and <strong><em>x2</em></strong> are passed into the encoder model to produce the embedding vectors <strong><em>z1 = f(x1) </em></strong>and <strong><em>z2 = f(x2)</em></strong>. We then normalize the embeddings along the batch dimension (not the feature dimension like it is usually done ).</p><p>The Barlow Twins objection function is stated as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*UjckvQKcM6J68VsJYNKGVA.png" /><figcaption>Barlow Twins objective function</figcaption></figure><p>Where:</p><ul><li><strong><em>λ</em></strong> is positive constant trading off the importance of the invariance term and the redundancy reduction term of the objective function.</li><li><strong><em>C</em></strong> is the cross correlation matrix computed between the normalized <strong><em>z1</em></strong> and <strong><em>z2</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*UVdxcWdNGeijUGLYJGhR4Q.png" /><figcaption>Pearson linear coefficient in the cross correlation matrix between dimension i and j</figcaption></figure><p>Let’s explain each term on it’s own:</p><ul><li><strong>The variance term:</strong> The Barlow Twins objective function tries to minimize the loss by equating the diagonal of the cross correlation matrix to one. This means that embedding vectors of distorted views will be correlated ( correlation = 1 ) and thus closer to each other.</li><li><strong>The redundancy reduction term: </strong>The Barlow Twins’ objective function tries to minimize the loss by equating the off diagonal of the cross correlation matrix to zero. This means that the different vector components will be decorrelated, thus reducing the redundancy between the different dimensions of the embedding vectors.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V1QrsE2fnCildA51NS12tg.gif" /><figcaption>Animated illustration of how the cross correlation matrix is computed in Barlow Twins. bi is the embedding vector and di is the dimension in the embedding vector.</figcaption></figure><p>A redundant embedding vector is a vector that contains the same information in different dimensions. This means that it contains dimensions that are correlated. Let’s see the following examples of embeddings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vpb7cGp1O3sb--YdTvaBaA.png" /><figcaption>Example 1: d’2 is equal to d1 → C12 = 1 → Redundant embedding</figcaption></figure><p>In this first example, the dimensions <strong><em>d1</em></strong> and <strong><em>d’2</em></strong> are equal, which means that <strong><em>d1</em></strong> and <strong><em>d’2 </em></strong>are correlated, so we get a correlation equal to one. This means that these embeddings are redundant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iJ-5ueeu9MmSu9tmS7tjsg.png" /><figcaption>Example 2: d’2 is equal to 3 x d1 → C12 = 1 → Redundant embedding</figcaption></figure><p>Here, even though <strong><em>d’2</em></strong> is not equal to <strong><em>d1</em></strong>, we get a correlation of 1 because we have <strong><em>d’2 = 3 </em>x<em> d1.</em></strong> This means that we can induce the value of <strong><em>d’2 </em></strong>given <strong><em>d1</em></strong>. So the embeddings are redundant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wEOVj0LR37VHSgkR4BBHyw.png" /><figcaption>Example 3: d’2 is equal to -d1 → C12 = -1 → Redundant embedding</figcaption></figure><p>Here, we have a correlation of -1 between <strong><em>d’2</em></strong> and <strong><em>d1</em></strong>. It’s called a negative correlation because we have <strong><em>d2 = -2 x d1</em></strong>. These embeddings are still redundant because the value of <strong><em>d’2</em></strong> can be induced from <strong><em>d1</em></strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFR21k02GRZxG7ycxWj5TQ.png" /><figcaption>Example 4: Cii ~ 1 and Cij ~ 0→ Non redundant embedding</figcaption></figure><p>In this example, we have a correlation close to zero between the dimensions. This means that the embeddings are not redundant.</p><p>The goal of the Barlow Twins objective function is to make the different dimensions of the embedding uncorrelated while keeping the same dimensions correlated.</p><h3>Batch size:</h3><p>Unlike many other visual learning representation methods, Barlow Twins can learn from small batch sizes like 256.</p><h3>Effect of removing augmentations:</h3><p>Barlow Twins is not as efficient as BYOL when removing augmentations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*JYfHBcEx7_k0singMZPw7w.png" /><figcaption>Effect of progressively removing data augmentations.</figcaption></figure><h3>Projection network:</h3><p>Unlike prior methods like <strong>simCLR</strong> and <strong>BYOL</strong> that drastically reduce the dimensionality of the representations and quickly saturate when the dimensionality is increased, Barlow Twins works very well with high dimensionality and keeps improving while increasing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*I-Srd4sj7c6Z2VoMjeX6xQ.png" /><figcaption>Effect of the dimensionality of the last layer of the projector network on performance. The parameter λ is kept fix for all dimensionalities tested.</figcaption></figure><h3>References:</h3><p><a href="https://arxiv.org/abs/2103.03230">Barlow Twins: Self-Supervised Learning via Redundancy Reduction</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92c90b49b21e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained — A Simple Framework for Contrastive Learning of Visual Representations [simCLR]]]></title>
            <link>https://medium.com/@nazimbendib/paper-explained-a-simple-framework-for-contrastive-learning-of-visual-representations-simclr-217ae5f13af2?source=rss-a0d407bce97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/217ae5f13af2</guid>
            <category><![CDATA[self-supervised-learning]]></category>
            <category><![CDATA[contrastive-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[simclr]]></category>
            <dc:creator><![CDATA[Nazim Bendib]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 14:52:38 GMT</pubDate>
            <atom:updated>2022-09-13T16:43:49.001Z</atom:updated>
            <content:encoded><![CDATA[<h3>Paper explained — A Simple Framework for Contrastive Learning of Visual Representations [simCLR]</h3><blockquote>SimCLR has first appeared in the paper: <a href="https://arxiv.org/abs/2002.05709">A Simple Framework for Contrastive Learning of Visual Representations</a> in 2020 by Chen et al.</blockquote><p>In this paper, the authors propose a simple framework for contrastive learning of visual representations <strong>without requiring memory banks, specialized architectures, dynamic dictionaries or momentum encoders</strong>. They show that:</p><ul><li><strong>Composition of data augmentations</strong> is critical in the implementation.</li><li>Introducing a <strong>non linear transformation</strong> between the representation and the loss function improves the performance.</li><li><strong>Representations before the projection head are of a better quality</strong> than those after it.</li><li>Contrastive learning benefits from <strong>large batch sizes</strong> (Like SwAV / Unlike simSIAM)</li></ul><p>SimCLR, similar to many contrastive learning methods ( e.g., simSIAM, MoCo ) learn by minimizing the distance between the representations of augmentations of the same image and maximizing the distance between the representations that come from different images.</p><h3>Architecture:</h3><p>In this method we use an encoder model <strong><em>f</em>(.)</strong> and a projection head <strong><em>g</em>(.)</strong>. The encoder <strong><em>f</em>(.)</strong> is a convolutional neural network that takes an image as an input and outputs its representation. the projection head <strong><em>g</em>(.)</strong> is a MLP with one hidden nonlinear layer ( ReLU is used ) that maps the representations to the space on which the loss function is applied.</p><p>We first start by uniformly sampling a batch of images from the dataset denoted <strong><em>x</em></strong> upon which we create two randomly augmented views using a transformation function, let’s call these views <strong><em>x1</em></strong> and <strong><em>x2</em></strong>. Both <strong><em>x1</em></strong> and <strong><em>x2</em></strong> are passed into the encoder model to produce the representations <strong><em>h1</em></strong> <strong>=</strong> <strong><em>f</em>(<em>x1</em>)</strong> and <strong><em>h2</em> = <em>f</em>(<em>x2</em>)</strong>. Both representations are passed to the projection to produce <strong><em>z1</em>=<em>g</em>(<em>h1</em>)</strong> and <strong><em>z2</em>=<em>g</em>(<em>h2</em>)</strong>.</p><p>Note that in SimCLR, negative samples are not sampled explicitly, instead, anything other than a positive pair (<strong><em>xi</em></strong>, <strong><em>xj</em></strong>) is considered to be a negative pair. In other words, if we sample <strong>N</strong> images from the dataset, we will have <strong>2N</strong> augmented views, and given a positive pair, we will have <strong>2N-2</strong> negative views.</p><h3>Loss function:</h3><p>Given a positive pair <strong>(<em>xi</em>, <em>xj</em>)</strong>, the loss function is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*MhccvsNTxnFKG0-Xkk3wJA.png" /></figure><p>where <strong><em>τ</em></strong> denotes a temperature parameter and <strong>sim(<em>zi</em>, <em>zj</em>)</strong> is the <strong>cosine similarity</strong> given by the dot product of two normalized vectors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*5drUe7fxtQfLZ7SbgGd3iQ.png" /></figure><p>The final loss is computed over all positive pairs with taking in consideration the symmetry, meaning we consider separately both <strong>(<em>xi</em>, <em>xj</em>)</strong> and <strong>(<em>xj</em>, <em>xi</em>)</strong>. The loss function would be as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*0Q3XHhwheB8L75YQF81sCQ.png" /></figure><p>The following is a Pytorch-like pseudocode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*FRz4PlA5chHrzlzfqNxPag.png" /></figure><h3>Data augmentations:</h3><p>To study the impact of view augmentations, the authors considered many compositions of data augmentation.</p><p>We have two types of data augmentation:</p><ul><li><strong>Spatial/geometric transformation:</strong> such as cropping, rotating, resizing…</li><li><strong>Appearance transformation: </strong>such as color distortion, blur, filters…</li></ul><p>To understand the effects of individual data augmentations and the importance of augmentation composition, the authors investigated the performance using individual and pair augmentations. The following figure resumes the linear evaluation (ImageNet top-1 accuracy) of each composition where the diagonal shows individual augmentations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*6e8XUcoyelGlTT_Ebq7zUQ.png" /></figure><p>Notice that no single transformation suffices to learn good representations. The best results are produced when we use 1) cropping and 2) color distortion. The reason behind not using cropping alone without color distortion is that positive pairs will share similar color histograms (similar color distribution), thus the model can exploit this shortcut to solve the predictive problem.</p><h3>A nonlinear projection head improves the representation quality:</h3><p>To study the importance of the nonlinear projection head, the authors investigated the performance of 3 architectures:</p><ul><li>With nonlinear projection head</li><li>With linear projection head</li><li>With no projection head</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*AkBj8ZFN-z-PHH7m07fBoQ.png" /></figure><p>As resumed above, nonlinear projection head performs better with all projection output’s dimensions.</p><p>Interestingly enough, the authors noticed that the representations before the projection head are of a better quality than after the projection head ( even with nonlinear projection head ), because the projection head suffers from a loss of information, this is due to it being invariant to image distortions that may be useful to predict in the downstream tasks. To better clarify this point let’s have an example:</p><p>Imagine if we use rotations in the data augmentation. After training the model, the projection head will be invariant to rotations, meaning it will produce the same representations to both left directed and right directed objects. In a downstream task where the object’s direction is relevant to the prediction, the projection head wouldn’t perform well because it is invariant to rotations.</p><p>The authors proved this by using representations from before and after the projection head to see which ones contain more information about the transformations applied:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hi6bQRMxsM9xsVnOAwYcVQ.png" /></figure><p>Notice how the representation before the projection head always performs better.</p><h3>References:</h3><p><a href="https://arxiv.org/abs/2002.05709">[SimCLR] A Simple Framework for Contrastive Learning of Visual Representations</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=217ae5f13af2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained — Exploring Simple Siamese Representation Learning [SimSiam]]]></title>
            <link>https://medium.com/@nazimbendib/paper-explained-exploring-simple-siamese-representation-learning-simsiam-65ed5ddbe91e?source=rss-a0d407bce97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/65ed5ddbe91e</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[simsiam]]></category>
            <category><![CDATA[contrastive-learning]]></category>
            <category><![CDATA[siamese-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Nazim Bendib]]></dc:creator>
            <pubDate>Thu, 04 Aug 2022 00:44:07 GMT</pubDate>
            <atom:updated>2022-09-14T10:43:47.643Z</atom:updated>
            <content:encoded><![CDATA[<h3>Paper explained — Exploring Simple Siamese Representation Learning [SimSiam]</h3><blockquote>SimSiam which stands for Simple Siamese has first appeared in the paper: <a href="https://arxiv.org/abs/2011.10566">Exploring Simple Siamese Representation Learning</a> in 2020 by Facebook AI Research (FAIR).</blockquote><p>Siamese networks recently became quite famous in unsupervised visual representation learning. Such models minimize the distance between augmented views of the same sample, and maximize the distance between the rest. Under some conditions to prevent collapse, this method results in clusters of the different classes in the representation space. In this paper, the authors have shown that Siamese networks can achieve impressive results without the use of negative samples, larges batches, dynamic dictionaries or momentum encoders.</p><p>In this method, we use an encoder model, a simple convolutional neural network ( a Resent-50 in the paper ) and a prediction MLP head.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hT8O9jmqlABBcLYO2VzvAQ.gif" /><figcaption>Animated illustration of SimSiam training</figcaption></figure><p>We first start by uniformly sampling an input image <strong><em>x</em></strong> from the dataset upon which we create two augmented views, let’s call them<strong> <em>x1</em></strong> and <strong><em>x2</em></strong>. Both views are passed to the encoder model <strong><em>f</em></strong> which will output <strong><em>z1</em></strong> and <strong><em>z2</em></strong>, the representations of <strong><em>x1</em></strong> and <strong><em>x2</em></strong> respectively. These representations are then passed to the prediction MLP ( noted <strong><em>h</em></strong> ) that will transform the representation of one view and matches it to the other view’s representation. For example taking the representation <strong><em>z1</em></strong> and transforms it to <strong><em>p1 </em>=<em> h</em>(<em>z1</em>)</strong> and then compare it to <strong><em>z2</em></strong>. This distance is minimized using the following loss function:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*RlCTMMVM_XGeeVZFSwC33g.png" /></figure><p>Where <strong>D(<em>p1</em>, <em>z2</em>)</strong> is the negative cosine similarity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*UbHGUNf3JvO3rFXJcx4L4g.png" /></figure><p>To calculate the loss, the authors treat <strong><em>z1</em></strong> as a constant by using <strong>gradient-stop</strong> ( detaching the variable from the graph ):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tCz3GUVBU5cJIZpGiw5E2A.png" /></figure><p>Here, the encoder on <strong><em>x1</em></strong> won’t receive any gradient from <strong><em>z1</em></strong> ( in the second term ) but receives a gradient from <strong><em>p1</em></strong> (in the first term).</p><p>The following is a Pytorch-like pseudo code of SimSiam training:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_7r50lFZuJfj2-rhEVlOQ.png" /><figcaption>SimSiam PyTorch-like Pseudocode</figcaption></figure><h3>Encoder model:</h3><p>The encoder is composed of:</p><ul><li>A ResNet-50 backbone.</li><li>A <strong>projection MLP</strong> of 3 layers of size 2048 upon which Batch Normalization and ReLU are applied,<strong> except for the output with no ReLU.</strong></li></ul><h3>Prediction MLP:</h3><p>The prediction MLP is composed of 2 layers with Batch Normalization and ReLU except for the output with <strong>no Batch Normalization nor ReLU</strong>. The input and output size is 2048, with a hidden layer of size 512, thus, the prediction MLP is <strong>bottelneck structure</strong>.</p><p><strong>Note: Don’t confuse between the projection MLP that belongs to the encoder and the prediction MLP that transforms representations.</strong></p><h3>Stop gradient:</h3><p>The authors show in their paper that stop-gradient is <strong>a critical setup</strong> in their architecture as neglecting it leads to extremely bad results. The following graph shows that without stop-gradient, the optimizer quickly finds a degenerated solution that leads to a loss of -1 ( the minimum loss achievable ).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*H7OYMsIJFl0XT1fQOg6uBQ.png" /></figure><p>To show that this a collapsed solution, the authors studied the standard deviation of the normalized outputs: a standard deviation over all samples is zero for each channel which means a constant output vector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*AZrg09_dwwO06TktS5k67g.png" /></figure><h3>Batch size:</h3><p>Unlike SimCLR and SwAV, SimSiam can perform decently with <strong>small batch sizes of 64 and 128</strong>, the results are pretty similar to when the batch size is from 256 to 2048. Both SimCLR and SwAV require large batch sizes (e.g., 4096) to work well.</p><h3>Similarity function:</h3><p>The similarity function used in the SimSiam loss function is the cosine similarity. Although the authors tried to replace this similarity function with the cross-entropy similarity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YZb0yMOtx8eeUL2V3lvNgQ.png" /></figure><p>This similarity function variant can also converge to reasonable results without collapsing: this suggests that the collapse problem isn’t directly related to the similarity function.</p><h3>References:</h3><p><a href="https://arxiv.org/abs/2011.10566">Exploring Simple Siamese Representation Learning paper [SimSiam]</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65ed5ddbe91e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Paper explained — Momentum Contrast for Unsupervised Visual Representation Learning [MoCo]]]></title>
            <link>https://medium.com/@nazimbendib/paper-explained-momentum-contrast-for-unsupervised-visual-representation-learning-moco-2b9e9aaffc1f?source=rss-a0d407bce97c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b9e9aaffc1f</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[moco]]></category>
            <category><![CDATA[self-supervised-learning]]></category>
            <category><![CDATA[momentum-contrast]]></category>
            <category><![CDATA[contrastive-learning]]></category>
            <dc:creator><![CDATA[Nazim Bendib]]></dc:creator>
            <pubDate>Wed, 03 Aug 2022 16:38:50 GMT</pubDate>
            <atom:updated>2022-08-03T16:38:50.398Z</atom:updated>
            <content:encoded><![CDATA[<h3>Paper explained — Momentum Contrast for Unsupervised Visual Representation Learning [MoCo]</h3><blockquote>MoCo which stands for Momentum Contrast has first appeared in the paper: Momentum Contrast for Unsupervised Visual Representation Learning by He et al. in 2020.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pZIfW2Gku0yvXqGS3hpzvg.png" /><figcaption>Conceptual comparison of three contrastive loss mechanisms</figcaption></figure><p>Several studies achieved promising results in unsupervised visual representation learning using contrastive learning by building dynamic dictionaries that contain key representations of data samples ( images or patches ) produced by an encoder model.</p><p>It is hypothesized in this paper that in order to enhance the quality of the feature representation, we should have:</p><ul><li><strong>A big dictionary size:</strong> The dictionary can be seen as a sample of all the images dataset. So clearly a big dictionary is better at sampling our high dimensional pixels space.</li><li><strong>A consistent dictionary as it evolves during the training:</strong> It means that all the keys are produced by the same encoder, or at least a similar one.</li></ul><h3>The dictionary is built as a queue:</h3><p>As the size of the dictionary is limited by memory, it still needs to sample the whole datasets as good as possible. An intuitive solution would be to use a <strong>queue</strong> <strong>as a dictionary</strong> that will repeatedly get updated during the training, such as in a given learning step, the most recent encoded keys are enqueued (pushed), and the oldest ones are dequeued.</p><h3>The training:</h3><p>In this method, we use two models, a <strong>query encoder</strong> model and a <strong>key encoder</strong> model. Both models are convolutional neural networks ( a ResNet-50 in the paper ) that take an input as an image ( or a patch ) and output its representation.</p><p>We first start by uniformly sampling a batch of images from the dataset upon which we create two randomly augmented sets of views: the <strong>query views</strong> and the <strong>keys views</strong>. Both views are then passed to the <strong>query encoder</strong> and <strong>key encoder </strong>respectively, that will output the <strong>query representation</strong> and the <strong>key representation</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qlfFof5sPPUQRWZlwzd4eg.gif" /><figcaption>Animated visualization of MoCo training</figcaption></figure><p>The loss is calculated using a variant of the NCE loss as following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/1*EariNk-gze40HVtQ8rAfAQ.png" /><figcaption>NCE loss function</figcaption></figure><p>where:</p><ul><li><strong><em>q</em></strong> is the query representation.</li><li><strong><em>k+</em></strong> is the corresponding key ( the one generated from the other augmented view of the query ) we call it the <strong>positive sample.</strong></li><li><strong><em>k-</em></strong><em>i</em> are the keys that are stored in the dictionary, we call them the <strong>negative samples</strong>.</li><li><strong><em>t</em></strong> is the temperature and it indicates how strict the loss function is with the negative samples.</li></ul><p>This loss function ( like most contrastive loss functions ) will try to <strong>minimize the distance between <em>q</em> and <em>k+</em>, and maximize it between <em>q</em> and <em>k-</em></strong>. In other words, it will pull the views that have been augmented from the same sample together and push away those that didn’t come from the same samples.</p><h3>The key encoder is a momentum moving average of the query encoder:</h3><p>The key encoder won’t get updated using back propagation, as the gradients will flow all the way down to all of the dictionary representation which makes it quite expensive. A naive solution would be to copy the parameters of the key encoder from the query encoder, but this solution yields bad experimental results, because the parameters were rapidly changing which led to reducing the representations’ consistency of the dictionary.</p><p>Another solution is to do <strong>momentum updates</strong>. The parameters of the encoder would update by:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/174/1*bdiMxe2T0Zn2HQCgKqmXeQ.png" /><figcaption>Momentum updates</figcaption></figure><p>where <strong>m</strong> is the <strong>momentum coefficient</strong> with a value in [0, 1). This makes the parameters of the key encoder update more smoothly than those of the query encoder which will lead to much more consistent representations in the dictionary. Experiments have shown that a big momentum coefficient like 0.999 yields far better results than a smaller value like 0.9 ( yes 0.9 is small ! ).</p><p>By the end of the training, only the query encoder is kept to be used as a feature extractor to solve downstream tasks like image classification and object detection.</p><h3>Reference:</h3><p><a href="https://arxiv.org/abs/1911.05722">Momentum Contrast for Unsupervised Visual Representation Learning</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b9e9aaffc1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>