# yvanyin/metric3d architecture

> Architecture diagram of the GitHub repository yvanyin/metric3d, 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/yvanyin/metric3d
- Repository: https://github.com/yvanyin/metric3d

## Overview

Metric3D is a monocular geometry foundation model for estimating metric depth and surface normals from a single image. The principal inference path is model construction, image feature encoding, dense decoding, and prediction; the repository also provides multi-dataset training, geometric losses, evaluation utilities, and ONNX export. Training data and model stages are represented separately from inference. Some subsystem links are omitted because the sampled excerpts do not show their runtime wiring.

Main entry points: [`mono/model/model_pipelines/dense_pipeline.py`](https://github.com/yvanyin/metric3d/blob/main/mono/model/model_pipelines/dense_pipeline.py) (Dense pipeline), [`training/mono/tools/train.py`](https://github.com/yvanyin/metric3d/blob/main/training/mono/tools/train.py) (Training entry), [`mono/model/monodepth_model.py`](https://github.com/yvanyin/metric3d/blob/main/mono/model/monodepth_model.py) (Depth model), [`hubconf.py`](https://github.com/yvanyin/metric3d/blob/main/hubconf.py) (Model loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference"]
  node_hub["Model loader<br/>[hubconf.py]"]
  node_model["Depth model<br/>[monodepth_model.py]"]
  node_base["Model wrapper<br/>[__base_model__.py]"]
  node_preprocess["Image transforms<br/>[transform.py]"]
  node_export["ONNX export"]
end

subgraph group_network["Model architecture"]
  node_pipeline["Dense pipeline<br/>[dense_pipeline.py]"]
  node_backbones["Feature backbones<br/>[ViT_DINO.py]"]
  node_hourglass["Hourglass decoder"]
  node_raftdecoder["RAFT depth-normal decoder"]
end

subgraph group_training["Training"]
  node_trainer["Training entry<br/>[train.py]"]
  node_datasets["Dataset loaders"]
  node_sampler["Distributed sampler"]
  node_trainloop["Training loop<br/>[do_train.py]"]
  node_trainmodel["Training model wrapper<br/>[__base_model__.py]"]
  node_losses["Training losses"]
  node_traintransform["Training transforms<br/>[transform.py]"]
  node_weather["Weather augmentation"]
end

subgraph group_support["Geometry and evaluation"]
  node_depthnormal["Depth to normal<br/>[depth_to_normal.py]"]
  node_raindropgen["Raindrop generation<br/>[dropgenerator.py]"]
  node_raindrop["Raindrop effects<br/>[raindrop.py]"]
  node_metrics["Depth metrics<br/>[avg_meter.py]"]
  node_normalmetrics["Normal metrics<br/>[avg_meter.py]"]
end

node_user(("Image user"))

node_user -->|"requests model"| node_hub
node_hub -->|"builds model"| node_model
node_model -->|"inherits wrapper"| node_base
node_base -->|"dispatches pipeline"| node_pipeline
node_pipeline -->|"builds encoder"| node_backbones
node_pipeline -.->|"builds decoder"| node_hourglass
node_pipeline -.->|"builds decoder"| node_raftdecoder
node_user -.->|"prepares image"| node_preprocess
node_trainer -->|"imports sampler"| node_sampler
node_trainer -->|"invokes training"| node_trainloop
node_trainer -.->|"configures training model"| node_trainmodel
node_datasets -.->|"applies transforms"| node_traintransform
node_traintransform -->|"uses augmentation"| node_weather
node_losses -->|"uses conversion"| node_depthnormal
node_raindropgen -->|"uses effects"| node_raindrop
node_model -.->|"exports model"| node_export

click node_hub "https://github.com/yvanyin/metric3d/blob/main/hubconf.py"
click node_model "https://github.com/yvanyin/metric3d/blob/main/mono/model/monodepth_model.py"
click node_base "https://github.com/yvanyin/metric3d/blob/main/mono/model/model_pipelines/__base_model__.py"
click node_pipeline "https://github.com/yvanyin/metric3d/blob/main/mono/model/model_pipelines/dense_pipeline.py"
click node_backbones "https://github.com/yvanyin/metric3d/blob/main/mono/model/backbones/ViT_DINO.py"
click node_hourglass "https://github.com/yvanyin/metric3d/blob/main/mono/model/decode_heads/HourGlassDecoder.py"
click node_raftdecoder "https://github.com/yvanyin/metric3d/blob/main/mono/model/decode_heads/RAFTDepthNormalDPTDecoder5.py"
click node_preprocess "https://github.com/yvanyin/metric3d/blob/main/mono/utils/transform.py"
click node_export "https://github.com/yvanyin/metric3d/blob/main/onnx/metric3d_onnx_export.py"
click node_trainer "https://github.com/yvanyin/metric3d/blob/main/training/mono/tools/train.py"
click node_datasets "https://github.com/yvanyin/metric3d/blob/main/training/mono/datasets/__base_dataset__.py"
click node_sampler "https://github.com/yvanyin/metric3d/blob/main/training/mono/datasets/distributed_sampler.py"
click node_trainloop "https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/do_train.py"
click node_trainmodel "https://github.com/yvanyin/metric3d/blob/main/training/mono/model/__base_model__.py"
click node_losses "https://github.com/yvanyin/metric3d/blob/main/training/mono/model/losses/NormalBranchLoss.py"
click node_depthnormal "https://github.com/yvanyin/metric3d/blob/main/training/mono/model/losses/depth_to_normal.py"
click node_traintransform "https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/transform.py"
click node_weather "https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/weather_aug_utils.py"
click node_raindropgen "https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/raindropper/dropgenerator.py"
click node_raindrop "https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/raindropper/raindrop.py"
click node_metrics "https://github.com/yvanyin/metric3d/blob/main/mono/utils/avg_meter.py"
click node_normalmetrics "https://github.com/yvanyin/metric3d/blob/main/mono/utils/avg_meter.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_model,node_base,node_preprocess,node_export,node_user toneBlue
class node_pipeline,node_backbones,node_hourglass,node_raftdecoder toneAmber
class node_trainer,node_datasets,node_sampler,node_trainloop,node_trainmodel,node_losses,node_traintransform,node_weather toneMint
class node_depthnormal,node_raindropgen,node_raindrop,node_metrics,node_normalmetrics toneRose
```

## Components

### Inference

- [Model loader](https://github.com/yvanyin/metric3d/blob/main/hubconf.py): `hubconf.py`
- [Depth model](https://github.com/yvanyin/metric3d/blob/main/mono/model/monodepth_model.py): `mono/model/monodepth_model.py`
- [Model wrapper](https://github.com/yvanyin/metric3d/blob/main/mono/model/model_pipelines/__base_model__.py): `mono/model/model_pipelines/__base_model__.py`
- [Image transforms](https://github.com/yvanyin/metric3d/blob/main/mono/utils/transform.py): `mono/utils/transform.py`
- [ONNX export](https://github.com/yvanyin/metric3d/blob/main/onnx/metric3d_onnx_export.py): `onnx/metric3d_onnx_export.py`

### Model architecture

- [Dense pipeline](https://github.com/yvanyin/metric3d/blob/main/mono/model/model_pipelines/dense_pipeline.py): `mono/model/model_pipelines/dense_pipeline.py`
- [Feature backbones](https://github.com/yvanyin/metric3d/blob/main/mono/model/backbones/ViT_DINO.py): `mono/model/backbones/ViT_DINO.py`
- [Hourglass decoder](https://github.com/yvanyin/metric3d/blob/main/mono/model/decode_heads/HourGlassDecoder.py): `mono/model/decode_heads/HourGlassDecoder.py`
- [RAFT depth-normal decoder](https://github.com/yvanyin/metric3d/blob/main/mono/model/decode_heads/RAFTDepthNormalDPTDecoder5.py): `mono/model/decode_heads/RAFTDepthNormalDPTDecoder5.py`

### Training

- [Training entry](https://github.com/yvanyin/metric3d/blob/main/training/mono/tools/train.py): `training/mono/tools/train.py`
- [Dataset loaders](https://github.com/yvanyin/metric3d/blob/main/training/mono/datasets/__base_dataset__.py): `training/mono/datasets/__base_dataset__.py`
- [Distributed sampler](https://github.com/yvanyin/metric3d/blob/main/training/mono/datasets/distributed_sampler.py): `training/mono/datasets/distributed_sampler.py`
- [Training loop](https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/do_train.py): `training/mono/utils/do_train.py`
- [Training model wrapper](https://github.com/yvanyin/metric3d/blob/main/training/mono/model/__base_model__.py): `training/mono/model/__base_model__.py`
- [Training losses](https://github.com/yvanyin/metric3d/blob/main/training/mono/model/losses/NormalBranchLoss.py): `training/mono/model/losses/NormalBranchLoss.py`
- [Training transforms](https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/transform.py): `training/mono/utils/transform.py`
- [Weather augmentation](https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/weather_aug_utils.py): `training/mono/utils/weather_aug_utils.py`

### Geometry and evaluation

- [Depth to normal](https://github.com/yvanyin/metric3d/blob/main/training/mono/model/losses/depth_to_normal.py): `training/mono/model/losses/depth_to_normal.py`
- [Raindrop generation](https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/raindropper/dropgenerator.py): `training/mono/utils/raindropper/dropgenerator.py`
- [Raindrop effects](https://github.com/yvanyin/metric3d/blob/main/training/mono/utils/raindropper/raindrop.py): `training/mono/utils/raindropper/raindrop.py`
- [Depth metrics](https://github.com/yvanyin/metric3d/blob/main/mono/utils/avg_meter.py): `mono/utils/avg_meter.py`
- [Normal metrics](https://github.com/yvanyin/metric3d/blob/main/mono/utils/avg_meter.py): `mono/utils/avg_meter.py`

### Other components

- **Image user**

## Connections

- Image user → Model loader: requests model (evidence: `hubconf.py`)
- Model loader → Depth model: builds model (evidence: `hubconf.py`)
- Depth model → Model wrapper: inherits wrapper (evidence: `mono/model/monodepth_model.py`)
- Model wrapper → Dense pipeline: dispatches pipeline (evidence: `mono/model/model_pipelines/__base_model__.py`)
- Dense pipeline → Feature backbones: builds encoder (evidence: `mono/model/model_pipelines/dense_pipeline.py`)
- Dense pipeline → Hourglass decoder: builds decoder
- Dense pipeline → RAFT depth-normal decoder: builds decoder
- Image user → Image transforms: prepares image
- Training entry → Distributed sampler: imports sampler (evidence: `training/mono/tools/train.py`)
- Training entry → Training loop: invokes training (evidence: `training/mono/tools/train.py`)
- Training entry → Training model wrapper: configures training model
- Dataset loaders → Training transforms: applies transforms
- Training transforms → Weather augmentation: uses augmentation (evidence: `training/mono/utils/transform.py`)
- Training losses → Depth to normal: uses conversion (evidence: `training/mono/model/losses/NormalBranchLoss.py`)
- Raindrop generation → Raindrop effects: uses effects (evidence: `training/mono/utils/raindropper/dropgenerator.py`)
- Depth model → ONNX export: exports model
