SwAV (Swapping Assignments between Views) is an online clustering-based self-supervised learning framework that trains a convolutional neural network by predicting the cluster assignments of one augmented view from the representations of another view. Unlike contrastive methods such as SimCLR or MoCo, SwAV does not compute pairwise comparisons between features. Instead, it maps image features to a set of learnable prototype vectors and enforces consistency between the assignment codes produced from different augmentations of the same image. The Sinkhorn-Knopp algorithm is applied to ensure balanced cluster assignments across the batch, preventing the trivial solution where all images collapse to a single prototype.
Glossary
SwAV (Swapping Assignments between Views)

What is SwAV (Swapping Assignments between Views)?
SwAV is a self-supervised learning method that learns visual representations by enforcing consistency between cluster assignments of different augmented views of the same image, without requiring pairwise feature comparisons.
The architecture operates by passing two high-resolution and multiple low-resolution crops through a shared encoder, then computing a swapped prediction problem: the code from one view predicts the features of another. This multi-crop augmentation strategy enforces local-to-global consistency without requiring large batch sizes or a memory bank of negative samples. For medical imaging, SwAV is particularly valuable because it learns semantically meaningful features from unlabeled scans—such as distinguishing anatomical structures in CT and MRI data—without manual annotation. The learned representations transfer effectively to downstream tasks like medical image segmentation and disease classification, making it a powerful pre-training strategy when labeled diagnostic data is scarce.
Key Features of SwAV
SwAV (Swapping Assignments between Views) introduces a clustering-based approach to self-supervised learning that enforces consistency between cluster assignments rather than direct feature comparison, eliminating the need for explicit negative pairs while maintaining computational efficiency.
Online Clustering with Sinkhorn-Knopp
SwAV computes cluster assignments online using the Sinkhorn-Knopp algorithm, an iterative normalization procedure that enforces an equipartition constraint. This ensures that samples within a batch are evenly distributed across clusters, preventing the trivial solution where all representations collapse into a single cluster. The algorithm operates directly on the transport polytope, producing soft assignments that respect both row and column normalization constraints. This approach replaces the need for a large memory bank or queue of negative samples, significantly reducing memory footprint while maintaining representation quality.
Swapped Prediction Mechanism
The core innovation of SwAV is the swapped prediction loss: the model predicts the cluster assignment of one augmented view using the feature representation of another view, and vice versa. Given two views of the same image, the encoder produces features that are mapped to a set of trainable prototype vectors. The loss enforces that the assignment computed from view A matches the features of view B, creating a cross-prediction task. This swapped mechanism implicitly compares all views against all prototypes, providing a rich training signal without requiring pairwise feature comparisons or negative samples.
Multi-Crop Augmentation Strategy
SwAV leverages a multi-crop strategy that generates multiple views at different resolutions from a single image. Standard crops (e.g., 2x224²) capture global context, while smaller crops (e.g., Vx96²) capture local details at reduced computational cost. The loss is applied only between standard-resolution crops, while smaller crops are used as additional targets. This enforces local-to-global consistency: the model learns that a small patch should map to the same cluster as the full image, dramatically improving representation quality without a proportional increase in compute.
Prototype-Based Representation Learning
SwAV maintains a set of learnable prototype vectors that serve as cluster centroids in the embedding space. These prototypes are updated via backpropagation alongside the encoder weights, allowing the clustering structure to adapt during training. The number of prototypes (typically 3,000) is a hyperparameter that controls the granularity of the learned representation. Each prototype captures a distinct visual concept, and the soft assignment of features to these prototypes creates a rich, structured representation that transfers effectively to downstream medical imaging tasks such as organ segmentation and lesion classification.
Equipartition Constraint for Collapse Prevention
SwAV prevents representation collapse through the equipartition constraint enforced by the Sinkhorn-Knopp algorithm. Unlike contrastive methods that rely on negative pairs to push representations apart, SwAV ensures diversity by requiring that each prototype is assigned an equal number of samples on average across the batch. This constraint operates at the batch level and is enforced through an entropy regularization term. The result is a self-organizing system where the model cannot cheat by assigning all samples to a single prototype, maintaining a balanced and informative clustering structure throughout training.
Medical Imaging Adaptation
SwAV is particularly well-suited for medical image pre-training due to its ability to learn from unlabeled scans without requiring large batch sizes or negative pair curation. In radiology and pathology, where annotated data is scarce but unlabeled DICOM archives are abundant, SwAV can pre-train on chest X-rays, CT volumes, or whole slide images to learn clinically relevant features. The prototype vectors often converge to represent anatomical structures and tissue textures, providing a strong initialization for downstream tasks such as tumor detection and disease staging with limited labeled data.
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.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the SwAV self-supervised learning framework, its mechanisms, and its application to medical imaging.
SwAV (Swapping Assignments between Views) is an online clustering-based self-supervised learning method that learns visual representations by enforcing consistency between cluster assignments produced from different augmented views of the same image. Unlike contrastive methods that compare features directly, SwAV operates by computing a 'code' (a soft cluster assignment) for one view and predicting that code from the representation of another view. The core mechanism uses the Sinkhorn-Knopp algorithm to ensure that cluster assignments are evenly distributed across a batch, preventing the trivial solution where all images map to a single cluster. This 'swapped prediction' problem eliminates the need for explicit negative pairs, making the approach computationally efficient and robust to the choice of batch size.
Related Terms
Explore the core mechanisms and related frameworks that contextualize SwAV within the broader landscape of self-supervised representation learning.
Online Clustering
The core paradigm behind SwAV, where cluster assignments are computed on-the-fly for each batch rather than over the entire dataset. This contrasts with offline clustering methods like DeepCluster. The system maintains a set of prototype vectors that act as cluster centroids, and the Sinkhorn-Knopp algorithm ensures balanced assignment across these prototypes to prevent the trivial solution where all representations collapse to a single cluster.
Sinkhorn-Knopp Algorithm
A fast, GPU-friendly iterative normalization procedure that transforms a raw similarity matrix into a doubly stochastic matrix. In SwAV, it enforces an equipartition constraint, ensuring that each prototype receives an equal share of assignments across the batch. This prevents representation collapse by forcing the model to utilize all clusters uniformly, acting as a regularizer without requiring explicit negative pairs.
Multi-Crop Augmentation
A data augmentation strategy integral to SwAV's efficiency. Instead of using only two full-resolution crops, it generates multiple views per image:
- 2 standard large crops (e.g., 224x224) capturing global context
- V additional small crops (e.g., 96x96) capturing local details The loss enforces consistency between cluster assignments of large crops and predictions from small crops, dramatically increasing training signal density without proportional compute cost.
Contrastive Learning vs. SwAV
SwAV fundamentally differs from contrastive methods like SimCLR and MoCo by eliminating the need for explicit negative pairs. Instead of comparing features directly in the embedding space, SwAV compares their cluster assignment codes. This 'swapped prediction' mechanism—predicting the code of one view from the features of another—achieves comparable or superior performance while being computationally more efficient, as it avoids the quadratic cost of pairwise comparisons.
Prototype Vectors
A learnable matrix of K trainable vectors of dimension D, where K is typically set to 3000. These prototypes represent the cluster centroids in the projection space. During training, the model computes the similarity between encoded features and all prototypes, then applies Sinkhorn-Knopp to generate soft assignment codes. The prototypes are optimized via backpropagation alongside the encoder, learning to represent the most discriminative visual concepts in the dataset.
Swapped Prediction Mechanism
The namesake operation of SwAV. Given two views of an image, the model computes a cluster assignment code from one view and predicts it using the features of the other view. This 'swapping' forces the model to learn representations that are invariant to augmentations while being discriminative enough to map to consistent clusters. The loss is a cross-entropy between the predicted softmax probabilities and the Sinkhorn-generated target code.

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