depth-estimation 0.0.8__tar.gz → 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- depth_estimation-0.1.0/PKG-INFO +246 -0
- depth_estimation-0.1.0/README.md +203 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/pyproject.toml +4 -17
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/__init__.py +43 -1
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/data/__init__.py +7 -0
- depth_estimation-0.1.0/src/depth_estimation/data/transforms.py +386 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/evaluation/metrics.py +23 -3
- depth_estimation-0.1.0/src/depth_estimation/losses.py +245 -0
- depth_estimation-0.1.0/src/depth_estimation/modeling_utils.py +253 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v1/modeling_depth_anything_v1.py +4 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v2/modeling_depth_anything_v2.py +4 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v3/modeling_depth_anything_v3.py +4 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_pro/modeling_depth_pro.py +30 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/marigold_dc/modeling_marigold_dc.py +7 -0
- depth_estimation-0.1.0/src/depth_estimation/models/midas/modeling_midas.py +132 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/moge/modeling_moge.py +9 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/omnivggt/modeling_omnivggt.py +20 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/pixel_perfect_depth/modeling_ppd.py +8 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/vggt/modeling_vggt.py +20 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/zoedepth/modeling_zoedepth.py +7 -0
- depth_estimation-0.1.0/src/depth_estimation/trainer.py +458 -0
- depth_estimation-0.1.0/src/depth_estimation/training_args.py +178 -0
- depth_estimation-0.1.0/src/depth_estimation.egg-info/PKG-INFO +246 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation.egg-info/SOURCES.txt +8 -1
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation.egg-info/requires.txt +1 -14
- depth_estimation-0.1.0/tests/test_losses.py +227 -0
- depth_estimation-0.1.0/tests/test_training.py +299 -0
- depth_estimation-0.1.0/tests/test_transforms.py +346 -0
- depth_estimation-0.0.8/PKG-INFO +0 -365
- depth_estimation-0.0.8/README.md +0 -313
- depth_estimation-0.0.8/src/depth_estimation/modeling_utils.py +0 -111
- depth_estimation-0.0.8/src/depth_estimation/models/midas/modeling_midas.py +0 -115
- depth_estimation-0.0.8/src/depth_estimation.egg-info/PKG-INFO +0 -365
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/LICENSE +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/setup.cfg +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/cli.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/configuration_utils.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/data/base_dataset.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/data/diode.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/data/folder.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/data/hub.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/data/kitti.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/data/nyu_depth_v2.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/evaluation/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/evaluation/evaluate.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/evaluation/profiling.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/auto/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/auto/modeling_auto.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/auto/processing_auto.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v1/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v1/configuration_depth_anything_v1.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v2/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v2/configuration_depth_anything_v2.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v3/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_anything_v3/configuration_depth_anything_v3.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_pro/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/depth_pro/configuration_depth_pro.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/marigold_dc/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/marigold_dc/configuration_marigold_dc.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/midas/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/midas/configuration_midas.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/moge/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/moge/configuration_moge.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/omnivggt/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/omnivggt/configuration_omnivggt.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/pixel_perfect_depth/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/pixel_perfect_depth/configuration_ppd.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/vggt/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/vggt/configuration_vggt.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/zoedepth/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/models/zoedepth/configuration_zoedepth.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/output.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/pipeline_utils.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/pipelines/__init__.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/pipelines/depth_estimation.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/processing_utils.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation/registry.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation.egg-info/dependency_links.txt +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation.egg-info/entry_points.txt +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/src/depth_estimation.egg-info/top_level.txt +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/tests/test_auto.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/tests/test_config.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/tests/test_data.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/tests/test_evaluation.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/tests/test_model.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/tests/test_pipeline.py +0 -0
- {depth_estimation-0.0.8 → depth_estimation-0.1.0}/tests/test_processor.py +0 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: depth_estimation
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Transformers-style Python library for monocular depth estimation — inference, evaluation, and fine-tuning
|
|
5
|
+
Author: shriarul5273
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/shriarul5273/depth_estimation
|
|
8
|
+
Project-URL: Repository, https://github.com/shriarul5273/depth_estimation
|
|
9
|
+
Project-URL: Issues, https://github.com/shriarul5273/depth_estimation/issues
|
|
10
|
+
Keywords: depth-estimation,monocular-depth,computer-vision,deep-learning,pytorch,fine-tuning,training
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
19
|
+
Classifier: Intended Audience :: Developers
|
|
20
|
+
Classifier: Intended Audience :: Science/Research
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: torch==2.9.0
|
|
25
|
+
Requires-Dist: torchvision>=0.15
|
|
26
|
+
Requires-Dist: Pillow>=9.0
|
|
27
|
+
Requires-Dist: numpy>=1.24
|
|
28
|
+
Requires-Dist: matplotlib>=3.6
|
|
29
|
+
Requires-Dist: opencv-python>=4.8
|
|
30
|
+
Requires-Dist: huggingface-hub>=0.16
|
|
31
|
+
Requires-Dist: transformers
|
|
32
|
+
Requires-Dist: diffusers
|
|
33
|
+
Requires-Dist: accelerate
|
|
34
|
+
Requires-Dist: timm>=0.9.1
|
|
35
|
+
Requires-Dist: einops>=0.6
|
|
36
|
+
Requires-Dist: addict
|
|
37
|
+
Requires-Dist: h5py
|
|
38
|
+
Requires-Dist: tqdm
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# depth_estimation
|
|
45
|
+
|
|
46
|
+
<p align="center">
|
|
47
|
+
<a href="https://github.com/shriarul5273/depth_estimation/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/shriarul5273/depth_estimation?color=blue"></a>
|
|
48
|
+
<a href="https://pypi.org/project/depth-estimation/"><img alt="PyPI" src="https://img.shields.io/pypi/v/depth-estimation"></a>
|
|
49
|
+
<a href="https://pypi.org/project/depth-estimation/"><img alt="Python" src="https://img.shields.io/pypi/pyversions/depth-estimation"></a>
|
|
50
|
+
</p>
|
|
51
|
+
|
|
52
|
+
<h3 align="center">A unified Python library for monocular depth estimation</h3>
|
|
53
|
+
|
|
54
|
+
<h3 align="center">Inference · Fine-Tuning · Evaluation · Dataset Loading</h3>
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
`depth_estimation` is the model-definition framework for depth estimation. It provides a single, consistent API across **12 model families and 28 variants** — so you can swap models, compare them, and fine-tune them without rewriting your pipeline.
|
|
59
|
+
|
|
60
|
+
It covers the full workflow end-to-end: run inference with one line, evaluate on standard benchmarks, and fine-tune on custom depth data — all with the same library.
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install depth-estimation
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
See [docs/dependencies.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/dependencies.md) for optional extras (CUDA, MPS, etc.).
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Quickstart
|
|
73
|
+
|
|
74
|
+
The `pipeline` API is the fastest way to get a depth map from any image:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from depth_estimation import pipeline
|
|
78
|
+
|
|
79
|
+
pipe = pipeline("depth-estimation", model="depth-anything-v2-vitb")
|
|
80
|
+
result = pipe("image.jpg")
|
|
81
|
+
|
|
82
|
+
depth_map = result.depth # np.ndarray, float32, (H, W)
|
|
83
|
+
colored = result.colored_depth # np.ndarray, uint8, (H, W, 3)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
For full control over each step — preprocessing, forward pass, postprocessing — use Auto Classes:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from depth_estimation import AutoDepthModel, AutoProcessor
|
|
90
|
+
import torch
|
|
91
|
+
|
|
92
|
+
model = AutoDepthModel.from_pretrained("zoedepth")
|
|
93
|
+
processor = AutoProcessor.from_pretrained("zoedepth")
|
|
94
|
+
|
|
95
|
+
inputs = processor("image.jpg")
|
|
96
|
+
with torch.no_grad():
|
|
97
|
+
depth = model(inputs["pixel_values"])
|
|
98
|
+
result = processor.postprocess(depth, inputs["original_sizes"])
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Or from the command line:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
depth-estimate predict image.jpg --model depth-anything-v2-vitb
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Why use depth_estimation?
|
|
110
|
+
|
|
111
|
+
**1. One API, every model.**
|
|
112
|
+
Switch from Depth Anything to DepthPro to MoGe by changing a single string. Preprocessing, postprocessing, and output format are identical across all models.
|
|
113
|
+
|
|
114
|
+
**2. The full depth workflow in one place.**
|
|
115
|
+
Most libraries stop at inference. This one covers training, evaluation on standard benchmarks, and dataset loading — so you don't have to stitch together separate tools.
|
|
116
|
+
|
|
117
|
+
**3. Modular, single-file model design.**
|
|
118
|
+
Each model lives in one self-contained file. No hidden abstractions. If you need to understand or modify a model, there's exactly one place to look. New models self-register — `AutoDepthModel` and `pipeline()` resolve them automatically.
|
|
119
|
+
|
|
120
|
+
**4. Designed for research.**
|
|
121
|
+
Trainable models with backbone freeze schedules, proper batch-level metric accumulation (no mean-of-means), and a `compare()` function that shows a formatted table across models.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Supported Models
|
|
126
|
+
|
|
127
|
+
12 model families · 28 variants — see [docs/models.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/models.md) for the full list.
|
|
128
|
+
|
|
129
|
+
All models support inference and CLI. The Trainable column indicates fine-tuning support via `DepthTrainer`.
|
|
130
|
+
|
|
131
|
+
| Family | Variants | Depth type | Trainable |
|
|
132
|
+
|---|---|---|:---:|
|
|
133
|
+
| Depth Anything v1 | vits / vitb / vitl | Relative | ✅ |
|
|
134
|
+
| Depth Anything v2 | vits / vitb / vitl | Relative | ✅ |
|
|
135
|
+
| Depth Anything v3 | small / base / large / giant / mono / metric | Relative + Metric | ✅ |
|
|
136
|
+
| Depth Anything v3 Nested | nested-giant-large | Relative | ✅ |
|
|
137
|
+
| ZoeDepth | nyu / kitti | Metric | ❌ |
|
|
138
|
+
| MiDaS | dpt-large / dpt-hybrid / beit-large | Relative | ✅ |
|
|
139
|
+
| Apple DepthPro | — | Metric | ✅ |
|
|
140
|
+
| Pixel-Perfect Depth | — | Relative | ❌ |
|
|
141
|
+
| Marigold-DC | — | Relative (depth completion) | ❌ |
|
|
142
|
+
| MoGe | v1 vitl / v2 vitl / v2 vitb / v2 vits (+ normal variants) | Metric | ❌ |
|
|
143
|
+
| OmniVGGT | vitl | Metric | ✅ |
|
|
144
|
+
| VGGT | standard / commercial | Metric | ✅ |
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## What can you do?
|
|
149
|
+
|
|
150
|
+
<details>
|
|
151
|
+
<summary><b>Inference</b> — single image, batch, or video</summary>
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
# Single image
|
|
155
|
+
result = pipe("image.jpg")
|
|
156
|
+
|
|
157
|
+
# Batch
|
|
158
|
+
results = pipe(["img1.jpg", "img2.jpg"], batch_size=2)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
# CLI — batch predict
|
|
163
|
+
depth-estimate predict "images/*.jpg" --model depth-anything-v2-vitb --output-dir results/
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
</details>
|
|
167
|
+
|
|
168
|
+
<details>
|
|
169
|
+
<summary><b>Evaluation</b> — standard benchmarks, custom predictions</summary>
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from depth_estimation.evaluation import evaluate, compare, Evaluator
|
|
173
|
+
|
|
174
|
+
# Single model on NYU Depth V2
|
|
175
|
+
results = evaluate("depth-anything-v2-vitb", "nyu_depth_v2", split="test")
|
|
176
|
+
|
|
177
|
+
# Compare multiple models — prints table with best values marked (*)
|
|
178
|
+
compare(["depth-anything-v2-vits", "depth-anything-v2-vitb"], dataset="nyu_depth_v2")
|
|
179
|
+
|
|
180
|
+
# Accumulate metrics over your own dataloader
|
|
181
|
+
ev = Evaluator()
|
|
182
|
+
for pred, gt, mask in dataloader:
|
|
183
|
+
ev.update(pred, gt, mask)
|
|
184
|
+
final = ev.compute() # abs_rel, sq_rel, rmse, rmse_log, delta1/2/3
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
See [docs/evaluation.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/evaluation.md).
|
|
188
|
+
|
|
189
|
+
</details>
|
|
190
|
+
|
|
191
|
+
<details>
|
|
192
|
+
<summary><b>Fine-Tuning</b> — any trainable model, any depth dataset</summary>
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from depth_estimation import DepthAnythingV2Model, DepthTrainer, DepthTrainingArguments, load_dataset
|
|
196
|
+
from depth_estimation.data.transforms import get_train_transforms, get_val_transforms
|
|
197
|
+
|
|
198
|
+
model = DepthAnythingV2Model.from_pretrained("depth-anything-v2-vits", for_training=True)
|
|
199
|
+
train_ds = load_dataset("nyu_depth_v2", split="train", transform=get_train_transforms(518))
|
|
200
|
+
val_ds = load_dataset("nyu_depth_v2", split="test", transform=get_val_transforms(518))
|
|
201
|
+
|
|
202
|
+
args = DepthTrainingArguments(output_dir="./checkpoints", num_epochs=25, batch_size=8,
|
|
203
|
+
freeze_backbone_epochs=5, mixed_precision=True)
|
|
204
|
+
DepthTrainer(model=model, args=args, train_dataset=train_ds, eval_dataset=val_ds).train()
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Any `torch.utils.data.Dataset` returning `pixel_values / depth_map / valid_mask` works directly — no subclassing needed. See [docs/training.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/training.md).
|
|
208
|
+
|
|
209
|
+
</details>
|
|
210
|
+
|
|
211
|
+
<details>
|
|
212
|
+
<summary><b>Dataset Loading</b> — standard benchmarks, custom folders</summary>
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from depth_estimation import load_dataset
|
|
216
|
+
|
|
217
|
+
ds = load_dataset("nyu_depth_v2", split="test") # auto-downloads ~2.8 GB
|
|
218
|
+
ds = load_dataset("diode", split="val", scene_type="indoors") # auto-downloads ~2.6 GB
|
|
219
|
+
ds = load_dataset("kitti_eigen", split="test", root="/data/kitti") # local path
|
|
220
|
+
ds = load_dataset("folder", image_dir="rgb/", depth_dir="depth/") # any folder
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
See [docs/data.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/data.md).
|
|
224
|
+
|
|
225
|
+
</details>
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## Adding a New Model
|
|
230
|
+
|
|
231
|
+
1. Create `src/depth_estimation/models/your_model/`
|
|
232
|
+
2. Add `configuration_your_model.py` (inherit `BaseDepthConfig`)
|
|
233
|
+
3. Add `modeling_your_model.py` (inherit `BaseDepthModel`, single file)
|
|
234
|
+
4. Add `__init__.py` with `MODEL_REGISTRY.register(...)`
|
|
235
|
+
|
|
236
|
+
`AutoDepthModel`, `AutoProcessor`, and `pipeline()` resolve the new model automatically. See [docs/adding_a_model.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/adding_a_model.md) for a step-by-step guide.
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Acknowledgments
|
|
241
|
+
|
|
242
|
+
This library builds upon the work of 12 research teams — see [docs/models.md#citations](https://github.com/shriarul5273/depth_estimation/blob/main/docs/models.md#citations) for the full list.
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
MIT
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
# depth_estimation
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://github.com/shriarul5273/depth_estimation/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/shriarul5273/depth_estimation?color=blue"></a>
|
|
5
|
+
<a href="https://pypi.org/project/depth-estimation/"><img alt="PyPI" src="https://img.shields.io/pypi/v/depth-estimation"></a>
|
|
6
|
+
<a href="https://pypi.org/project/depth-estimation/"><img alt="Python" src="https://img.shields.io/pypi/pyversions/depth-estimation"></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<h3 align="center">A unified Python library for monocular depth estimation</h3>
|
|
10
|
+
|
|
11
|
+
<h3 align="center">Inference · Fine-Tuning · Evaluation · Dataset Loading</h3>
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
`depth_estimation` is the model-definition framework for depth estimation. It provides a single, consistent API across **12 model families and 28 variants** — so you can swap models, compare them, and fine-tune them without rewriting your pipeline.
|
|
16
|
+
|
|
17
|
+
It covers the full workflow end-to-end: run inference with one line, evaluate on standard benchmarks, and fine-tune on custom depth data — all with the same library.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install depth-estimation
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
See [docs/dependencies.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/dependencies.md) for optional extras (CUDA, MPS, etc.).
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## Quickstart
|
|
30
|
+
|
|
31
|
+
The `pipeline` API is the fastest way to get a depth map from any image:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from depth_estimation import pipeline
|
|
35
|
+
|
|
36
|
+
pipe = pipeline("depth-estimation", model="depth-anything-v2-vitb")
|
|
37
|
+
result = pipe("image.jpg")
|
|
38
|
+
|
|
39
|
+
depth_map = result.depth # np.ndarray, float32, (H, W)
|
|
40
|
+
colored = result.colored_depth # np.ndarray, uint8, (H, W, 3)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For full control over each step — preprocessing, forward pass, postprocessing — use Auto Classes:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from depth_estimation import AutoDepthModel, AutoProcessor
|
|
47
|
+
import torch
|
|
48
|
+
|
|
49
|
+
model = AutoDepthModel.from_pretrained("zoedepth")
|
|
50
|
+
processor = AutoProcessor.from_pretrained("zoedepth")
|
|
51
|
+
|
|
52
|
+
inputs = processor("image.jpg")
|
|
53
|
+
with torch.no_grad():
|
|
54
|
+
depth = model(inputs["pixel_values"])
|
|
55
|
+
result = processor.postprocess(depth, inputs["original_sizes"])
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or from the command line:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
depth-estimate predict image.jpg --model depth-anything-v2-vitb
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Why use depth_estimation?
|
|
67
|
+
|
|
68
|
+
**1. One API, every model.**
|
|
69
|
+
Switch from Depth Anything to DepthPro to MoGe by changing a single string. Preprocessing, postprocessing, and output format are identical across all models.
|
|
70
|
+
|
|
71
|
+
**2. The full depth workflow in one place.**
|
|
72
|
+
Most libraries stop at inference. This one covers training, evaluation on standard benchmarks, and dataset loading — so you don't have to stitch together separate tools.
|
|
73
|
+
|
|
74
|
+
**3. Modular, single-file model design.**
|
|
75
|
+
Each model lives in one self-contained file. No hidden abstractions. If you need to understand or modify a model, there's exactly one place to look. New models self-register — `AutoDepthModel` and `pipeline()` resolve them automatically.
|
|
76
|
+
|
|
77
|
+
**4. Designed for research.**
|
|
78
|
+
Trainable models with backbone freeze schedules, proper batch-level metric accumulation (no mean-of-means), and a `compare()` function that shows a formatted table across models.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Supported Models
|
|
83
|
+
|
|
84
|
+
12 model families · 28 variants — see [docs/models.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/models.md) for the full list.
|
|
85
|
+
|
|
86
|
+
All models support inference and CLI. The Trainable column indicates fine-tuning support via `DepthTrainer`.
|
|
87
|
+
|
|
88
|
+
| Family | Variants | Depth type | Trainable |
|
|
89
|
+
|---|---|---|:---:|
|
|
90
|
+
| Depth Anything v1 | vits / vitb / vitl | Relative | ✅ |
|
|
91
|
+
| Depth Anything v2 | vits / vitb / vitl | Relative | ✅ |
|
|
92
|
+
| Depth Anything v3 | small / base / large / giant / mono / metric | Relative + Metric | ✅ |
|
|
93
|
+
| Depth Anything v3 Nested | nested-giant-large | Relative | ✅ |
|
|
94
|
+
| ZoeDepth | nyu / kitti | Metric | ❌ |
|
|
95
|
+
| MiDaS | dpt-large / dpt-hybrid / beit-large | Relative | ✅ |
|
|
96
|
+
| Apple DepthPro | — | Metric | ✅ |
|
|
97
|
+
| Pixel-Perfect Depth | — | Relative | ❌ |
|
|
98
|
+
| Marigold-DC | — | Relative (depth completion) | ❌ |
|
|
99
|
+
| MoGe | v1 vitl / v2 vitl / v2 vitb / v2 vits (+ normal variants) | Metric | ❌ |
|
|
100
|
+
| OmniVGGT | vitl | Metric | ✅ |
|
|
101
|
+
| VGGT | standard / commercial | Metric | ✅ |
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## What can you do?
|
|
106
|
+
|
|
107
|
+
<details>
|
|
108
|
+
<summary><b>Inference</b> — single image, batch, or video</summary>
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
# Single image
|
|
112
|
+
result = pipe("image.jpg")
|
|
113
|
+
|
|
114
|
+
# Batch
|
|
115
|
+
results = pipe(["img1.jpg", "img2.jpg"], batch_size=2)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# CLI — batch predict
|
|
120
|
+
depth-estimate predict "images/*.jpg" --model depth-anything-v2-vitb --output-dir results/
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
</details>
|
|
124
|
+
|
|
125
|
+
<details>
|
|
126
|
+
<summary><b>Evaluation</b> — standard benchmarks, custom predictions</summary>
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from depth_estimation.evaluation import evaluate, compare, Evaluator
|
|
130
|
+
|
|
131
|
+
# Single model on NYU Depth V2
|
|
132
|
+
results = evaluate("depth-anything-v2-vitb", "nyu_depth_v2", split="test")
|
|
133
|
+
|
|
134
|
+
# Compare multiple models — prints table with best values marked (*)
|
|
135
|
+
compare(["depth-anything-v2-vits", "depth-anything-v2-vitb"], dataset="nyu_depth_v2")
|
|
136
|
+
|
|
137
|
+
# Accumulate metrics over your own dataloader
|
|
138
|
+
ev = Evaluator()
|
|
139
|
+
for pred, gt, mask in dataloader:
|
|
140
|
+
ev.update(pred, gt, mask)
|
|
141
|
+
final = ev.compute() # abs_rel, sq_rel, rmse, rmse_log, delta1/2/3
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
See [docs/evaluation.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/evaluation.md).
|
|
145
|
+
|
|
146
|
+
</details>
|
|
147
|
+
|
|
148
|
+
<details>
|
|
149
|
+
<summary><b>Fine-Tuning</b> — any trainable model, any depth dataset</summary>
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from depth_estimation import DepthAnythingV2Model, DepthTrainer, DepthTrainingArguments, load_dataset
|
|
153
|
+
from depth_estimation.data.transforms import get_train_transforms, get_val_transforms
|
|
154
|
+
|
|
155
|
+
model = DepthAnythingV2Model.from_pretrained("depth-anything-v2-vits", for_training=True)
|
|
156
|
+
train_ds = load_dataset("nyu_depth_v2", split="train", transform=get_train_transforms(518))
|
|
157
|
+
val_ds = load_dataset("nyu_depth_v2", split="test", transform=get_val_transforms(518))
|
|
158
|
+
|
|
159
|
+
args = DepthTrainingArguments(output_dir="./checkpoints", num_epochs=25, batch_size=8,
|
|
160
|
+
freeze_backbone_epochs=5, mixed_precision=True)
|
|
161
|
+
DepthTrainer(model=model, args=args, train_dataset=train_ds, eval_dataset=val_ds).train()
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Any `torch.utils.data.Dataset` returning `pixel_values / depth_map / valid_mask` works directly — no subclassing needed. See [docs/training.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/training.md).
|
|
165
|
+
|
|
166
|
+
</details>
|
|
167
|
+
|
|
168
|
+
<details>
|
|
169
|
+
<summary><b>Dataset Loading</b> — standard benchmarks, custom folders</summary>
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
from depth_estimation import load_dataset
|
|
173
|
+
|
|
174
|
+
ds = load_dataset("nyu_depth_v2", split="test") # auto-downloads ~2.8 GB
|
|
175
|
+
ds = load_dataset("diode", split="val", scene_type="indoors") # auto-downloads ~2.6 GB
|
|
176
|
+
ds = load_dataset("kitti_eigen", split="test", root="/data/kitti") # local path
|
|
177
|
+
ds = load_dataset("folder", image_dir="rgb/", depth_dir="depth/") # any folder
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
See [docs/data.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/data.md).
|
|
181
|
+
|
|
182
|
+
</details>
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Adding a New Model
|
|
187
|
+
|
|
188
|
+
1. Create `src/depth_estimation/models/your_model/`
|
|
189
|
+
2. Add `configuration_your_model.py` (inherit `BaseDepthConfig`)
|
|
190
|
+
3. Add `modeling_your_model.py` (inherit `BaseDepthModel`, single file)
|
|
191
|
+
4. Add `__init__.py` with `MODEL_REGISTRY.register(...)`
|
|
192
|
+
|
|
193
|
+
`AutoDepthModel`, `AutoProcessor`, and `pipeline()` resolve the new model automatically. See [docs/adding_a_model.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/adding_a_model.md) for a step-by-step guide.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Acknowledgments
|
|
198
|
+
|
|
199
|
+
This library builds upon the work of 12 research teams — see [docs/models.md#citations](https://github.com/shriarul5273/depth_estimation/blob/main/docs/models.md#citations) for the full list.
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
MIT
|
|
@@ -4,11 +4,11 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "depth_estimation"
|
|
7
|
-
version = "0.0
|
|
7
|
+
version = "0.1.0"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name = "shriarul5273" },
|
|
10
10
|
]
|
|
11
|
-
description = "A Transformers-style Python library for monocular depth estimation"
|
|
11
|
+
description = "A Transformers-style Python library for monocular depth estimation — inference, evaluation, and fine-tuning"
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
requires-python = ">=3.9"
|
|
14
14
|
license = "MIT"
|
|
@@ -25,9 +25,9 @@ classifiers = [
|
|
|
25
25
|
"Intended Audience :: Developers",
|
|
26
26
|
"Intended Audience :: Science/Research",
|
|
27
27
|
]
|
|
28
|
-
keywords = ["depth-estimation", "monocular-depth", "computer-vision", "deep-learning", "pytorch"]
|
|
28
|
+
keywords = ["depth-estimation", "monocular-depth", "computer-vision", "deep-learning", "pytorch", "fine-tuning", "training"]
|
|
29
29
|
dependencies = [
|
|
30
|
-
"torch==2.
|
|
30
|
+
"torch==2.9.0",
|
|
31
31
|
"torchvision>=0.15",
|
|
32
32
|
"Pillow>=9.0",
|
|
33
33
|
"numpy>=1.24",
|
|
@@ -54,19 +54,6 @@ dev = [
|
|
|
54
54
|
"pytest>=7.0",
|
|
55
55
|
"pytest-cov",
|
|
56
56
|
]
|
|
57
|
-
transformers = [
|
|
58
|
-
"transformers>=4.30",
|
|
59
|
-
]
|
|
60
|
-
diffusers = [
|
|
61
|
-
"diffusers>=0.25",
|
|
62
|
-
]
|
|
63
|
-
data = [
|
|
64
|
-
"h5py>=3.0",
|
|
65
|
-
"tqdm",
|
|
66
|
-
]
|
|
67
|
-
all = [
|
|
68
|
-
"depth_estimation[transformers,diffusers,data]",
|
|
69
|
-
]
|
|
70
57
|
|
|
71
58
|
[project.scripts]
|
|
72
59
|
depth-estimate = "depth_estimation.cli:main"
|
|
@@ -51,6 +51,39 @@ def __getattr__(name):
|
|
|
51
51
|
from .pipeline_utils import pipeline
|
|
52
52
|
globals()["pipeline"] = pipeline
|
|
53
53
|
return pipeline
|
|
54
|
+
# Training symbols
|
|
55
|
+
if name == "DepthTrainer":
|
|
56
|
+
from .trainer import DepthTrainer
|
|
57
|
+
globals()["DepthTrainer"] = DepthTrainer
|
|
58
|
+
return DepthTrainer
|
|
59
|
+
if name == "DepthTrainingArguments":
|
|
60
|
+
from .training_args import DepthTrainingArguments
|
|
61
|
+
globals()["DepthTrainingArguments"] = DepthTrainingArguments
|
|
62
|
+
return DepthTrainingArguments
|
|
63
|
+
if name == "CombinedDepthLoss":
|
|
64
|
+
from .losses import CombinedDepthLoss
|
|
65
|
+
globals()["CombinedDepthLoss"] = CombinedDepthLoss
|
|
66
|
+
return CombinedDepthLoss
|
|
67
|
+
if name == "ScaleInvariantLoss":
|
|
68
|
+
from .losses import ScaleInvariantLoss
|
|
69
|
+
globals()["ScaleInvariantLoss"] = ScaleInvariantLoss
|
|
70
|
+
return ScaleInvariantLoss
|
|
71
|
+
if name == "GradientLoss":
|
|
72
|
+
from .losses import GradientLoss
|
|
73
|
+
globals()["GradientLoss"] = GradientLoss
|
|
74
|
+
return GradientLoss
|
|
75
|
+
if name == "BerHuLoss":
|
|
76
|
+
from .losses import BerHuLoss
|
|
77
|
+
globals()["BerHuLoss"] = BerHuLoss
|
|
78
|
+
return BerHuLoss
|
|
79
|
+
if name == "get_train_transforms":
|
|
80
|
+
from .data.transforms import get_train_transforms
|
|
81
|
+
globals()["get_train_transforms"] = get_train_transforms
|
|
82
|
+
return get_train_transforms
|
|
83
|
+
if name == "get_val_transforms":
|
|
84
|
+
from .data.transforms import get_val_transforms
|
|
85
|
+
globals()["get_val_transforms"] = get_val_transforms
|
|
86
|
+
return get_val_transforms
|
|
54
87
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
55
88
|
|
|
56
89
|
|
|
@@ -65,6 +98,15 @@ __all__ = [
|
|
|
65
98
|
"AutoProcessor",
|
|
66
99
|
"MODEL_REGISTRY",
|
|
67
100
|
"load_dataset",
|
|
101
|
+
# Training
|
|
102
|
+
"DepthTrainer",
|
|
103
|
+
"DepthTrainingArguments",
|
|
104
|
+
"CombinedDepthLoss",
|
|
105
|
+
"ScaleInvariantLoss",
|
|
106
|
+
"GradientLoss",
|
|
107
|
+
"BerHuLoss",
|
|
108
|
+
"get_train_transforms",
|
|
109
|
+
"get_val_transforms",
|
|
68
110
|
]
|
|
69
111
|
|
|
70
|
-
__version__ = "0.0.
|
|
112
|
+
__version__ = "0.0.9"
|
|
@@ -46,6 +46,8 @@ from .folder import FolderDataset
|
|
|
46
46
|
from .nyu_depth_v2 import NYUDepthV2Dataset
|
|
47
47
|
from .kitti import KITTIEigenDataset
|
|
48
48
|
from .diode import DIODEDataset
|
|
49
|
+
from . import transforms
|
|
50
|
+
from .transforms import get_train_transforms, get_val_transforms, Compose, PairedResize
|
|
49
51
|
|
|
50
52
|
__all__ = [
|
|
51
53
|
"load_dataset",
|
|
@@ -54,6 +56,11 @@ __all__ = [
|
|
|
54
56
|
"KITTIEigenDataset",
|
|
55
57
|
"DIODEDataset",
|
|
56
58
|
"FolderDataset",
|
|
59
|
+
"transforms",
|
|
60
|
+
"get_train_transforms",
|
|
61
|
+
"get_val_transforms",
|
|
62
|
+
"Compose",
|
|
63
|
+
"PairedResize",
|
|
57
64
|
]
|
|
58
65
|
|
|
59
66
|
_REGISTRY = {
|