Search

Search papers and lessons

VICReg: Variance-Invariance-Covariance Regularization

Adrien Bardes, Jean Ponce, Yann LeCun · 2021

VICReg learns image features without labels: it pulls two views of an image together and keeps each embedding dimension spread out and decorrelated, with no negative pairs needed.

On this page

  • Colour = topic mix
  • Linear algebra
  • Discrete math
  • Representation learning
  • Calculus
  • Probability
  • Neural network basics
  • ReadReady to readNot yet

TL;DR

VICReg is a way to train an image encoder without labels. It takes two random views of each photo and asks their embeddings to match, but matching alone has a trivial solution: map every image to the same vector. VICReg blocks that with two penalties on the batch. A variance term keeps every embedding dimension spread out, and a covariance term stops the dimensions from copying each other. It needs no negative pairs, no memory bank and no stop-gradient, and its two branches may have different weights or architectures. With a ResNet-50 backbone it reached 73.2 percent top-1 accuracy on ImageNet with a linear classifier, on par with the state of the art reported in the paper.

Builds on: Self-Supervised Learning, Siamese Network, Representation Collapse, Covariance Matrix · Leads to: later self-supervised methods that add a variance term (no lessons yet)

Why it mattered

Self-supervised pretraining made it possible to learn strong image features from unlabelled photos. By 2021 the leading methods each needed a special trick to avoid collapse. SimCLR needs large batches of negative pairs, BYOL and SimSiam need a Stop-Gradient and an asymmetric predictor, and SwAV needs clustering. VICReg showed that a symmetric, modular loss, with an explicit term against each kind of collapse, could match them on ImageNet.

The benchmark is ImageNet, a collection of about 1.3 million labelled photos in 1000 classes, and the paper pretrains on its images with the labels thrown away.

The design also widened what joint-embedding learning can do. Each branch is regularised on its own, so the two branches can have different weights, different architectures, or even different kinds of input, such as an image and its caption. The paper uses exactly that case to train image-text retrieval on MS-COCO. The variance term can also be bolted onto existing methods, where it steadies training. The paper appeared a few months after Barlow Twins, whose decorrelation idea it reuses.

The problem

Joint-embedding learning runs the same network on two random views of a photo, here two crops followed by colour changes, and trains the outputs to be close. Closeness is the only goal, so the easiest solution is a constant encoder: every image gets the same vector and the loss is zero. The features then carry no information. This is Representation Collapse.

The paper separates two forms. In norm collapse the vectors shrink toward zero. In informational collapse the dimensions carry the same information, so most of the vector is redundant. Earlier methods avoided one or both forms with machinery. Contrastive methods push different images apart and need many negatives per batch. Asymmetric methods use a predictor and a stop-gradient so the two branches cannot agree on a trivial answer. Barlow Twins removes redundancy between dimensions, but it relies on normalising each dimension across the batch, and that normalisation is what the other branch has to match. The question VICReg asks is whether a loss with one explicit term for each form of collapse can avoid trivial solutions without any of that machinery.

How it works

Take a toy batch of three images, each with two views, and an embedding of two dimensions. The real model uses a batch of 2048 images and 8192 embedding dimensions. The steps are the same.

flowchart LR
  A["Image"] --> B["Two random views"]
  B --> C["Encoder f: ResNet-50, 2048 numbers"]
  C --> D["Expander h: embeddings Z and Z prime"]
  D --> E["Invariance: match the two views"]
  D --> F["Variance: keep each dimension spread"]
  D --> G["Covariance: decorrelate the dimensions"]
  1. Make two views. Each image gets two random crops, each followed by colour changes. Check: the two views of image 1 differ in pixels but show the same object.
  2. Encode. A ResNet-50 turns each view into a 2048-number representation. These representations are what you keep after training. Check: the encoder output is saved, the expander below is thrown away.
  3. Expand. The expander is three linear layers of width 8192, with batch normalisation and ReLU after the first two. It maps each representation to an embedding. The paper says this step removes information that differs between the views and spreads the features out, so that decorrelating the embedding dimensions also reduces their dependence. Check: in the toy, each branch gives a 3-by-2 matrix of embeddings. Call the first branch ZZ and the second Z′Z'.
  4. Invariance: match the views. For each image, take the squared distance between its two embeddings and average over the batch. The toy rows of ZZ are (1,0.5)(1, 0.5), (−1,−0.5)(-1, -0.5) and (0,0)(0, 0), and the rows of Z′Z' are (1.2,0.5)(1.2, 0.5), (−0.8,−0.5)(-0.8, -0.5) and (0,0.5)(0, 0.5). The squared distances are 0.040.04, 0.040.04 and 0.250.25, so the invariance term is 0.33/3=0.110.33 / 3 = 0.11. Check: a term near zero means the views agree.
  5. Variance: keep each dimension spread out. For each of the two dimensions, measure the spread of its values across the batch as a standard deviation SS (a tiny constant is added inside the square root for stability). Charge a penalty of max⁡(0,1−S)\max(0, 1 - S), then average over the dimensions. The first column of ZZ is (1,−1,0)(1, -1, 0), with S=1S = 1 and penalty 00. The second is (0.5,−0.5,0)(0.5, -0.5, 0), with S=0.5S = 0.5 and penalty 0.50.5. The average is (0+0.5)/2=0.25(0 + 0.5) / 2 = 0.25. Check: a dimension whose spread is at least 1 costs nothing.
00.511.5200.20.40.60.811.2standard deviation Spenalty
  • variance penalty
The variance penalty is 1 for a collapsed dimension (S = 0), 0.5 at S = 0.5, and zero once the spread reaches 1.
  1. Covariance: decorrelate the dimensions. Centre each dimension, then build the 2×22 \times 2 covariance matrix across the batch. Its diagonal is 11 and 0.250.25. Its off-diagonal entries are 0.50.5, because the second dimension is exactly half the first in the toy. The covariance term adds the squared off-diagonal entries and scales by 1/d1/d: (0.52+0.52)/2=0.25(0.5^2 + 0.5^2) / 2 = 0.25. Check: two dimensions that move together are penalised, and two that move independently cost nothing.
  2. Combine the terms. The paper uses weights λ=25\lambda = 25 for invariance, μ=25\mu = 25 for variance and ν=1\nu = 1 for covariance. To keep the arithmetic short, assume the second branch has the same spread and correlation as the first, so its variance and covariance terms match. Then the loss is 25×0.11+25×(0.25+0.25)+1×(0.25+0.25)=2.75+12.5+0.5=15.7525 \times 0.11 + 25 \times (0.25 + 0.25) + 1 \times (0.25 + 0.25) = 2.75 + 12.5 + 0.5 = 15.75. Check: most of the loss here comes from the variance term, which is the one that pushes the spread up.
  3. Train. The paper trains for 1000 epochs on ImageNet images without labels, with batch size 2048 and base learning rate 0.2. The learning rate is scaled by batch size over 256, so it is 2048/256×0.2=1.62048 / 256 \times 0.2 = 1.6 at full batch. It warms up over the first 10 epochs and then follows a cosine decay. Check: 10 of 1000 epochs is 1 percent of training, so the warm-up is short.

The math

Let Z=[z1,…,zn]Z = [z_1, \dots, z_n] be the nn embeddings from one branch, each with dd dimensions, and Z′Z' the matching embeddings from the other branch. Write zjz^{j} for the vector of the jj-th coordinate across the batch. Write zˉ\bar{z} for the mean embedding.

Definition: VICReg loss

The loss on one batch is

ℓ(Z,Z′)=λ s(Z,Z′)+μ [ v(Z)+v(Z′) ]+ν [ c(Z)+c(Z′) ]\ell(Z, Z') = \lambda\, s(Z, Z') + \mu\,[\,v(Z) + v(Z')\,] + \nu\,[\,c(Z) + c(Z')\,]

where ss is the invariance term, vv the variance term and cc the covariance term. The weights are λ=μ=25\lambda = \mu = 25 and ν=1\nu = 1 in the paper. The loss is summed over all batches of an unlabelled dataset.

Step 4 in symbols: invariance

s(Z,Z′)=1n∑i=1n∥zi−zi′∥22s(Z, Z') = \frac{1}{n} \sum_{i=1}^{n} \lVert z_i - z'_i \rVert_2^2

This is the mean squared Euclidean distance between the two views of each image. The paper does not normalise the vectors first, unlike some related methods.

Step 5 in symbols: variance

v(Z)=1d∑j=1dmax⁡(0, γ−S(zj,ϵ)),S(x,ϵ)=Var(x)+ϵv(Z) = \frac{1}{d} \sum_{j=1}^{d} \max\bigl(0,\ \gamma - S(z^{j}, \epsilon)\bigr), \qquad S(x, \epsilon) = \sqrt{\mathrm{Var}(x) + \epsilon}

Here γ=1\gamma = 1 is the target spread and ϵ=0.0001\epsilon = 0.0001 keeps the square root away from zero. Var(x)\mathrm{Var}(x) is the sample variance of the batch values of one dimension. The paper takes the hinge on the standard deviation rather than the variance, and this matters: the gradient of the variance is close to zero when the values sit near their mean, so a variance hinge would stop pushing exactly when collapse begins.

Step 6 in symbols: covariance

C(Z)=1n−1∑i=1n(zi−zˉ)(zi−zˉ)T,c(Z)=1d∑i≠j[C(Z)]i,j2C(Z) = \frac{1}{n - 1} \sum_{i=1}^{n} (z_i - \bar{z})(z_i - \bar{z})^{T}, \qquad c(Z) = \frac{1}{d} \sum_{i \neq j} \bigl[C(Z)\bigr]_{i,j}^{2}

The off-diagonal entries of C(Z)C(Z) are covariances between different dimensions, so the sum penalises redundancy. Its cost grows with the square of the dimension count: a dd-by-dd matrix has d(d−1)d(d - 1) off-diagonal entries. At d=8192d = 8192 that is 67,100,67267{,}100{,}672 entries per branch per batch.

Step 7 in symbols: the total

Substitute the three terms into the definition. For the toy batch with λ=μ=25\lambda = \mu = 25 and ν=1\nu = 1, the loss is ℓ=25(0.11)+25(0.25+0.25)+1(0.25+0.25)=15.75\ell = 25(0.11) + 25(0.25 + 0.25) + 1(0.25 + 0.25) = 15.75, as in the walkthrough.

Why collapse costs more

Take a batch in which every embedding is the same vector. Each dimension has zero spread, so S=0+0.0001=0.01S = \sqrt{0 + 0.0001} = 0.01 and its hinge is 1−0.01=0.991 - 0.01 = 0.99. The variance term is v=0.99v = 0.99 for each branch. The invariance term is 00, since the views agree, and the covariance term is 00, since there is no spread to correlate. The loss is 25×(0.99+0.99)=49.525 \times (0.99 + 0.99) = 49.5. The spread batch from the walkthrough scores 15.7515.75. Because the collapsed batch scores far worse, gradient descent is pushed away from collapse, even though the invariance term on its own would be happiest there.

Results

ImageNet, linear classification. With a ResNet-50 backbone pretrained for 1000 epochs, a linear classifier on the frozen features reaches 73.2 percent top-1 and 91.1 percent top-5 accuracy. Barlow Twins gets 73.2 and 91.0. BYOL gets 74.3 and 91.6. SimCLR gets 69.3 and 89.0. The linear results are means over three random seeds, and the paper reports that the gap between the worst and best run is under 0.1 points.

ImageNet, semi-supervised. Fine-tuning on 1 percent of the labels gives VICReg 54.8 top-1 and 79.4 top-5. On 10 percent of the labels it gives 69.5 top-1 and 89.5 top-5. BYOL gets 53.2 and 68.8 top-1, and Barlow Twins gets 55.0 and 69.7 top-1.

Transfer to other tasks. A linear classifier on the frozen features gives VICReg 54.3 percent on Places205, 86.6 mAP on VOC07 and 47.0 percent on iNaturalist 2018. Barlow Twins gets 54.1, 86.2 and 46.5. On detection with Faster R-CNN on VOC07+12, VICReg reaches 82.4 AP50, behind Barlow Twins' 82.6 and the top three methods. On COCO it reaches 39.4 detection AP and 36.4 segmentation AP. The paper describes this as on par with most methods and slightly behind the top three on detection.

Image-text retrieval on MS-COCO 5K. Pretraining on image-caption pairs, with a ResNet-152 for images and a word embedding followed by a GRU for text, gives VICReg 33.6 / 62.7 / 77.9 recall at 1, 5 and 10 for image-to-text retrieval (recall at kk is the share of queries whose correct match appears among the top kk results), and 45.2 / 76.1 / 84.2 for text-to-image. Barlow Twins gets 31.4 / 60.4 / 75.1 and 42.9 / 74.0 / 83.5. The contrastive VSE++ loss gets 30.3 / 59.4 / 72.4 and 41.3 / 71.1 / 81.2.

Adding the variance term to other methods. With the BYOL setup, the variance term alone lifts top-1 linear accuracy from 69.3 to 70.2 at 100 epochs. Adding covariance brings it to 69.5. In the SimSiam setup, the variance term moves 67.9 to 68.1, and adding covariance gives 67.6. Without any regulariser, VICReg's own architecture without a stop-gradient or momentum encoder collapses. With the variance term it reaches 56.2 to 57.5, and with variance and covariance together 67.3 to 68.7.

Weight sharing and architectures. Linear accuracy at 100 epochs is 68.6 with shared weights, 66.5 with separate weights, and 68.1 when the branches use a ResNet-50 and a ResNet-101. Barlow Twins drops from 68.7 with shared weights to 64.2 with separate weights, and VICReg is 2.8 points ahead of it with a ResNet-50 and ResNet-101 pair.

Limits. Only the linear ImageNet results were repeated over seeds. The paper states that time did not allow repeats for the semi-supervised, transfer and analysis experiments, so single-run differences of about a point should be read with care. VICReg does not beat the best methods on every benchmark: detection is slightly behind the top three. The analysis experiments use 100 epochs, not 1000, and the paper says the conclusions carry over.

Reading guide

Check yourself

QuestionName the three terms of the VICReg loss and the failure each one prevents.Show answer

Invariance pulls the two views of an image together, which is the goal of the task. Variance keeps the spread of each embedding dimension above a target, which prevents norm collapse, where all vectors shrink toward a point. Covariance pushes the off-diagonal covariances toward zero, which prevents informational collapse, where the dimensions carry the same information.

QuestionOne embedding dimension takes the batch values 0.25, −0.25 and 0. With γ = 1 and ε = 0, what is its variance penalty?Show answer

The mean is 0. The sample variance is (0.0625+0.0625+0)/2=0.0625(0.0625 + 0.0625 + 0) / 2 = 0.0625. The standard deviation is S=0.0625=0.25S = \sqrt{0.0625} = 0.25. The penalty is max⁡(0,1−0.25)=0.75\max(0, 1 - 0.25) = 0.75.

QuestionWhy does the paper take the hinge on the standard deviation rather than on the variance?Show answer

The gradient of the variance with respect to a value is close to zero when that value is near the batch mean. The gradient of the standard deviation does not vanish that way. A hinge on the variance would therefore stop pushing the embeddings apart just as they begin to collapse.

QuestionA team pretrains a vision encoder and a text encoder with separate weights and different architectures. Why might VICReg suit this better than BYOL or SimSiam?Show answer

VICReg regularises each branch independently with its own variance and covariance terms, and it needs no shared weights, no predictor and no stop-gradient. BYOL and SimSiam rely on an asymmetry between the branches, such as a predictor or a momentum encoder, that depends on the branches being built alike. The paper's weight-sharing results show VICReg losing less accuracy than Barlow Twins when the branches are made different.

Sources

Read the full paper

Adrien Bardes, Jean Ponce, Yann LeCun, 2021. arXiv:2105.04906