How yvanyin/metric3d works
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: dense_pipeline.py Dense pipeline · train.py Training entry · monodepth_model.py Depth model · hubconf.py Model loader
Components 23
Inference
- Model loader
hubconf.py - Depth model
mono/model/monodepth_model.py - Model wrapper
mono/model/model_pipelines/__base_model__.py - Image transforms
mono/utils/transform.py - ONNX export
onnx/metric3d_onnx_export.py
Model architecture
- Dense pipeline
mono/model/model_pipelines/dense_pipeline.py - Feature backbones
mono/model/backbones/ViT_DINO.py - Hourglass decoder
mono/model/decode_heads/HourGlassDecoder.py - RAFT depth-normal decoder
mono/model/decode_heads/RAFTDepthNormalDPTDecoder5.py
Training
- Training entry
training/mono/tools/train.py - Dataset loaders
training/mono/datasets/__base_dataset__.py - Distributed sampler
training/mono/datasets/distributed_sampler.py - Training loop
training/mono/utils/do_train.py - Training model wrapper
training/mono/model/__base_model__.py - Training losses
training/mono/model/losses/NormalBranchLoss.py - Training transforms
training/mono/utils/transform.py - Weather augmentation
training/mono/utils/weather_aug_utils.py
Geometry and evaluation
- Depth to normal
training/mono/model/losses/depth_to_normal.py - Raindrop generation
training/mono/utils/raindropper/dropgenerator.py - Raindrop effects
training/mono/utils/raindropper/raindrop.py - Depth metrics
mono/utils/avg_meter.py - Normal metrics
mono/utils/avg_meter.py
Other components
- Image user
Connections 16
- Image user → Model loader: requests model
hubconf.py - Model loader → Depth model: builds model
hubconf.py - Depth model → Model wrapper: inherits wrapper
mono/model/monodepth_model.py - Model wrapper → Dense pipeline: dispatches pipeline
mono/model/model_pipelines/__base_model__.py - Dense pipeline → Feature backbones: builds encoder
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
training/mono/tools/train.py - Training entry → Training loop: invokes training
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
training/mono/utils/transform.py - Training losses → Depth to normal: uses conversion
training/mono/model/losses/NormalBranchLoss.py - Raindrop generation → Raindrop effects: uses effects
training/mono/utils/raindropper/dropgenerator.py - Depth model → ONNX export: exports model