# openmedlab/retfound_mae architecture

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

- Interactive diagram: https://gitdiagram.com/openmedlab/retfound_mae
- Repository: https://github.com/openmedlab/retfound_mae

## Overview

RETFound is a retinal-image foundation model, with this repository chiefly providing supervised fine-tuning and evaluation of pretrained weights. The workflow is: an engineer configures a task and dataset, the entry point builds image loaders and a ViT classifier, the training engine updates it, and evaluation reports disease-classification metrics. The repository also includes a masked-autoencoder architecture representing the self-supervised pretraining approach. The README documents pretraining and adaptation capabilities, but the supplied tree has no pretraining runner; that branch is therefore limited to the architecture. Edges reflect excerpts, indexed references, or README statements.

Main entry points: [`main_finetune.py`](https://github.com/openmedlab/retfound_mae/blob/main/main_finetune.py) (Fine-tune entry), [`engine_finetune.py`](https://github.com/openmedlab/retfound_mae/blob/main/engine_finetune.py) (Train and evaluate), [`models_mae.py`](https://github.com/openmedlab/retfound_mae/blob/main/models_mae.py) (Masked autoencoder), [`util/pos_embed.py`](https://github.com/openmedlab/retfound_mae/blob/main/util/pos_embed.py) (Position embeddings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Fine-tuning workflow"]
  node_entry["Fine-tune entry<br/>[main_finetune.py]"]
  node_images["Image datasets<br/>[datasets.py]"]
  node_engine["Train and evaluate<br/>[engine_finetune.py]"]
end

subgraph group_models["Model architectures"]
  node_vit["ViT classifier<br/>[models_vit.py]"]
  node_mae["Masked autoencoder<br/>[models_mae.py]"]
  node_position["Position embeddings<br/>[pos_embed.py]"]
end

subgraph group_training["Training support"]
  node_decay["Layer-wise decay<br/>[lr_decay.py]"]
  node_schedule["Learning-rate schedule<br/>[lr_sched.py]"]
  node_distributed["Distributed utilities<br/>[misc.py]"]
end

subgraph group_artifacts["Weights and results"]
  node_weights["Pretrained weights"]
  node_results["Metrics and checkpoints"]
end

node_engineer(("Engineer"))

node_engineer -->|"configures task"| node_entry
node_entry -->|"builds loaders"| node_images
node_entry -->|"constructs model"| node_vit
node_entry -->|"interpolates embeddings"| node_position
node_entry -->|"groups parameters"| node_decay
node_entry -->|"sets up training"| node_distributed
node_entry -->|"runs epochs"| node_engine
node_entry -->|"loads fine-tune weights"| node_weights
node_engine -->|"adjusts learning rate"| node_schedule
node_engine -->|"logs and synchronizes"| node_distributed
node_engine -->|"writes evaluation metrics"| node_results
node_entry -->|"saves checkpoints"| node_results
node_mae -->|"initializes embeddings"| node_position
node_engineer -.->|"uses pretrained approach"| node_mae

click node_entry "https://github.com/openmedlab/retfound_mae/blob/main/main_finetune.py"
click node_images "https://github.com/openmedlab/retfound_mae/blob/main/util/datasets.py"
click node_vit "https://github.com/openmedlab/retfound_mae/blob/main/models_vit.py"
click node_mae "https://github.com/openmedlab/retfound_mae/blob/main/models_mae.py"
click node_position "https://github.com/openmedlab/retfound_mae/blob/main/util/pos_embed.py"
click node_engine "https://github.com/openmedlab/retfound_mae/blob/main/engine_finetune.py"
click node_decay "https://github.com/openmedlab/retfound_mae/blob/main/util/lr_decay.py"
click node_schedule "https://github.com/openmedlab/retfound_mae/blob/main/util/lr_sched.py"
click node_distributed "https://github.com/openmedlab/retfound_mae/blob/main/util/misc.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_entry,node_images,node_engine toneBlue
class node_vit,node_mae,node_position toneAmber
class node_decay,node_schedule,node_distributed toneMint
class node_weights,node_results toneRose
class node_engineer toneIndigo
```

## Components

### Fine-tuning workflow

- [Fine-tune entry](https://github.com/openmedlab/retfound_mae/blob/main/main_finetune.py): `main_finetune.py`
- [Image datasets](https://github.com/openmedlab/retfound_mae/blob/main/util/datasets.py): `util/datasets.py`
- [Train and evaluate](https://github.com/openmedlab/retfound_mae/blob/main/engine_finetune.py): `engine_finetune.py`

### Model architectures

- [ViT classifier](https://github.com/openmedlab/retfound_mae/blob/main/models_vit.py): `models_vit.py`
- [Masked autoencoder](https://github.com/openmedlab/retfound_mae/blob/main/models_mae.py): `models_mae.py`
- [Position embeddings](https://github.com/openmedlab/retfound_mae/blob/main/util/pos_embed.py): `util/pos_embed.py`

### Training support

- [Layer-wise decay](https://github.com/openmedlab/retfound_mae/blob/main/util/lr_decay.py): `util/lr_decay.py`
- [Learning-rate schedule](https://github.com/openmedlab/retfound_mae/blob/main/util/lr_sched.py): `util/lr_sched.py`
- [Distributed utilities](https://github.com/openmedlab/retfound_mae/blob/main/util/misc.py): `util/misc.py`

### Weights and results

- **Pretrained weights**
- **Metrics and checkpoints**

### Other components

- **Engineer**

## Connections

- Engineer → Fine-tune entry: configures task (evidence: `README.md`)
- Fine-tune entry → Image datasets: builds loaders (evidence: `main_finetune.py`)
- Fine-tune entry → ViT classifier: constructs model (evidence: `main_finetune.py`)
- Fine-tune entry → Position embeddings: interpolates embeddings (evidence: `main_finetune.py`)
- Fine-tune entry → Layer-wise decay: groups parameters (evidence: `main_finetune.py`)
- Fine-tune entry → Distributed utilities: sets up training (evidence: `main_finetune.py`)
- Fine-tune entry → Train and evaluate: runs epochs (evidence: `main_finetune.py`)
- Fine-tune entry → Pretrained weights: loads fine-tune weights (evidence: `README.md`)
- Train and evaluate → Learning-rate schedule: adjusts learning rate (evidence: `engine_finetune.py`)
- Train and evaluate → Distributed utilities: logs and synchronizes (evidence: `engine_finetune.py`)
- Train and evaluate → Metrics and checkpoints: writes evaluation metrics (evidence: `engine_finetune.py`)
- Fine-tune entry → Metrics and checkpoints: saves checkpoints (evidence: `main_finetune.py`)
- Masked autoencoder → Position embeddings: initializes embeddings (evidence: `models_mae.py`)
- Engineer → Masked autoencoder: uses pretrained approach (evidence: `README.md`)
