Search

Search papers and lessons

Barlow Twins: Self-Supervised Learning via Redundancy Reduction

Jure Zbontar, Li Jing, Ishan Misra et al. · 2021

Barlow Twins learns image features by making two augmented views agree while decorrelating the embedding components, with a loss that needs no negative pairs or asymmetric tricks.

On this page

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

TL;DR

Barlow Twins is a method for learning image features without labels. It shows a network two randomly distorted versions of each image and asks the two outputs to match, but it also asks the output components to be uncorrelated with each other. The loss is built from the cross-correlation matrix between the two views, which it pushes toward the identity matrix. That design avoids the trivial solution where every image gets the same output, without negative pairs, prediction networks or stop-gradients. With ResNet-50 features and a linear classifier, it reached 73.2 percent top-1 accuracy on ImageNet.

Builds on: Self-Supervised Learning, Siamese Network, Correlation Coefficient · Leads to: VICReg: Variance-Invariance-Covariance Regularization

Why it mattered

Self-supervised pretraining on images became the standard way to get strong features from unlabelled photos, and many of the leading methods of 2020 and 2021 used some mix of negative pairs, momentum encoders and asymmetric networks to stop their features from collapsing. Barlow Twins showed that a single symmetric loss with none of that machinery could come close to them on the paper's benchmarks. Its specific strengths were robustness to small batches and continued gains as the embedding grew to 8192 dimensions. Later work built on the same idea; VICReg is the clearest example in this graph.

The problem

The goal is a network whose output vectors stay the same when an image is cropped, recoloured or blurred. The common way to get that is to make the outputs of two augmented views of the same image similar, which is a Siamese Network objective.

That objective has an obvious cheat. If the network outputs the same constant vector for every input, the two views always agree and the loss is zero, yet the features carry no information. This is called collapse. Before this paper, the standard fixes were:

  • Contrastive methods such as SimCLR push apart the outputs of different images, so collapse is penalised. They need many negatives per batch, so they work best with large batches.
  • Asymmetric methods such as BYOL and SimSiam add a predictor network and a Stop-Gradient on one branch, so the two branches cannot settle into the same trivial answer.
  • Clustering and momentum methods such as SwAV and MoCo add their own mechanisms to avoid trivial solutions.

Each fix works, but each adds machinery that is easy to get wrong and expensive to tune. The question the paper asks is whether a single, symmetric loss can avoid collapse by construction.

How it works

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

flowchart LR
  A["Image"] --> B["Two random augmentations"]
  B --> C["Encoder: ResNet-50, 2048-d representation"]
  C --> D["Projector: embeddings Z_A and Z_B"]
  D --> E["Cross-correlation matrix C"]
  E --> F["Loss: diagonal to 1, off-diagonal to 0"]
  1. Make two views. Each image gets two random augmentations, such as a crop, a flip, a colour change or a blur. Stack the views into two batches, YAY^A and YBY^B, one row per image. 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. The paper keeps this representation for downstream tasks. Check: the representation is the output used later, not the projector output.

  3. Project. A projector network maps each representation to an embedding, ZAZ_A and ZBZ_B. In the paper the projector has three layers of 8192 units each. Check: in the toy, each view gives a 3-by-2 matrix of embeddings.

  4. Standardise each column. Subtract each dimension's mean over the batch and divide by its spread. After this, every column has mean zero. In the toy, the columns are:

    • View A, dimension 1: (1,−1,0)(1, -1, 0), and dimension 2: (1,0,−1)(1, 0, -1).
    • View B, dimension 1: (1,−1,0)(1, -1, 0), and dimension 2: (0,1,−1)(0, 1, -1).

    Check: each column sums to zero.

  5. Compute the cross-correlation matrix. Entry CijC_{ij} measures how well dimension ii of view A matches dimension jj of view B across the batch. For the toy:

    • C11=(1+1+0)/(22)=1C_{11} = (1+1+0)/(\sqrt{2}\sqrt{2}) = 1.
    • C22=(0+0+1)/(22)=0.5C_{22} = (0+0+1)/(\sqrt{2}\sqrt{2}) = 0.5.
    • C12=(0−1+0)/(22)=−0.5C_{12} = (0-1+0)/(\sqrt{2}\sqrt{2}) = -0.5.
    • C21=(1+0+0)/(22)=0.5C_{21} = (1+0+0)/(\sqrt{2}\sqrt{2}) = 0.5.

    Check: every entry lies between −1-1 and 11, as it must for a correlation.

  6. Score the matrix. The loss rewards diagonal entries near 1 and off-diagonal entries near 0. With a trade-off weight λ=0.5\lambda = 0.5 (a toy value), the diagonal term is (1−1)2+(1−0.5)2=0.25(1-1)^2 + (1-0.5)^2 = 0.25 and the off-diagonal term is (−0.5)2+(0.5)2=0.5(-0.5)^2 + (0.5)^2 = 0.5, so the loss is 0.25+0.5×0.5=0.50.25 + 0.5 \times 0.5 = 0.5. Check: a perfect solution would make CC the identity and the loss zero.

  7. Update the network. Gradient descent changes the encoder and projector so that the diagonal rises toward 1 and the off-diagonal entries fall toward 0. The first term makes the views agree, which is the invariance. The second makes the embedding dimensions carry different information, which is the redundancy reduction.

  8. Keep the features. After training, drop the projector and use the 2048-number representations for a linear classifier, for semi-supervised fine-tuning or for transfer. Check: a collapsed network would fail the second term, because all dimensions would be perfectly correlated.

At full scale the matrix is 8192×8192=67,108,8648192 \times 8192 = 67{,}108{,}864 entries, and 67,100,67267{,}100{,}672 of them are off-diagonal. The off-diagonal entries outnumber the diagonal ones almost 8,192 to 1, so the redundancy term has most of the entries to control. The paper finds that the method benefits from very high-dimensional embeddings, unlike contrastive methods.

The math

The batch has NN images and each embedding has DD dimensions. Both views are standardised over the batch, so each column has mean zero and unit spread. The cross-correlation matrix is

Cij=∑bzb,iA zb,jB∑b(zb,iA)2 ∑b(zb,jB)2,\mathcal{C}_{ij} = \frac{\sum_{b} z^{A}_{b,i}\, z^{B}_{b,j}}{\sqrt{\sum_{b} (z^{A}_{b,i})^{2}}\,\sqrt{\sum_{b} (z^{B}_{b,j})^{2}}},

where bb indexes the images in the batch and i,ji, j index the embedding dimensions. Each entry lies between −1-1 and 11, and it is the correlation between dimension ii of view A and dimension jj of view B.

Step 5 in symbols: the matrix

For the toy batch in the walkthrough, the matrix is the one computed in step 5. Two things are worth noticing. The matrix is not symmetric, because the two views are different inputs passed through the same network. And the diagonal entries carry the invariance signal, while the off-diagonal entries carry the redundancy signal.

Step 6 in symbols: the loss

The paper's loss is

LBT=∑i(1−Cii)2+λ∑i∑j≠iCij2.\mathcal{L}_{BT} = \sum_{i} (1 - \mathcal{C}_{ii})^2 + \lambda \sum_{i} \sum_{j \ne i} \mathcal{C}_{ij}^{2}.

The first sum is the invariance term. It is zero only when each diagonal entry is exactly 1, meaning dimension ii of the two views is perfectly correlated. The second sum is the redundancy reduction term. It is zero only when every off-diagonal entry is zero, meaning different dimensions carry uncorrelated information. The weight λ\lambda balances the two. The paper's search found λ=5×10−3\lambda = 5 \times 10^{-3} best, and reports that performance is not very sensitive to it.

Two properties follow from the formula. Collapse makes every embedding dimension the same up to a constant, so each off-diagonal entry is 1 and the second term is large. And because the loss is built from correlations, it needs no negative pairs: the second term plays the role that contrastive negatives play in other methods, but it works across dimensions rather than across images. So it does not need a large batch to supply hard negatives.

Results

All numbers are from the paper, using ResNet-50 pretrained on unlabelled ImageNet.

Linear evaluation. A linear classifier on frozen features reached 73.2 percent top-1 and 91.0 percent top-5. The comparison set in the paper's table was: supervised 76.5, BYOL 74.3, SwAV 75.3, SimCLR 69.3. So Barlow Twins was competitive, but not the best on this benchmark.

Semi-supervised, few labels. Fine-tuning on 1 percent of ImageNet labels, Barlow Twins reached 55.0 percent top-1, against 53.9 for SwAV, 53.2 for BYOL, 48.3 for SimCLR and 25.4 for supervised training on the same labels. On 10 percent of labels it reached 69.7 percent, behind SwAV's 70.2 and above BYOL's 68.8. This is the regime where the paper claims its clearest advantage.

Transfer. With frozen features, Barlow Twins reached 54.1 percent on Places-205, 86.2 mAP on VOC07 and 46.5 percent on iNaturalist 2018. Supervised training scored 53.2, 87.5 and 46.7 on the same tasks. For detection on VOC07 and 12, its AP was 56.8, against 57.4 for MoCo v2.

Ablations. Ablations use 300 epochs, where the baseline reached 71.4 percent top-1:

  • Invariance term alone: 57.3.
  • Redundancy term alone: 0.1, which is collapse.
  • Normalising along the feature dimension instead of the batch: 69.8.
  • Removing batch normalisation in the projector: 71.2.
  • Cross-entropy with a temperature in place of this loss: 63.3.

Asymmetry. Adding a Stop-Gradient alone gave 70.5, a predictor alone 70.2, and both together 61.3, all below the symmetric baseline of 71.4. The asymmetric tricks that other methods need do not help this one.

Batch size and cost. On a grid over learning rates, accuracy was almost unchanged down to a batch of 256, where SimCLR drops by about 4 points. The best Barlow Twins result, 71.7 percent in the batch-size plot, came at batch 1024. The full run used 1000 epochs at batch 2048 with the LARS optimiser, a layer-wise adaptive learning rate method for large batches, and a cosine decay schedule, taking about 124 hours on 32 V100 GPUs.

What the results do and do not show. It is tempting to think Barlow Twins is just contrastive learning under another name. In fact it has no negative pairs, and its batch-size behaviour is the evidence for that difference. It is tempting to think the invariance term alone would be enough. In fact the redundancy term is what prevents collapse; without it the top-1 accuracy falls to 0.1 percent. And it is tempting to think the method is robust to any augmentations. In fact the paper reports that it is not robust to removing some augmentations, as SimCLR is not, while BYOL is, so the learned invariances follow the augmentations chosen. The experiments use one architecture and one pretraining set, and several comparisons quote numbers from other papers trained under their own settings, so gaps of about a point are not decisive.

When to use it. Use the idea when you want a symmetric, simple objective, when batches are small, or when you want explicit control over which distortions the features ignore. It is also a good fit where a predictor or momentum encoder is awkward to implement. Avoid it when the augmentations are poorly chosen, since the features inherit their gaps, and when the strongest invariance to unknown distortions matters more than simplicity; the paper's augmentation ablation favours BYOL there.

Reading guide

  1. Abstract and Section 1, Introduction. The motivation: invariance-based learning, collapse, and the existing fixes. Read with Self-Supervised Learning, Data Augmentation and Siamese Network in mind.
  2. Section 2.1, Description. The one section to read slowly. It defines the cross-correlation matrix and the loss. Prerequisites: Correlation Coefficient, and the batch standardisation from Batch Normalization.
  3. Section 2.2, Implementation. Algorithm 1 gives the whole method as pseudocode. The optimiser and schedule are specific to the paper; skim them, and note the cosine schedule in Cosine Annealing.
  4. Section 3, Results. Tables 1 and 2 carry the headline claims. For the ideas behind transfer, read Representation Learning and Semi-Supervised Learning.
  5. Section 4, Ablations. Table 5 shows why each term is needed; Table 6 tests the Stop-Gradient and predictor from BYOL.
  6. Section 5, Discussion. A careful comparison with the infoNCE loss used in Contrastive Learning, and the link to whitening. The mutual-information view in Appendix A builds on Mutual Information.

Check yourself

QuestionRecall: what does the invariance term of the loss ask for, and what does the redundancy reduction term ask for?Show answer

The invariance term asks each diagonal entry of the cross-correlation matrix to be 1, so that each embedding dimension is perfectly correlated between the two views of an image. The redundancy reduction term asks each off-diagonal entry to be 0, so that different dimensions carry uncorrelated information. Together they ask for matched views with non-redundant components.

QuestionComputation: two standardised columns are (1,−1,1,−1)(1, -1, 1, -1) and (1,1,−1,−1)(1, 1, -1, -1). What is their entry in the cross-correlation matrix?Show answer

The elementwise products are 1,−1,−1,11, -1, -1, 1, which sum to 00. The entry is 0/(44)=00 / (\sqrt{4}\sqrt{4}) = 0. The two columns are uncorrelated, which is exactly what the redundancy term rewards.

QuestionWhy: why does the paper treat its batch-size result as a difference in kind from contrastive learning, not just a difference in tuning?Show answer

Contrastive methods need negative pairs, and the number of available negatives shrinks with the batch, which hurts them when batches are small. Barlow Twins compares dimensions rather than images, and its loss does not need negatives at all, so its objective does not depend on batch size in the same way. The paper's batch-size results match this: accuracy barely changes down to batch 256, while SimCLR loses about 4 points.

QuestionApplied: you add a predictor network and a stop-gradient to Barlow Twins, as BYOL does, expecting gains. What does the paper suggest will happen, and why?Show answer

The paper found that each asymmetry slightly decreases accuracy, and together they drop it much further, to 61.3 from a baseline of 71.4. Barlow Twins already avoids collapse through its symmetric loss, so the asymmetric tricks solve a problem it does not have, and they add a mismatch between the two branches.

Sources

Read the full paper

Jure Zbontar, Li Jing, Ishan Misra et al., 2021. arXiv:2103.03230