A Transformers-style Python library for monocular depth estimation
Project description
depth_estimation
A Python library for monocular depth estimation.
Provides a unified, modular API for running inference, comparing, and integrating depth estimation models — supporting 8 model families with 20 variants and designed to accommodate new models with minimal friction.
Installation
git clone https://github.com/shriarul5273/depth_estimation.git
cd depth_estimation
pip install -e .
# With dev dependencies
pip install -e ".[dev]"
# With all optional model dependencies
pip install -e ".[all]"
Core Dependencies
| Package | Min Version |
|---|---|
| Python | 3.9 |
| PyTorch | 2.0 |
| torchvision | 0.15 |
| Pillow | 9.0 |
| NumPy | 1.24 |
| matplotlib | 3.6 |
| opencv-python | 4.8 |
| huggingface-hub | 0.16 |
| timm | 0.9.1 |
| einops | 0.6 |
| addict | — |
Optional Dependencies
| Group | Package | Required for |
|---|---|---|
transformers |
transformers>=4.30 |
MiDaS, ZoeDepth |
diffusers |
diffusers>=0.25 |
Marigold-DC |
Quick Start
Pipeline API (Recommended)
from depth_estimation import pipeline
pipe = pipeline("depth-estimation", model="depth-anything-v2-vitb")
result = pipe("image.jpg")
depth_map = result.depth # np.ndarray, float32, (H, W)
colored = result.colored_depth # np.ndarray, uint8, (H, W, 3)
meta = result.metadata # dict with model info
Auto Classes
from depth_estimation import AutoDepthModel, AutoProcessor
# Works with any of the 20 supported variants
model = AutoDepthModel.from_pretrained("zoedepth")
processor = AutoProcessor.from_pretrained("zoedepth")
inputs = processor("image.jpg")
with torch.no_grad():
depth = model(inputs["pixel_values"])
result = processor.postprocess(depth, inputs["original_sizes"])
Batch Inference
results = pipe(["img1.jpg", "img2.jpg", "img3.jpg"])
for r in results:
print(r.depth.shape)
Supported Models
Depth Anything v1
| Variant ID | Backbone | Source |
|---|---|---|
depth-anything-v1-vits |
ViT-S | LiheYoung/depth-anything-small |
depth-anything-v1-vitb |
ViT-B | LiheYoung/depth-anything-base |
depth-anything-v1-vitl |
ViT-L | LiheYoung/depth-anything-large |
Depth Anything v2
| Variant ID | Backbone | Source |
|---|---|---|
depth-anything-v2-vits |
ViT-S | depth-anything/Depth-Anything-V2-Small |
depth-anything-v2-vitb |
ViT-B | depth-anything/Depth-Anything-V2-Base |
depth-anything-v2-vitl |
ViT-L | depth-anything/Depth-Anything-V2-Large |
Depth Anything v3
| Variant ID | Source |
|---|---|
depth-anything-v3-small |
depth-anything/DA3-SMALL |
depth-anything-v3-base |
depth-anything/DA3-BASE |
depth-anything-v3-large |
depth-anything/DA3-LARGE |
depth-anything-v3-giant |
depth-anything/DA3-GIANT |
depth-anything-v3-nested-giant-large |
depth-anything/DA3NESTED-GIANT-LARGE |
depth-anything-v3-metric-large |
depth-anything/DA3METRIC-LARGE |
depth-anything-v3-mono-large |
depth-anything/DA3MONO-LARGE |
ZoeDepth (Metric)
| Variant ID | Source |
|---|---|
zoedepth |
Intel/zoedepth-nyu-kitti |
MiDaS
| Variant ID | Source |
|---|---|
midas-dpt-large |
Intel/dpt-large |
midas-dpt-hybrid |
Intel/dpt-hybrid-midas |
midas-beit-large |
Intel/dpt-beit-large-512 |
Apple DepthPro (Metric)
| Variant ID | Source |
|---|---|
depth-pro |
apple/DepthPro |
Pixel-Perfect Depth
| Variant ID | Source |
|---|---|
pixel-perfect-depth |
gangweix/Pixel-Perfect-Depth |
Marigold-DC (Depth Completion)
| Variant ID | Source |
|---|---|
marigold-dc |
prs-eth/marigold-depth-v1-0 |
Architecture
The library follows the HuggingFace Transformers modular design philosophy:
- Single model, single file — each model's architecture is self-contained
- Shared processor — preprocessing/postprocessing is not duplicated
- Registry-based auto-loading — new models self-register, no core changes needed
- Config inheritance — configs override only what differs from the base
Input → Processor.preprocess() → Model.forward() → Processor.postprocess() → DepthOutput
Adding a New Model
- Create
src/depth_estimation/models/your_model/ - Add
configuration_your_model.py(inheritBaseDepthConfig) - Add
modeling_your_model.py(inheritBaseDepthModel, single file) - Add
__init__.pywithMODEL_REGISTRY.register(...)
That's it — AutoDepthModel, AutoProcessor, and pipeline() will automatically resolve your model.
Running Tests
pip install -e ".[dev]"
pytest tests/ -v
Acknowledgments
This library builds upon the incredible work of the following research teams:
| Model | Repository |
|---|---|
| Depth Anything v1 | github.com/LiheYoung/Depth-Anything |
| Depth Anything v2 | github.com/DepthAnything/Depth-Anything-V2 |
| Depth Anything v3 | github.com/DepthAnything/Depth-Anything-V3 |
| DINOv2 | github.com/facebookresearch/dinov2 |
| DepthPro | github.com/apple/ml-depth-pro |
| ZoeDepth | github.com/isl-org/ZoeDepth |
| MiDaS | github.com/isl-org/MiDaS |
| Pixel-Perfect Depth | github.com/gangweix/Pixel-Perfect-Depth |
| Marigold-DC | github.com/prs-eth/Marigold-DC |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file depth_estimation-0.0.3.tar.gz.
File metadata
- Download URL: depth_estimation-0.0.3.tar.gz
- Upload date:
- Size: 68.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
792f416a166fac1021bd568e961cd2218c53d79c7cb4565cc0da1890758e2bfe
|
|
| MD5 |
d3e9f7aedfe21a4193bc428de3f0d22f
|
|
| BLAKE2b-256 |
98a959bf955933501d186ca3af36e7a6e102ccba6f98219c97db816b8b9a62b4
|
Provenance
The following attestation bundles were made for depth_estimation-0.0.3.tar.gz:
Publisher:
python-publish.yml on shriarul5273/depth_estimation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
depth_estimation-0.0.3.tar.gz -
Subject digest:
792f416a166fac1021bd568e961cd2218c53d79c7cb4565cc0da1890758e2bfe - Sigstore transparency entry: 1051984734
- Sigstore integration time:
-
Permalink:
shriarul5273/depth_estimation@468de021c651b719b83fdd9977d6671d1b7c89fa -
Branch / Tag:
refs/tags/v.0.0.3 - Owner: https://github.com/shriarul5273
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@468de021c651b719b83fdd9977d6671d1b7c89fa -
Trigger Event:
release
-
Statement type:
File details
Details for the file depth_estimation-0.0.3-py3-none-any.whl.
File metadata
- Download URL: depth_estimation-0.0.3-py3-none-any.whl
- Upload date:
- Size: 80.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab4a351cff012c1eb6fa02190bd7b02375c701a0b81a61a81eb2e5ab3ee621da
|
|
| MD5 |
071ab770025ab2c0a526bac4f5fb8b1d
|
|
| BLAKE2b-256 |
190824df8f3aa5f27be76877bf9e76299245f3f48534079124946573444adc0a
|
Provenance
The following attestation bundles were made for depth_estimation-0.0.3-py3-none-any.whl:
Publisher:
python-publish.yml on shriarul5273/depth_estimation
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
depth_estimation-0.0.3-py3-none-any.whl -
Subject digest:
ab4a351cff012c1eb6fa02190bd7b02375c701a0b81a61a81eb2e5ab3ee621da - Sigstore transparency entry: 1051984806
- Sigstore integration time:
-
Permalink:
shriarul5273/depth_estimation@468de021c651b719b83fdd9977d6671d1b7c89fa -
Branch / Tag:
refs/tags/v.0.0.3 - Owner: https://github.com/shriarul5273
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@468de021c651b719b83fdd9977d6671d1b7c89fa -
Trigger Event:
release
-
Statement type: