# zhu-xlab/dofa architecture

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

- Interactive diagram: https://gitdiagram.com/zhu-xlab/dofa
- Repository: https://github.com/zhu-xlab/dofa

## Overview

DOFA is a remote-sensing and Earth-observation foundation model designed to process imagery with varying modalities and channel counts. Its lifecycle runs from multimodal pretraining through reusable model inference to GeoBench classification and segmentation fine-tuning/evaluation. The graph includes the documented Torch Hub entrypoint and shared training utilities; source excerpts and the index support the pretraining and downstream links shown. Several README capabilities, including object detection and TorchGeo use, have no implementation path in this tree, so they are noted as documented capabilities rather than mapped to invented components.

Main entry points: [`dofa_v1.py`](https://github.com/zhu-xlab/dofa/blob/master/dofa_v1.py) (DOFA ViT), [`downstream_tasks/geobench_classification/engine.py`](https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_classification/engine.py) (Classification engine), [`downstream_tasks/geobench_segmentation/engine.py`](https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_segmentation/engine.py) (Segmentation engine), [`pretraining/main_pretrain_ofa.py`](https://github.com/zhu-xlab/dofa/blob/master/pretraining/main_pretrain_ofa.py) (Pretrain runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["DOFA model"]
  node_hub["Torch Hub entry<br/>[hubconf.py]"]
  node_vit["DOFA ViT<br/>[dofa_v1.py]"]
  node_dynamic["Dynamic layers"]
  node_inference["Inference output"]
end

subgraph group_pretrain["Pretraining"]
  node_pretrain_main["Pretrain runner"]
  node_eo_data["EO dataset<br/>[ofall_dataset.py]"]
  node_pretrain_engine["Pretrain engine<br/>[engine_pretrain.py]"]
  node_mae["MAE model"]
  node_wave_pretrain["Pretrain dynamic layers"]
  node_train_utils["Training utilities<br/>[misc.py]"]
  node_lr_schedule["Learning-rate schedule<br/>[lr_sched.py]"]
end

subgraph group_classification["Classification"]
  node_class_main["Linear probe runner"]
  node_class_engine["Classification engine<br/>[engine.py]"]
  node_class_result["Class predictions"]
end

subgraph group_segmentation["Segmentation"]
  node_seg_main["Fine-tune runner<br/>[main_finetune.py]"]
  node_seg_model["UPerNet model<br/>[main_finetune.py]"]
  node_seg_engine["Segmentation engine<br/>[engine.py]"]
  node_seg_result["Segmentation output"]
end

node_user(("Model user"))

node_user -->|"loads model"| node_hub
node_hub -->|"creates"| node_vit
node_user -->|"provides imagery"| node_vit
node_vit -->|"uses"| node_dynamic
node_vit -->|"produces features"| node_inference
node_pretrain_main -->|"loads datasets"| node_eo_data
node_pretrain_main -->|"runs epochs"| node_pretrain_engine
node_pretrain_main -->|"builds model"| node_mae
node_pretrain_engine -->|"uses metrics"| node_train_utils
node_pretrain_engine -->|"adjusts learning rate"| node_lr_schedule
node_mae -->|"uses dynamic layers"| node_wave_pretrain
node_class_main -->|"initializes backbone"| node_vit
node_class_main -->|"runs training"| node_class_engine
node_class_engine -->|"uses metrics"| node_train_utils
node_class_engine -->|"adjusts learning rate"| node_lr_schedule
node_class_engine -->|"evaluates predictions"| node_class_result
node_seg_main -->|"constructs model"| node_seg_model
node_seg_main -->|"runs training"| node_seg_engine
node_seg_engine -->|"uses metrics"| node_train_utils
node_seg_engine -->|"adjusts learning rate"| node_lr_schedule
node_seg_model -.->|"uses backbone"| node_vit
node_seg_engine -->|"evaluates masks"| node_seg_result

click node_hub "https://github.com/zhu-xlab/dofa/blob/master/hubconf.py"
click node_vit "https://github.com/zhu-xlab/dofa/blob/master/dofa_v1.py"
click node_dynamic "https://github.com/zhu-xlab/dofa/blob/master/wave_dynamic_layer.py"
click node_pretrain_main "https://github.com/zhu-xlab/dofa/blob/master/pretraining/main_pretrain_ofa.py"
click node_eo_data "https://github.com/zhu-xlab/dofa/blob/master/pretraining/datasets/ofall_dataset.py"
click node_pretrain_engine "https://github.com/zhu-xlab/dofa/blob/master/pretraining/engine_pretrain.py"
click node_mae "https://github.com/zhu-xlab/dofa/blob/master/pretraining/models_base_ofa_mae.py"
click node_wave_pretrain "https://github.com/zhu-xlab/dofa/blob/master/pretraining/wave_dynamic_layer.py"
click node_class_main "https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_classification/main_linear_probe.py"
click node_class_engine "https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_classification/engine.py"
click node_seg_main "https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_segmentation/main_finetune.py"
click node_seg_model "https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_segmentation/main_finetune.py"
click node_seg_engine "https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_segmentation/engine.py"
click node_train_utils "https://github.com/zhu-xlab/dofa/blob/master/pretraining/util/misc.py"
click node_lr_schedule "https://github.com/zhu-xlab/dofa/blob/master/pretraining/util/lr_sched.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_hub,node_vit,node_dynamic,node_inference,node_user toneBlue
class node_pretrain_main,node_eo_data,node_pretrain_engine,node_mae,node_wave_pretrain,node_train_utils,node_lr_schedule toneAmber
class node_class_main,node_class_engine,node_class_result toneMint
class node_seg_main,node_seg_model,node_seg_engine,node_seg_result toneRose
```

## Components

### DOFA model

- [Torch Hub entry](https://github.com/zhu-xlab/dofa/blob/master/hubconf.py): `hubconf.py`
- [DOFA ViT](https://github.com/zhu-xlab/dofa/blob/master/dofa_v1.py): `dofa_v1.py`
- [Dynamic layers](https://github.com/zhu-xlab/dofa/blob/master/wave_dynamic_layer.py): `wave_dynamic_layer.py`
- **Inference output**

### Pretraining

- [Pretrain runner](https://github.com/zhu-xlab/dofa/blob/master/pretraining/main_pretrain_ofa.py): `pretraining/main_pretrain_ofa.py`
- [EO dataset](https://github.com/zhu-xlab/dofa/blob/master/pretraining/datasets/ofall_dataset.py): `pretraining/datasets/ofall_dataset.py`
- [Pretrain engine](https://github.com/zhu-xlab/dofa/blob/master/pretraining/engine_pretrain.py): `pretraining/engine_pretrain.py`
- [MAE model](https://github.com/zhu-xlab/dofa/blob/master/pretraining/models_base_ofa_mae.py): `pretraining/models_base_ofa_mae.py`
- [Pretrain dynamic layers](https://github.com/zhu-xlab/dofa/blob/master/pretraining/wave_dynamic_layer.py): `pretraining/wave_dynamic_layer.py`
- [Training utilities](https://github.com/zhu-xlab/dofa/blob/master/pretraining/util/misc.py): `pretraining/util/misc.py`
- [Learning-rate schedule](https://github.com/zhu-xlab/dofa/blob/master/pretraining/util/lr_sched.py): `pretraining/util/lr_sched.py`

### Classification

- [Linear probe runner](https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_classification/main_linear_probe.py): `downstream_tasks/geobench_classification/main_linear_probe.py`
- [Classification engine](https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_classification/engine.py): `downstream_tasks/geobench_classification/engine.py`
- **Class predictions**

### Segmentation

- [Fine-tune runner](https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_segmentation/main_finetune.py): `downstream_tasks/geobench_segmentation/main_finetune.py`
- [UPerNet model](https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_segmentation/main_finetune.py): `downstream_tasks/geobench_segmentation/main_finetune.py`
- [Segmentation engine](https://github.com/zhu-xlab/dofa/blob/master/downstream_tasks/geobench_segmentation/engine.py): `downstream_tasks/geobench_segmentation/engine.py`
- **Segmentation output**

### Other components

- **Model user**

## Connections

- Model user → Torch Hub entry: loads model (evidence: `README.md`)
- Torch Hub entry → DOFA ViT: creates (evidence: `hubconf.py`)
- Model user → DOFA ViT: provides imagery (evidence: `README.md`)
- DOFA ViT → Dynamic layers: uses (evidence: `dofa_v1.py`)
- DOFA ViT → Inference output: produces features (evidence: `README.md`)
- Pretrain runner → EO dataset: loads datasets (evidence: `pretraining/main_pretrain_ofa.py`)
- Pretrain runner → Pretrain engine: runs epochs (evidence: `pretraining/main_pretrain_ofa.py`)
- Pretrain runner → MAE model: builds model (evidence: `pretraining/main_pretrain_ofa.py`)
- Pretrain engine → Training utilities: uses metrics (evidence: `pretraining/engine_pretrain.py`)
- Pretrain engine → Learning-rate schedule: adjusts learning rate (evidence: `pretraining/engine_pretrain.py`)
- MAE model → Pretrain dynamic layers: uses dynamic layers (evidence: `pretraining/models_base_ofa_mae.py`)
- Linear probe runner → DOFA ViT: initializes backbone (evidence: `downstream_tasks/geobench_classification/main_linear_probe.py`)
- Linear probe runner → Classification engine: runs training (evidence: `downstream_tasks/geobench_classification/main_linear_probe.py`)
- Classification engine → Training utilities: uses metrics (evidence: `downstream_tasks/geobench_classification/engine.py`)
- Classification engine → Learning-rate schedule: adjusts learning rate (evidence: `downstream_tasks/geobench_classification/engine.py`)
- Classification engine → Class predictions: evaluates predictions (evidence: `downstream_tasks/geobench_classification/engine.py`)
- Fine-tune runner → UPerNet model: constructs model (evidence: `downstream_tasks/geobench_segmentation/main_finetune.py`)
- Fine-tune runner → Segmentation engine: runs training (evidence: `downstream_tasks/geobench_segmentation/main_finetune.py`)
- Segmentation engine → Training utilities: uses metrics (evidence: `downstream_tasks/geobench_segmentation/engine.py`)
- Segmentation engine → Learning-rate schedule: adjusts learning rate (evidence: `downstream_tasks/geobench_segmentation/engine.py`)
- UPerNet model → DOFA ViT: uses backbone
- Segmentation engine → Segmentation output: evaluates masks (evidence: `downstream_tasks/geobench_segmentation/engine.py`)
