SwAV (Swapping Assignments between Views) is a self-supervised learning algorithm that learns visual representations by enforcing consistency between cluster assignments of differently augmented views of the same image. It operates by using a codebook of trainable prototype vectors to perform online clustering on one view's features, generating a "code" (a soft assignment over prototypes). The model is then trained to predict this code from the features of another augmented view of the same image, using a cross-entropy loss. This clustering pretext task avoids the need for explicit negative sample pairs, making it computationally efficient.
Glossary
SwAV

What is SwAV?
SwAV (Swapping Assignments between Views) is a self-supervised learning method that uses online clustering to generate supervisory signals from unlabeled data.
The method's core innovation is the swapped prediction objective, which learns an invariant mapping from different data augmentations to a shared set of semantic concepts represented by the prototypes. By performing clustering online (i.e., synchronously with network updates on each batch), SwAV avoids the computational overhead of an offline clustering step. This architecture is highly relevant for continual self-supervised learning, as the online clustering mechanism can theoretically adapt to evolving data streams, though it requires careful management to prevent feature drift and catastrophic forgetting of past cluster structures.
Key Features of SwAV
SwAV (Swapping Assignments between Views) is a self-supervised learning method that uses online clustering to generate supervisory signals from unlabeled data. Its core innovation is learning by predicting the cluster assignment of one augmented view from another, eliminating the need for explicit negative pairs.
Online Clustering for Self-Supervision
SwAV's core mechanism is online clustering within a mini-batch. During the forward pass, image embeddings are assigned to prototype vectors (learnable cluster centroids) using the Sinkhorn-Knopp algorithm. This creates a 'code' (a soft cluster assignment) for each view. The model learns by predicting the code of one view from the embedding of another, creating a cross-view prediction task that drives representation learning without manual labels.
Sinkhorn-Knopp Algorithm for Code Assignment
To avoid trivial solutions where all samples collapse to a single cluster, SwAV uses the Sinkhorn-Knopp algorithm. This iterative, differentiable algorithm enforces an equipartition constraint, ensuring the mini-batch's embeddings are evenly distributed across the prototypes. This prevents representation collapse and ensures the clustering produces meaningful, diverse supervisory signals. It acts as a form of online regularization during training.
Swapped Prediction Objective
The learning objective is a swapped prediction problem. For two augmented views of the same image, the model must predict the code (cluster assignment) of view B using only the feature representation of view A, and vice-versa. The loss function is the cross-entropy between the predicted code and the target code generated by the online clustering. This symmetric loss forces the model to learn augmentation-invariant features that capture the semantic content shared between different views.
Elimination of Explicit Negative Pairs
Unlike contrastive methods like SimCLR or MoCo, SwAV is a non-contrastive method. It does not require maintaining a large memory bank or constructing explicit negative pairs for comparison. The supervisory signal comes entirely from the cluster assignments and the swapped prediction task. This makes SwAV more memory-efficient and computationally scalable, as it avoids the quadratic cost of comparing all pairs in a batch.
Multi-Crop Strategy
SwAV introduced a multi-crop data augmentation strategy. Instead of just two global views, it uses:
- Two standard-resolution crops (e.g., 224x224 pixels).
- Several additional low-resolution crops (e.g., 96x96 pixels). All crops from the same image share the same cluster code. This increases the number of positive pairs per image and provides a multi-scale supervisory signal, forcing the model to recognize objects across varying scales and contexts, which improves representation robustness.
Compatibility with Continual Learning
SwAV's online, clustering-based learning paradigm is inherently suited for continual learning on data streams. Because it generates labels on-the-fly, it can process non-stationary, unlabeled data without predefined tasks. Key considerations for continual adaptation include:
- Managing prototype drift as new concepts emerge.
- Preventing catastrophic forgetting of old cluster structures.
- This makes SwAV a foundational technique for continual self-supervised learning, where a model must learn new visual concepts over time without forgetting.
SwAV vs. Other SSL Methods
A technical comparison of SwAV's core mechanisms against other prominent self-supervised learning approaches, highlighting architectural and efficiency trade-offs.
| Feature / Mechanism | SwAV (Swapping Assignments) | Contrastive (e.g., SimCLR, MoCo) | Non-Contrastive (e.g., BYOL, Barlow Twins) |
|---|---|---|---|
Core Learning Signal | Online clustering & code swapping | Explicit positive/negative sample comparison | Architectural asymmetry & feature regularization |
Requires Explicit Negative Pairs | |||
Momentum Encoder / Target Network | MoCo: true, SimCLR: false | ||
Large Batch Size Dependency | |||
Memory Bank / Queue | Prototypes (cluster centroids) | MoCo: true, SimCLR: false | |
Primary Loss Function | Swapped prediction loss | InfoNCE / NT-Xent loss | Mean squared error / Redundancy reduction |
Computational Efficiency (vs. SimCLR) | High (avoids pairwise comparisons) | Low (scales with batch size) | Medium |
Typical Linear Evaluation Accuracy (ImageNet) | ~75.3% | ~74.2% (SimCLR) | ~74.3% (BYOL) |
Frequently Asked Questions
SwAV (Swapping Assignments between Views) is a cornerstone self-supervised learning method for continuous model learning. This FAQ addresses its core mechanics, advantages, and role in modern AI pipelines.
SwAV (Swapping Assignments between Views) is a self-supervised learning algorithm that uses online clustering to generate supervisory signals from unlabeled images. It works by creating multiple augmented views of an image, assigning each view to a set of trainable prototype vectors (cluster centroids) via a Sinkhorn-Knopp algorithm, and then training the network to predict the cluster assignment of one view from the representation of another. This swap prediction objective avoids the need for explicit pairwise comparisons, making it computationally efficient.
Key Steps:
- Multi-crop Augmentation: Generate two global views and several smaller local views of an image.
- Online Clustering: Pass views through the encoder and project features to a lower-dimensional space. Assign each projected feature to a prototype code via optimal transport.
- Swap Prediction: Compute a cross-entropy loss where the code from one view is predicted using the feature from another, swapped view.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
SwAV operates within the broader ecosystem of self-supervised and continual learning. These related concepts define its mechanisms, objectives, and evaluation context.
Contrastive Learning
A foundational self-supervised technique where a model learns by pulling positive pairs (different views of the same data) together in an embedding space while pushing negative pairs (views from different data) apart. SwAV builds upon this by replacing explicit negative pairs with online clustering assignments, which act as a more efficient supervisory signal. Core objectives include alignment (similarity for positives) and uniformity (even distribution of all embeddings).
Online Clustering
The core mechanism of SwAV. It dynamically assigns data points to prototype vectors (cluster centroids) during training, without pre-computing a fixed dataset clustering.
- Sinkhorn-Knopp Algorithm: Used to enforce balanced cluster assignments, preventing collapse where all inputs map to a single prototype.
- Swapped Prediction: The model learns to predict the cluster code of one augmented view from the representation of another, creating a robust learning objective from unlabeled data.
Non-Contrastive Learning
A category of self-supervised methods, including BYOL and Barlow Twins, that learn useful representations without using negative samples. SwAV shares this efficiency goal but uses a different mechanism. While non-contrastive methods often rely on architectural tricks like stop-gradient and predictor networks, SwAV uses clustering to generate discrete targets, avoiding the need to compare against a large batch of negatives.
Momentum Encoder
A slowly updated copy of the main model, central to frameworks like MoCo. While SwAV does not strictly require a momentum encoder, the concept is related to maintaining consistency. In SwAV, the prototype vectors are updated using an exponential moving average of the representations, providing a stable target for the clustering assignments, analogous to how a momentum encoder provides stable features for contrastive learning.
Continual Self-Supervised Learning
The problem setting where a model must learn representations from a non-stationary stream of unlabeled data. SwAV is a strong candidate for this setting due to its online nature and lack of dependency on curated negative batches. Key challenges include feature drift and maintaining plasticity for new data while retaining useful features for past data distributions, a core focus of the Continuous Model Learning Systems pillar.
Linear Evaluation Protocol
The standard benchmark for evaluating the quality of representations learned by self-supervised methods like SwAV.
- A linear classifier (a single fully-connected layer) is trained on top of the frozen pretrained encoder using a labeled dataset (e.g., ImageNet).
- High accuracy indicates the encoder has learned general, transferable features.
- This protocol decouples representation learning from supervised fine-tuning, providing a clear measure of pretraining efficacy.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us