# facebookresearch/dino architecture

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

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

## Overview

##### Main Components Identification

a) Core Model Components:
- Vision Transformer (ViT) Architecture
- Student Network
- Teacher Network
- Projection Head
- Self-Attention Mechanism

b) Training Pipeline:
- Data Augmentation Pipeline
- Self-Supervised Learning Framework
- Multi-crop Strategy
- Temperature-based Knowledge Distillation

**[Input Layer]**

- ▼
**[Data Augmentation]**

- ┬────────────┐
- ▼            ▼            ▼
**[Global Crops] [Local Crops] [Other Augmentations]**

- ┴────────────┘

- ▼
**┌─────────────────────────┐**
- Student Network      │
- ┌─────────────────┐   │
- ViT Backbone   │   │
- ┘   │
- ┌─────────────────┐   │
- Projection Head  │   │
- ┘   │
- ┘

- ▼
**┌─────────────────────────┐**
- Teacher Network      │
- ┌─────────────────┐   │
- ViT Backbone   │   │
- ┘   │
- ┌─────────────────┐   │
- Projection Head  │   │
- ┘   │
- ┘

- ▼
**[Loss Computation]**

##### Additional Elements

a) Evaluation Components:
- K-NN Classification
- Linear Classification
- Self-attention Visualization
- Video Segmentation
- Image Retrieval
- Copy Detection

b) Model Variants:
- ViT-S/16
- ViT-S/8
- ViT-B/16
- ViT-B/8
- ResNet-50
- XCiT variants

##### Implementation Details to Highlight

- Multi-GPU Training Support
- Distributed Training Capabilities
- Checkpoint Management
- Model Export Formats (ONNX)

##### Notes

- Keep the main flow clear and centered
- Related components together
- Clear data paths between components
- Batch sizes and dimensions where relevant
- Important hyperparameters (temperature, momentum, etc.)

##### Technical Specifications

- Supported Python version (3.6)
- PyTorch version (1.7.1)
- CUDA version (11.0)
- Memory requirements
- GPU requirements

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        I[Input Layer]
    end

    subgraph Augmentation
        DA[Data Augmentation]
        GC[Global Crops]
        LC[Local Crops]
        OA[Other Augmentations]
        
        DA --> GC
        DA --> LC
        DA --> OA
    end

    subgraph "Student Network"
        SN[Student Network Container]
        VB1[ViT Backbone]:::vit
        PH1[Projection Head]
        
        SN --> VB1
        VB1 --> PH1
    end

    subgraph "Teacher Network"
        TN[Teacher Network Container]
        VB2[ViT Backbone]:::vit
        PH2[Projection Head]
        
        TN --> VB2
        VB2 --> PH2
    end

    subgraph Evaluation
        KNN[K-NN Classification]:::knn
        LC1[Linear Classification]:::linear
        SAV[Self-attention Visualization]:::viz
        VS[Video Segmentation]:::video
        IR[Image Retrieval]:::retrieval
        CD[Copy Detection]:::copy
    end

    subgraph "Technical Specs"
        TS1[Python 3.6]
        TS2[PyTorch 1.7.1]
        TS3[CUDA 11.0]
    end

    I --> DA
    GC & LC & OA --> SN
    SN --> TN
    TN --> LOSS[Loss Computation]

    LOSS --> |Backward Pass| SN
    TN -.-> |Momentum Update| SN

    LOSS --> Evaluation

    %% Component Mappings
    click VB1 "https://github.com/facebookresearch/dino/blob/main/vision_transformer.py"
    click KNN "https://github.com/facebookresearch/dino/blob/main/eval_knn.py"
    click LC1 "https://github.com/facebookresearch/dino/blob/main/eval_linear.py"
    click SAV "https://github.com/facebookresearch/dino/blob/main/visualize_attention.py"
    click VS "https://github.com/facebookresearch/dino/blob/main/eval_video_segmentation.py"
    click IR "https://github.com/facebookresearch/dino/blob/main/eval_image_retrieval.py"
    click CD "https://github.com/facebookresearch/dino/blob/main/eval_copy_detection.py"

    %% Styling
    classDef default fill:#f9f9f9,stroke:#333,stroke-width:2px
    classDef vit fill:#d1f2eb,stroke:#333
    classDef knn fill:#f9e79f,stroke:#333
    classDef linear fill:#f5cba7,stroke:#333
    classDef viz fill:#d2b4de,stroke:#333
    classDef video fill:#aed6f1,stroke:#333
    classDef retrieval fill:#a3e4d7,stroke:#333
    classDef copy fill:#f5b7b1,stroke:#333

    %% Legend
    subgraph Legend
        L1[Component]
        L2[ViT Module]:::vit
        L3[Evaluation Module]:::knn
        L4[Data Flow]
        L5[Momentum Update]
    end
```
