# facebookresearch/swav architecture

> Architecture diagram of the GitHub repository facebookresearch/swav, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/facebookresearch/swav
- Repository: https://github.com/facebookresearch/swav

## Overview

This repository implements SwAV self-supervised visual pretraining, alongside DeepCluster-v2 training, pretrained-backbone distribution, and supervised evaluation workflows. The main path transforms each image into multiple crops, encodes views, computes cluster assignments and swapped-prediction loss, then updates and saves the model. Separate evaluation programs measure frozen-feature linear performance and semi-supervised fine-tuning. The graph follows documented entry points and sampled calls; omitted source details limit finer-grained training and evaluation links.

Main entry points: [`main_deepclusterv2.py`](https://github.com/facebookresearch/swav/blob/main/main_deepclusterv2.py) (DeepCluster entry), [`main_swav.py`](https://github.com/facebookresearch/swav/blob/main/main_swav.py) (SwAV entry), [`src/resnet50.py`](https://github.com/facebookresearch/swav/blob/main/src/resnet50.py) (ResNet backbone), [`hubconf.py`](https://github.com/facebookresearch/swav/blob/main/hubconf.py) (Torch Hub models)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Pretraining"]
  node_swav_entry["SwAV entry<br/>[main_swav.py]"]
  node_swav_train["SwAV training<br/>[main_swav.py]"]
  node_dc_entry["DeepCluster entry"]
  node_dc_train["DeepCluster training"]
  node_swav_state["SwAV checkpoints<br/>[main_swav.py]"]
  node_dc_memory[("Cluster memory")]
  node_runtime_utils["Runtime utilities<br/>[utils.py]"]
end

subgraph group_model["Models and data"]
  node_crops["Multi-crop views"]
  node_resnet["ResNet backbone<br/>[resnet50.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_linear_eval["Linear evaluation<br/>[eval_linear.py]"]
  node_semisup_eval["Semi-supervised evaluation<br/>[eval_semisup.py]"]
end

subgraph group_distribution["Model distribution"]
  node_hub["Torch Hub models<br/>[hubconf.py]"]
  node_weights["Pretrained weights"]
end

node_researcher(("Researcher"))
node_images[("ImageNet images")]
node_downstream_user(("Downstream user"))

node_researcher -->|"starts training"| node_swav_entry
node_researcher -->|"starts training"| node_dc_entry
node_swav_entry -->|"builds dataset"| node_crops
node_images -->|"loads images"| node_crops
node_swav_entry -->|"builds model"| node_resnet
node_swav_entry -->|"initializes runtime"| node_runtime_utils
node_swav_entry -->|"runs epochs"| node_swav_train
node_swav_train -->|"encodes views"| node_resnet
node_swav_train -->|"saves queue and checkpoints"| node_swav_state
node_swav_entry -->|"restores state"| node_swav_state
node_dc_entry -->|"builds dataset"| node_crops
node_dc_entry -->|"builds model"| node_resnet
node_dc_entry -->|"initializes runtime"| node_runtime_utils
node_dc_entry -->|"loads memory"| node_dc_memory
node_dc_entry -->|"runs epochs"| node_dc_train
node_dc_train -->|"encodes views"| node_resnet
node_dc_train -->|"updates assignments"| node_dc_memory
node_dc_entry -->|"saves checkpoints"| node_swav_state
node_researcher -->|"runs evaluation"| node_linear_eval
node_linear_eval -->|"builds backbone"| node_resnet
node_linear_eval -->|"loads pretrained state"| node_swav_state
node_researcher -->|"runs fine-tuning"| node_semisup_eval
node_semisup_eval -->|"builds model"| node_resnet
node_semisup_eval -->|"loads pretrained state"| node_swav_state
node_downstream_user -->|"requests model"| node_hub
node_hub -->|"constructs backbone"| node_resnet
node_hub -.->|"downloads weights"| node_weights
node_weights -.->|"provides parameters"| node_hub
node_hub -->|"returns model"| node_downstream_user

click node_swav_entry "https://github.com/facebookresearch/swav/blob/main/main_swav.py"
click node_swav_train "https://github.com/facebookresearch/swav/blob/main/main_swav.py"
click node_dc_entry "https://github.com/facebookresearch/swav/blob/main/main_deepclusterv2.py"
click node_dc_train "https://github.com/facebookresearch/swav/blob/main/main_deepclusterv2.py"
click node_crops "https://github.com/facebookresearch/swav/blob/main/src/multicropdataset.py"
click node_resnet "https://github.com/facebookresearch/swav/blob/main/src/resnet50.py"
click node_swav_state "https://github.com/facebookresearch/swav/blob/main/main_swav.py"
click node_dc_memory "https://github.com/facebookresearch/swav/blob/main/main_deepclusterv2.py"
click node_runtime_utils "https://github.com/facebookresearch/swav/blob/main/src/utils.py"
click node_linear_eval "https://github.com/facebookresearch/swav/blob/main/eval_linear.py"
click node_semisup_eval "https://github.com/facebookresearch/swav/blob/main/eval_semisup.py"
click node_hub "https://github.com/facebookresearch/swav/blob/main/hubconf.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_swav_entry,node_swav_train,node_dc_entry,node_dc_train,node_swav_state,node_dc_memory,node_runtime_utils,node_downstream_user toneBlue
class node_crops,node_resnet,node_images toneAmber
class node_linear_eval,node_semisup_eval toneMint
class node_hub,node_weights toneRose
class node_researcher toneIndigo
```

## Components

### Pretraining

- [SwAV entry](https://github.com/facebookresearch/swav/blob/main/main_swav.py): `main_swav.py`
- [SwAV training](https://github.com/facebookresearch/swav/blob/main/main_swav.py): `main_swav.py`
- [DeepCluster entry](https://github.com/facebookresearch/swav/blob/main/main_deepclusterv2.py): `main_deepclusterv2.py`
- [DeepCluster training](https://github.com/facebookresearch/swav/blob/main/main_deepclusterv2.py): `main_deepclusterv2.py`
- [SwAV checkpoints](https://github.com/facebookresearch/swav/blob/main/main_swav.py): `main_swav.py`
- [Cluster memory](https://github.com/facebookresearch/swav/blob/main/main_deepclusterv2.py): `main_deepclusterv2.py`
- [Runtime utilities](https://github.com/facebookresearch/swav/blob/main/src/utils.py): `src/utils.py`

### Models and data

- [Multi-crop views](https://github.com/facebookresearch/swav/blob/main/src/multicropdataset.py): `src/multicropdataset.py`
- [ResNet backbone](https://github.com/facebookresearch/swav/blob/main/src/resnet50.py): `src/resnet50.py`

### Evaluation

- [Linear evaluation](https://github.com/facebookresearch/swav/blob/main/eval_linear.py): `eval_linear.py`
- [Semi-supervised evaluation](https://github.com/facebookresearch/swav/blob/main/eval_semisup.py): `eval_semisup.py`

### Model distribution

- [Torch Hub models](https://github.com/facebookresearch/swav/blob/main/hubconf.py): `hubconf.py`
- **Pretrained weights**

### Other components

- **Researcher**
- **ImageNet images**
- **Downstream user**

## Connections

- Researcher → SwAV entry: starts training
- Researcher → DeepCluster entry: starts training
- SwAV entry → Multi-crop views: builds dataset
- ImageNet images → Multi-crop views: loads images
- SwAV entry → ResNet backbone: builds model
- SwAV entry → Runtime utilities: initializes runtime
- SwAV entry → SwAV training: runs epochs
- SwAV training → ResNet backbone: encodes views
- SwAV training → SwAV checkpoints: saves queue and checkpoints
- SwAV entry → SwAV checkpoints: restores state
- DeepCluster entry → Multi-crop views: builds dataset
- DeepCluster entry → ResNet backbone: builds model
- DeepCluster entry → Runtime utilities: initializes runtime
- DeepCluster entry → Cluster memory: loads memory
- DeepCluster entry → DeepCluster training: runs epochs
- DeepCluster training → ResNet backbone: encodes views
- DeepCluster training → Cluster memory: updates assignments
- DeepCluster entry → SwAV checkpoints: saves checkpoints
- Researcher → Linear evaluation: runs evaluation
- Linear evaluation → ResNet backbone: builds backbone
- Linear evaluation → SwAV checkpoints: loads pretrained state
- Researcher → Semi-supervised evaluation: runs fine-tuning
- Semi-supervised evaluation → ResNet backbone: builds model
- Semi-supervised evaluation → SwAV checkpoints: loads pretrained state
- Downstream user → Torch Hub models: requests model
- Torch Hub models → ResNet backbone: constructs backbone
- Torch Hub models → Pretrained weights: downloads weights
- Pretrained weights → Torch Hub models: provides parameters
- Torch Hub models → Downstream user: returns model
