Settings

Theme
Lite Mode (saves mobile data)

In Lite Mode, animations and videos don't play until you tap them, and their size is shown first. Interactive widgets still work.

Text size

Back up or move your progress →

Part 5: Computer Vision and CNNs

Self-supervised vision

P5.1645 min●●● AdvancedReviewed Dec 3, 2026

Why this matters for machine learning

Labels cost time and money, but unlabelled images are everywhere. Self-supervised pretraining turns the pictures themselves into a training signal, and gives a backbone whose features you can reuse with few labels.

  • The pretrained backbone you fine-tune or probe with a linear head (the setting of P5.10) can come from self-supervised training instead of labels. (P5.10: Transfer learning and fine-tuning)
  • CLIP applies the same pull-together, push-apart loss to image and caption pairs instead of two views of one image. (P8.13: CLIP and contrastive image-text learning, coming soon)
  • BERT is pretrained by hiding about 15% of the words and predicting them, the idea that MAE carries over to image patches. (P7.10: Three families, coming soon)

Before this: Transfer learning and fine-tuning, Vision Transformers, Data augmentation, Dot product and cosine similarity

After this lesson you can

  • Compute the NT-Xent loss for a small batch at two temperatures
  • Describe what SimCLR and MoCo each add
  • Explain collapse and how negatives, or DINO's tricks, prevent it
  • Describe how MAE masks and reconstructs, and why its ratio is high

A photo of a dog, zoomed in on its head and then tinted orange, is still a photo of that dog. Can a network learn from that fact alone, with no label at all?

P5.10 started from weights trained on 1.28 million labelled photos that somebody had to label. This lesson gets features from unlabelled pictures with four methods: contrastive learning (SimCLR and MoCo), a self-distilling teacher (DINO) and masked image modelling (MAE).

The idea: make labels from the data

Self-supervised learning invents a task, called a pretext task, whose answer is already inside the data. Nobody labels anything. The network solves the pretext task, and while doing so it has to build features that describe the image. Afterwards you throw the pretext task away and keep the encoder (the network that turns an image into a feature vector).

How do you know the features are any good? You test them on a real task, in the two ways of P5.10:

  • Linear probe: freeze the encoder and train only a new linear head on labelled images. The probe measures how easily the labels can be read off the features. (This is the same meaning as in P5.10.)
  • Fine-tuning: start from the encoder and train all or some layers on the labelled task.

DINO also reports a k-NN test: label an image by its nearest neighbours in feature space (P3.B1), with no training.

Three families share this recipe, and they differ in the pretext task:

  1. Contrastive: two views of the same image must have similar features, and views of different images must not.
  2. Self-distillation (DINO): a student network must match the output of a teacher network, which is a slow average of the student, on another view of the same image.
  3. Masked image modelling (MAE): hide most of the image and predict what is missing.

Contrastive learning: pull together, push apart

Take one image and make two random augmented views of it, for example two different crops with different colour changes. The augmentations themselves are in P4.18 and P5.7, so we only use them here. The two views form a positive pair: they should have similar features. Every view of every other image in the same batch is a negative: it should have different features.

The encoder maps each view to a vector z\mathbf{z} and we compare vectors by cosine similarity, the dot product of the vectors scaled to length 1 (P1.B3):

sim(u,v)=u⋅v∥u∥ ∥v∥.\mathrm{sim}(\mathbf{u},\mathbf{v})=\frac{\mathbf{u}\cdot\mathbf{v}}{\lVert\mathbf{u}\rVert\,\lVert\mathbf{v}\rVert}.

It is 11 for the same direction, 00 for perpendicular and −1-1 for opposite. Every embedding is a point on a sphere (a circle, with two numbers).

A worked example with four views

Take a batch of N=2N=2 images, AA and BB, and two views of each: A1A_1, A2A_2, B1B_1, B2B_2. Suppose the encoder, with two output numbers, put them at angles 0∘0^\circ, 20∘20^\circ, 90∘90^\circ and 110∘110^\circ on the circle. The cosines of A1A_1 with the others are cos⁡20∘=0.94\cos 20^\circ=0.94 for A2A_2, cos⁡90∘=0\cos 90^\circ=0 for B1B_1 and cos⁡110∘=−0.342\cos 110^\circ=-0.342 for B2B_2.

For the view A1A_1, the question is a multiple choice: of the other three views, which is its partner? Turn the three similarities into scores by dividing by a temperature τ\tau (take τ=0.5\tau=0.5), and apply softmax (P3.A8) to get probabilities:

  • scores ≈1.879\approx1.879, 00 and −0.684-0.684 (0.94/0.50.94/0.5, 0/0.50/0.5 and −0.342/0.5-0.342/0.5);
  • probabilities 0.8130.813 for A2A_2, 0.1240.124 for B1B_1 and 0.0630.063 for B2B_2.

The loss for this view is minus the log of the probability of the right partner: −ln⁡0.813=0.207-\ln 0.813=0.207. That is a cross-entropy loss (P1.E3) where the “classes” are the other views and the correct class is the partner. Doing the same for all four views gives 0.2070.207, 0.3750.375, 0.3750.375 and 0.2070.207, and the mean is 0.2910.291. This loss is called NT-Xent, short for normalized temperature-scaled cross-entropy (Chen and co-authors, SimCLR). It is the InfoNCE loss of P1.E5 with cosine similarity inside. The code cell below runs it.

In general, for a batch of NN images there are 2N2N views, and each view has 2N−12N-1 candidates, of which one is the partner and 2N−22N-2 are negatives. The loss for view ii, whose partner is p(i)p(i), is

ℓi=−log⁡exp⁡ ⁣(sim(zi,zp(i))/τ)∑k≠iexp⁡ ⁣(sim(zi,zk)/τ),\ell_i=-\log\frac{\exp\!\big(\mathrm{sim}(\mathbf{z}_i,\mathbf{z}_{p(i)})/\tau\big)}{\sum_{k\neq i}\exp\!\big(\mathrm{sim}(\mathbf{z}_i,\mathbf{z}_k)/\tau\big)},

and the training loss is the mean of ℓi\ell_i over all 2N2N views.

What the temperature does

The same four points at three τ\tau (the cell prints them):

  • τ=0.1\tau=0.1: mean loss 0.0010.001 (a small τ\tau spreads the scores apart, so the softmax is nearly certain).
  • τ=0.5\tau=0.5: mean loss 0.2910.291.
  • τ=1.0\tau=1.0: mean loss 0.5870.587 (cosines only range from −1-1 to 11, so the probabilities stay spread out).

A small τ\tau makes the softmax sharp, and the loss then cares mostly about the negatives that are closest to the view (the hardest ones), because only they have a large share of the probability. A large τ\tau treats all negatives more equally. One consequence: loss values at different temperatures cannot be compared, because the floor differs. In SimCLR’s own comparison (ResNet-50, 100 epochs, batch size 4096, linear probe on ImageNet) the temperature mattered: τ=0.1\tau=0.1 gave 64.4% top-1, τ=0.5\tau=0.5 gave 60.7% and τ=1\tau=1 gave 58.0% (and τ=0.05\tau=0.05 gave 59.7%, so smaller is not always better).

NT-Xent for four views

Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).

The first cosine printed is the view with itself (11). The last line previews the next section: when every view has the same embedding, the loss is ln⁡3=1.0986\ln 3=1.0986, whatever τ\tau is.

See it: pull together, push apart

Four code-drawn images, each with two augmented views, become points on a circle. Move the slider through the training steps of a real, tiny contrastive run.

A circle
views A1, A2
B square
views B1, B2
C triangle
views C1, C2
D cross
views D1, D2
Temperature τ
A1B1C1D1A2B2C2D2

NT-Xent loss (τ = 0.5) 3.016
Mean cosine, two views of one image-0.02
Mean cosine, views of different images0.25

Not trained yet: pairs are not yet close, or different images are not yet apart.

A stand-in for a real encoder: each image is 7 numbers (4 that identify it plus small noise, 2 of fresh random “colour jitter” per view, and a constant 1), and the encoder is one 2×7 matrix whose output is scaled to length 1. Stored run of one seed; loss and cosines are computed here from the stored points.

Eight views of four images on the unit circle. Filled marker: first view. Ring: second view, joined to the first by a line. Colour, marker shape and the labels A1 to D2 name each view.

Things to try:

  1. With negatives and τ=0.5\tau=0.5, press Back to step 0 and then slide to about step 16. In this run the two views of every image move together (mean positive cosine about 0.960.96) and the images spread around the circle, so the mean cosine between different images falls from 0.250.25 to −0.27-0.27. The ideal for four images spread 90∘90^\circ apart is −1/3-1/3, and the run ends close to it at −0.31-0.31.
  2. Set τ=0.1\tau=0.1 and slide to step 120: the loss ends near 0.0060.006. At τ=1\tau=1 it levels off near 1.11.1, close to the collapsed value ln⁡3≈1.099\ln 3\approx1.099, because even a perfect layout only reaches about 1.011.01 there. Judge the picture and the cosines, not the loss.
  3. Switch to No negatives and slide to step 16 or later. The pairs are as close as ever (positive cosine above 0.990.99), but all four images have collapsed onto the same small arc of the circle: the mean cosine between different images is 0.930.93 at step 16. The positives-only loss is near its best possible value, −1-1, while the embedding has forgotten which image is which.

The widget is a stand-in, not a real image encoder (the note under it says how). Its random “colour jitter” is what the encoder must learn to ignore, the job of real augmentations. The run was trained offline with tests/data/P5.16-train.py.

Why positives alone are not enough: collapse

Look at the positives-only run again. The loss only asks “make the two views of one image agree”. The cheapest way to satisfy that is to ignore the input and output the same vector for everything: then every pair agrees perfectly. This is collapse (also called a trivial solution or a constant embedding), and the loss cannot tell it apart from a useful encoder.

Negatives forbid it. If all views had the same embedding, every candidate would look like the partner, the softmax would be uniform over 2N−12N-1 views, and the loss would be ln⁡(2N−1)\ln(2N-1), which is the loss of a blind guess among the 2N−12N-1 candidates (the cell above: ln⁡3\ln 3 for N=2N=2). Any embedding that ranks the partner above the others does better. To lower the loss the encoder must make the partner closer than the others, which needs different images to land in different places.

The widget run is one seed, and over 8 seeds of this toy model positives-only collapsed in 6 of 8 (script in the repository). It shows the mechanism, not real networks.

SimCLR: a simple recipe

SimCLR (Chen, Kornblith, Norouzi and Hinton, ICML 2020) is the setup above with a ResNet encoder, and its paper studied which parts matter.

  • Augmentations decide what the encoder learns. Two views of one image are positive, so whatever differs between them becomes something the features must ignore. The paper found that composing augmentations is critical, and that one composition stands out: random crop plus random colour distortion. It conjectured the reason: with crops alone, the pixel-intensity histograms of two crops of one image are similar, and histograms alone are enough to tell images apart, so the network can solve the task with colour statistics and learn little else.
  • A projection head. Between the encoder output h\mathbf{h} and the loss sits a small network gg, giving z=g(h)\mathbf{z}=g(\mathbf{h}). The loss is computed on z\mathbf{z}, but after training the head is thrown away and h\mathbf{h} is used. The paper found a nonlinear head (one hidden layer) gave about 3 points better linear-probe accuracy than a linear head and more than 10 points better than no head, and that h\mathbf{h} was better than z\mathbf{z} by more than 10 points. Its conjecture is that z\mathbf{z} is trained to ignore things the augmentations change, such as colour, which a later task may need.
  • Large batches. Every other image in the batch is a negative, so a bigger batch means more negatives. The paper used batch sizes from 256 to 8192; at 8192 each positive pair has 16,382 negative examples.
  • Result. ResNet-50 (the usual width), 1000 epochs: 69.3% top-1 with a linear probe on ImageNet. A ResNet-50 four times wider (375 M parameters instead of 24 M): 76.5%, about the level of a standard supervised ResNet-50 (the paper’s supervised baseline gets 76.3%). At the standard width the supervised network is still ahead (76.3% against 69.3%).

MoCo: many negatives without a huge batch

A big batch needs a lot of memory. MoCo (Momentum Contrast, He, Fan, Wu, Xie and Girshick, CVPR 2020) gets many negatives another way. It treats learning as a dictionary look-up: a view’s encoded vector is the query q\mathbf{q}, and the vectors of other images are keys in a dictionary. Two ideas make a big, useful dictionary:

  • A queue. The keys from the most recent batches are kept in a queue of fixed length KK (65,536 in the paper’s main ResNet-50 setup): the newest batch is added and the oldest removed. The dictionary size is then decoupled from the batch size, which was 256 there.
  • A momentum encoder. The keys are produced by a second encoder whose weights are a slow moving average of the main one: θk←m θk+(1−m) θq\boldsymbol{\theta}_k\leftarrow m\,\boldsymbol{\theta}_k+(1-m)\,\boldsymbol{\theta}_q with mm close to 1 (0.999 by default). Why: the keys in the queue were computed by encoders from many steps ago, and if the encoder changed fast, old keys would be incomparable with new queries. A slowly moving key encoder keeps the queue consistent. The paper reports that without it (m=0m=0) the training loss oscillated and failed to converge, and that m=0.999m=0.999 worked better than m=0.9m=0.9 (59.0% against 55.2%, in an ablation with a queue of 4096 keys). Gradients flow only through the query, not the keys.

With a ResNet-50, 200 epochs and batch size 256, MoCo reached 60.6% top-1 with a linear probe on ImageNet in the paper (SimCLR’s 69.3% above was with a longer, larger-batch run, so the two numbers are not an equal comparison). The momentum idea comes back in DINO below.

DINO: no negatives, a teacher that is a slow average

DINO (Caron and co-authors, ICCV 2021) drops negatives completely. Two networks with the same architecture look at different views of one image:

  • the student gets all the views, and is trained by gradient descent;
  • the teacher gets only the large views and is not trained by gradient: its weights are an exponential moving average of the student’s (the same momentum update as MoCo, with the momentum rate going from 0.996 towards 1).

Both output a probability distribution over KK numbers, and the student is trained to match the teacher’s distribution with a cross-entropy loss, for views of the same image. The teacher is built from the student’s past, which is why the paper calls this self-distillation with no labels. The multi-crop idea feeds the student also several small 96×9696\times96 crops, while the teacher sees only the two large 224×224224\times224 ones, so the student learns “small piece to whole image” matches.

Avoiding collapse: centring and sharpening

With no negatives, what stops the output being constant? DINO applies two small operations to the teacher’s output:

  • Centring subtracts a running average of the teacher’s outputs, so no single output dimension can dominate for every image.
  • Sharpening divides by a small temperature before the softmax (the paper uses 0.04 to 0.07 for the teacher against 0.1 for the student), making the teacher’s distribution peaked.

The paper states that they work in opposite directions: centring alone pushes towards a flat (uniform) output, sharpening alone pushes towards one dimension winning, and applying both balances them. In the paper’s ablation, DINO without the momentum teacher (centring and sharpening alone) fell to 0.1% (ViT-S/16, 300 epochs). The paper describes centring and sharpening as enough to avoid collapse when a momentum teacher is present; it does not claim a proof of why.

A tiny version you can run: three images, four output numbers, where dimension 0 is large for every image.

Centring and sharpening

Runs real Python in your browser. First run downloads about 9 MB (once; your browser keeps it).

Reading it: without centring every image picks dimension 0 (collapse), sharpening alone makes that certain, centring alone leaves the outputs flat (maximum about 0.40.4, near the uniform 0.250.25), and together each image picks its own dimension confidently. Real DINO uses a running average over batches for the centre.

What DINO showed

All of these numbers are on ImageNet with no labels used for pretraining, and a Vision Transformer (P5.15):

  • A ViT-Base with 8×88\times8 patches reached 80.1% top-1 in linear evaluation and 77.4% with k-NN. A small ViT gave 78.3% with k-NN (the abstract).
  • Attention maps. The paper looks at the self-attention of the class token in the last layer of a ViT trained with DINO. These maps, without any segmentation training, highlight objects and give rough object masks. Thresholding the map to keep 60% of its mass and comparing with ground-truth masks on PASCAL VOC12 (Jaccard similarity, intersection over union), the best head of a ViT-S/16 scored 45.9, against 27.3 for a supervised ViT of the same size and 22.0 for a random network. The maps are not trained to be masks and the best head is picked, so this shows that object information is in the features, not a finished segmentation method.

BYOL (Grill and co-authors, 2020) is a related method with no negatives that reported 74.3% with a linear probe on ImageNet using a ResNet-50.

MAE: hide most of the image, predict the pixels

The third family comes straight from language. BERT hides a few words and predicts them, so MAE (Masked Autoencoders, He and co-authors, CVPR 2022) hides patches of an image and predicts them. The image is cut into a grid of squares (the patches of P5.15) and a random subset is masked.

  • The encoder (a ViT) sees only the visible patches. It never sees mask placeholders, which is what makes it cheap.
  • A light decoder gets the encoded visible patches plus a learned mask token for each missing patch, with position information, and predicts the pixel values of the missing patches.
  • The loss is the squared error on the masked patches only. The paper found that normalizing each patch’s pixels (its own mean and standard deviation) first gave better features.
  • After pretraining the decoder is thrown away, and the encoder is used on full images.
Masked patches147 of 196
Visible patches the encoder reads49
Encoder input length vs the full image25%

A made-up 224×224 scene as 14×14 patches of 16×16 pixels (P5.15). Crossed grey squares are masked; the MAE encoder reads only the rest.

Slide the masking ratio and see how many of the 196 patches the encoder would read.

At 75% masking, 0.75×196=1470.75\times196=147 patches are hidden and 4949 are seen. Attention compares every token with every other, so 196 to 49 tokens takes the pairs from 1962=38,416196^2=38{,}416 to 492=2,40149^2=2{,}401, a sixteenth. The paper reports a training speedup of 3 times or more.

Why so much masking?

BERT hides about 15% of its tokens. MAE found that for images the best ratios were far higher: 75% worked well for both linear probing and fine-tuning. The reason the paper gives is redundancy. Language is dense, so predicting a few missing words needs real understanding. A missing image patch can mostly be filled in from its neighbours by extending lines and textures, so a low ratio is solved without learning about objects. Hiding most of the image removes that shortcut. (BERT and other text objectives are in P7.10.)

What MAE showed

All on ImageNet-1K, with a vanilla ViT (conditions matter):

  • ViT-Large, 800 epochs of pretraining, 75% masking: fine-tuned 84.9% top-1, but a linear probe only 73.5%. The paper itself notes MAE features are less linearly separable than those of a contrastive method (MoCo v3), yet become stronger once even a little is fine-tuned: tuning one extra Transformer block lifted ViT-L from 73.5% to 81.0%.
  • ViT-Huge, 1600 epochs: 86.9% at 224×224224\times224 and 87.8% when fine-tuned at 448×448448\times448, the best result among methods using only ImageNet-1K data at the time of the paper.
  • The same ViT-L trained from scratch reached 82.5% in the paper’s implementation.

So linear-probe accuracy is only one way to judge features: a method can score lower on it and still be a better starting point for fine-tuning.

CLIP (P8.13) also uses a contrastive loss, but its positive pair is an image and its caption, not two views.

Three ways to see it

Intuition

Contrastive learning is a game of “spot the twin”: given one cropped, recoloured photo and a line-up of others, pick the other version of the same photo. To win you must notice what stays the same under cropping and recolouring, the object, and ignore the rest. With no negatives the game is only “say these two look alike”, and the lazy strategy is to call everything alike. MAE is a jigsaw with 75% of the pieces missing. The picture breaks where the network uses whatever lowers the loss, which can be a shortcut such as colour.

Math

For the 2N2N views with unit embeddings zi\mathbf{z}_i and partner p(i)p(i), define the scores sik=sim(zi,zk)/τs_{ik}=\mathrm{sim}(\mathbf{z}_i,\mathbf{z}_k)/\tau and the softmax probabilities pik=esik/∑j≠iesijp_{ik}=e^{s_{ik}}/\sum_{j\neq i}e^{s_{ij}}. The loss is

L=12N∑i=12N−log⁡pi,p(i).\mathcal{L}=\frac{1}{2N}\sum_{i=1}^{2N}-\log p_{i,p(i)}.

It is a softmax cross-entropy, so (P3.A8) the derivative with respect to a score is

∂ℓi∂sik=pik−1[k=p(i)].\frac{\partial \ell_i}{\partial s_{ik}}=p_{ik}-\mathbb{1}[k=p(i)].

The partner is pulled with strength 1−pi,p(i)1-p_{i,p(i)} and each negative is pushed with strength pikp_{ik}. In the worked example, view A1A_1 at τ=0.5\tau=0.5 has p=0.813p=0.813 for its partner, so the pull is 0.1870.187, and the pushes are 0.1240.124 on B1B_1 and 0.0630.063 on B2B_2 (they add up to 0.1870.187). Negatives that are close to the view have the largest pikp_{ik}, so they are pushed the hardest, and a small τ\tau makes this concentration stronger. When the embeddings are all equal, pik=1/(2N−1)p_{ik}=1/(2N-1) and L=ln⁡(2N−1)\mathcal{L}=\ln(2N-1).

P1.E5 shows that, in expectation and under assumptions, log⁡(number of candidates)−loss\log(\text{number of candidates})-\text{loss} is a lower bound on the mutual information between the two views. That bound can never exceed log⁡(number of candidates)\log(\text{number of candidates}), which is ln⁡(2N−1)\ln(2N-1) here, so a small batch limits what it can certify. It says nothing guaranteed about the quality of the features.

DINO: the student’s softmax output is trained to match the teacher’s centred, sharpened output with cross-entropy H(Pt,Ps)=−∑jPt,jlog⁡Ps,jH(P_t,P_s)=-\sum_j P_{t,j}\log P_{s,j}, and the teacher is a moving average of the student. MAE: mean squared pixel error over the masked patches MM only, 1∣M∣∑j∈M∥x^j−xj∥2\frac{1}{|M|}\sum_{j\in M}\lVert\hat{\mathbf{x}}_j-\mathbf{x}_j\rVert^2.

Code

The same loss in PyTorch (static: PyTorch is not available in the browser), checked against the NumPy cell above. Shapes are (2N,d)(2N, d).

import math, torch, torch.nn.functional as F

def nt_xent(z, tau):
    z = F.normalize(z, dim=1)
    n = z.shape[0] // 2
    s = z @ z.T / tau
    s = s.masked_fill(torch.eye(2 * n, dtype=torch.bool), float("-inf"))
    target = torch.cat([torch.arange(n, 2 * n), torch.arange(0, n)])
    return F.cross_entropy(s, target)

a = torch.tensor([0., 90., 20., 110.]) * math.pi / 180
z = torch.stack([a.cos(), a.sin()], dim=1)
print(round(nt_xent(z, 0.5).item(), 4), round(nt_xent(z, 0.1).item(), 4))
0.291 0.0014

A training step: make two views of each image, encode and project all 2N2N views, compute this loss, then backward() and the optimizer (P2.7). After training, drop the projection head.

Common mistakes

Quiz

Check your understanding

  1. In a contrastive batch of NN images, each with two augmented views, how many negatives does one view have in the NT-Xent loss?

  2. You train an encoder with a loss that only asks the two views of one image to have high cosine similarity, with no negatives and nothing else. What is the most likely failure?

  3. In SimCLR, what is done with the projection head after pretraining?

  4. Why does MoCo give its key encoder a slow moving average of the query encoder, instead of using the query encoder directly?

  5. MAE masks about 75% of the image patches, while BERT hides about 15% of the tokens. What reason does the MAE paper give for the high ratio on images?

Exercises

  1. Using the four views of the worked example, A1A_1 at 0∘0^\circ, A2A_2 at 20∘20^\circ, B1B_1 at 90∘90^\circ and B2B_2 at 110∘110^\circ, compute by hand the loss of the view A2A_2 at τ=1\tau=1. The cosines of A2A_2 with A1A_1, B1B_1 and B2B_2 are 0.9400.940, 0.3420.342 and 00 (use cos⁡70∘=0.342\cos 70^\circ=0.342 and cos⁡90∘=0\cos 90^\circ=0).
    Show answerThe scores are 0.9400.940, 0.3420.342 and 00, so the exponentials are 2.5602.560, 1.4081.408 and 11, which sum to 4.9684.968. The partner probability is 2.560/4.968=0.5152.560/4.968=0.515, and the loss is −ln⁡0.515=0.663-\ln 0.515=0.663. It matches the printed row of the code cell at τ=1.0\tau=1.0 (0.6630.663 for the third view).
  2. A batch has N=256N=256 images with two views each. How many candidates does each view have in NT-Xent, and what is the loss if all embeddings are identical?
    Show answer2N−1=5112N-1=511 candidates, of which 510510 are negatives. With identical embeddings the softmax is uniform, so the loss is ln⁡511≈6.236\ln 511\approx6.236, whatever τ\tau is.
  3. An MAE uses a 14×1414\times14 patch grid and masks 75% of the patches. How many patches does the encoder see, and how many do the masked ones number? What does the encoder see at a 15% ratio, as in BERT?
    Show answer196×0.75=147196\times0.75=147 are masked and 4949 are visible. At 15%, 2929 are masked (196×0.15=29.4196\times0.15=29.4) and 167167 are visible, so the saving is small.

Next: P5.17 shows how small, deliberate changes to a picture can fool a network. P8.13 uses the pull-together, push-apart loss for images and text.

Key takeaways

  • Self-supervised learning makes its own labels from the data. A good encoder is judged by a linear probe (frozen backbone, new linear head, as in P5.10) or by fine-tuning.
  • Contrastive learning: two augmented views of one image are a positive pair, the other images in the batch are negatives. NT-Xent is a softmax cross-entropy over cosine similarities divided by a temperature.
  • SimCLR: crop plus colour distortion, a projection head dropped after training, large batches. MoCo: a queue of negatives and a momentum encoder.
  • Collapse is every image getting the same embedding. Positives alone allow it, negatives forbid it. DINO avoids it without negatives with a momentum teacher, centring and sharpening.
  • MAE masks 75% of the patches, encodes the visible ones and reconstructs the hidden pixels. Images are redundant, so a high ratio is needed.
Found a mistake? Tell us