depth-estimation 0.1.1__tar.gz → 0.1.2__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.1/src/depth_estimation.egg-info → depth_estimation-0.1.2}/PKG-INFO +65 -5
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/README.md +57 -1
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/pyproject.toml +35 -4
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/__init__.py +72 -3
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/cli.py +197 -42
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/configuration_utils.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/data/__init__.py +4 -7
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/data/base_dataset.py +1 -1
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/data/diode.py +2 -4
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/data/folder.py +5 -3
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/data/hub.py +37 -3
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/data/kitti.py +5 -8
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/data/nyu_depth_v2.py +10 -14
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/data/transforms.py +47 -30
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/evaluation/evaluate.py +48 -33
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/evaluation/metrics.py +71 -46
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/evaluation/profiling.py +15 -13
- depth_estimation-0.1.2/src/depth_estimation/export.py +301 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/losses.py +6 -2
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/modeling_utils.py +114 -4
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/auto/processing_auto.py +2 -1
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v1/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v1/configuration_depth_anything_v1.py +1 -1
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v1/modeling_depth_anything_v1.py +173 -43
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v2/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v2/configuration_depth_anything_v2.py +4 -2
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v2/modeling_depth_anything_v2.py +397 -126
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v3/__init__.py +4 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v3/configuration_depth_anything_v3.py +6 -6
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_anything_v3/modeling_depth_anything_v3.py +257 -77
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_pro/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_pro/modeling_depth_pro.py +79 -27
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/marigold_dc/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/marigold_dc/modeling_marigold_dc.py +68 -30
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/midas/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/midas/configuration_midas.py +14 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/midas/modeling_midas.py +3 -1
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/moge/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/moge/modeling_moge.py +1136 -421
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/omnivggt/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/omnivggt/modeling_omnivggt.py +861 -283
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/pixel_perfect_depth/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/pixel_perfect_depth/modeling_ppd.py +76 -34
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/vggt/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/vggt/modeling_vggt.py +663 -223
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/zoedepth/__init__.py +2 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/zoedepth/modeling_zoedepth.py +20 -6
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/pipeline_utils.py +20 -8
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/processing_utils.py +24 -15
- depth_estimation-0.1.2/src/depth_estimation/pruning.py +216 -0
- depth_estimation-0.1.2/src/depth_estimation/quantization.py +284 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/registry.py +1 -1
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/trainer.py +19 -11
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/training_args.py +13 -6
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/video.py +11 -8
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/viz/animate.py +7 -2
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/viz/composite.py +8 -3
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/viz/display.py +8 -2
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/viz/error.py +4 -4
- {depth_estimation-0.1.1 → depth_estimation-0.1.2/src/depth_estimation.egg-info}/PKG-INFO +65 -5
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation.egg-info/SOURCES.txt +10 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation.egg-info/requires.txt +7 -1
- depth_estimation-0.1.2/tests/test_auto.py +174 -0
- depth_estimation-0.1.2/tests/test_cli.py +279 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_config.py +48 -26
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_data.py +85 -4
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_evaluation.py +15 -3
- depth_estimation-0.1.2/tests/test_export_onnx.py +402 -0
- depth_estimation-0.1.2/tests/test_inference_all_models.py +161 -0
- depth_estimation-0.1.2/tests/test_inference_image.py +72 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_losses.py +10 -7
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_model.py +13 -4
- depth_estimation-0.1.2/tests/test_package.py +20 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_pipeline.py +6 -3
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_processor.py +87 -1
- depth_estimation-0.1.2/tests/test_pruning.py +168 -0
- depth_estimation-0.1.2/tests/test_quantization.py +225 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_training.py +24 -11
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_transforms.py +22 -4
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_video.py +8 -2
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/tests/test_viz.py +15 -3
- depth_estimation-0.1.1/tests/test_auto.py +0 -142
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/LICENSE +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/setup.cfg +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/evaluation/__init__.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/__init__.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/auto/__init__.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/auto/modeling_auto.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/depth_pro/configuration_depth_pro.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/marigold_dc/configuration_marigold_dc.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/moge/configuration_moge.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/omnivggt/configuration_omnivggt.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/pixel_perfect_depth/configuration_ppd.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/vggt/configuration_vggt.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/models/zoedepth/configuration_zoedepth.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/output.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/pipelines/__init__.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/pipelines/depth_estimation.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation/viz/__init__.py +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation.egg-info/dependency_links.txt +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation.egg-info/entry_points.txt +0 -0
- {depth_estimation-0.1.1 → depth_estimation-0.1.2}/src/depth_estimation.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: depth_estimation
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: A Transformers-style Python library for monocular depth estimation — inference, evaluation, and fine-tuning
|
|
5
5
|
Author: shriarul5273
|
|
6
6
|
License-Expression: MIT
|
|
@@ -9,7 +9,6 @@ Project-URL: Repository, https://github.com/shriarul5273/depth_estimation
|
|
|
9
9
|
Project-URL: Issues, https://github.com/shriarul5273/depth_estimation/issues
|
|
10
10
|
Keywords: depth-estimation,monocular-depth,computer-vision,deep-learning,pytorch,fine-tuning,training
|
|
11
11
|
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
@@ -18,10 +17,10 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
|
18
17
|
Classifier: Topic :: Scientific/Engineering :: Image Recognition
|
|
19
18
|
Classifier: Intended Audience :: Developers
|
|
20
19
|
Classifier: Intended Audience :: Science/Research
|
|
21
|
-
Requires-Python: >=3.
|
|
20
|
+
Requires-Python: >=3.10
|
|
22
21
|
Description-Content-Type: text/markdown
|
|
23
22
|
License-File: LICENSE
|
|
24
|
-
Requires-Dist: torch
|
|
23
|
+
Requires-Dist: torch>=2.0
|
|
25
24
|
Requires-Dist: torchvision>=0.15
|
|
26
25
|
Requires-Dist: Pillow>=9.0
|
|
27
26
|
Requires-Dist: numpy>=1.24
|
|
@@ -39,14 +38,21 @@ Requires-Dist: tqdm
|
|
|
39
38
|
Provides-Extra: dev
|
|
40
39
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
41
40
|
Requires-Dist: pytest-cov; extra == "dev"
|
|
41
|
+
Requires-Dist: onnx>=1.14; extra == "dev"
|
|
42
|
+
Requires-Dist: onnxruntime; extra == "dev"
|
|
43
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
44
|
+
Provides-Extra: export
|
|
45
|
+
Requires-Dist: onnx>=1.14; extra == "export"
|
|
42
46
|
Dynamic: license-file
|
|
43
47
|
|
|
44
48
|
# depth_estimation
|
|
45
49
|
|
|
46
50
|
<p align="center">
|
|
51
|
+
<a href="https://github.com/shriarul5273/depth_estimation/actions/workflows/test.yml"><img alt="CI" src="https://github.com/shriarul5273/depth_estimation/actions/workflows/test.yml/badge.svg"></a>
|
|
47
52
|
<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
53
|
<a href="https://pypi.org/project/depth-estimation/"><img alt="PyPI" src="https://img.shields.io/pypi/v/depth-estimation"></a>
|
|
49
54
|
<a href="https://pypi.org/project/depth-estimation/"><img alt="Python" src="https://img.shields.io/pypi/pyversions/depth-estimation"></a>
|
|
55
|
+
<a href="https://pepy.tech/projects/depth-estimation"><img alt="PyPI Downloads" src="https://static.pepy.tech/personalized-badge/depth-estimation?period=total&units=INTERNATIONAL_SYSTEM&left_color=GREY&right_color=GREEN&left_text=downloads"></a>
|
|
50
56
|
<a href="https://huggingface.co/spaces/shriarul5273/Depth-Estimation-Compare-demo"><img alt="Demo" src="https://img.shields.io/badge/🤗%20Hugging%20Face-Demo-blue"></a>
|
|
51
57
|
</p>
|
|
52
58
|
|
|
@@ -266,7 +272,8 @@ See [docs/evaluation.md](https://github.com/shriarul5273/depth_estimation/blob/m
|
|
|
266
272
|
<summary><b>Fine-Tuning</b> — any trainable model, any depth dataset</summary>
|
|
267
273
|
|
|
268
274
|
```python
|
|
269
|
-
from depth_estimation import
|
|
275
|
+
from depth_estimation import DepthTrainer, DepthTrainingArguments, load_dataset
|
|
276
|
+
from depth_estimation.models.depth_anything_v2 import DepthAnythingV2Model
|
|
270
277
|
from depth_estimation.data.transforms import get_train_transforms, get_val_transforms
|
|
271
278
|
|
|
272
279
|
model = DepthAnythingV2Model.from_pretrained("depth-anything-v2-vits", for_training=True)
|
|
@@ -298,6 +305,59 @@ See [docs/data.md](https://github.com/shriarul5273/depth_estimation/blob/main/do
|
|
|
298
305
|
|
|
299
306
|
</details>
|
|
300
307
|
|
|
308
|
+
<details>
|
|
309
|
+
<summary><b>ONNX Export</b> — deploy outside PyTorch</summary>
|
|
310
|
+
|
|
311
|
+
```python
|
|
312
|
+
from depth_estimation import AutoDepthModel, export_onnx
|
|
313
|
+
|
|
314
|
+
model = AutoDepthModel.from_pretrained("depth-anything-v2-vitb")
|
|
315
|
+
export_onnx(model, "depth_anything_v2_vitb.onnx", input_size=518, verify=True)
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
# CLI
|
|
320
|
+
depth-estimate export --model depth-anything-v2-vitb --output model.onnx --verify
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
Verified working for `depth-anything-v1/v2/v3`, `depth-pro`, and `moge`. `zoedepth` and `marigold-dc` are **not exportable** (both wrap an opaque external pipeline) — `export_onnx()` raises a clear error immediately rather than a doomed attempt. Requires the optional `onnx` package: `pip install "depth-estimation[export]"`. GPU inference on the exported file works too via `onnxruntime-gpu`. See [docs/export.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/export.md) for the full supported-models table, known limitations, and GPU setup.
|
|
324
|
+
|
|
325
|
+
</details>
|
|
326
|
+
|
|
327
|
+
<details>
|
|
328
|
+
<summary><b>Pruning</b> — reduce effective parameter count</summary>
|
|
329
|
+
|
|
330
|
+
```python
|
|
331
|
+
from depth_estimation import AutoDepthModel, prune_model, compute_sparsity
|
|
332
|
+
|
|
333
|
+
model = AutoDepthModel.from_pretrained("depth-anything-v2-vitb")
|
|
334
|
+
prune_model(model, amount=0.3) # zero out the smallest-magnitude 30% of weights
|
|
335
|
+
print(compute_sparsity(model)["overall"]) # ~0.3
|
|
336
|
+
|
|
337
|
+
model.export_onnx("pruned.onnx", verify=True) # pruned models export like any other
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Pure PyTorch (`torch.nn.utils.prune`) — no special hardware or SDK. See [docs/pruning.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/pruning.md) for prune-aware fine-tuning and what pruning does/doesn't buy you (it zeros weights, it doesn't shrink tensors).
|
|
341
|
+
|
|
342
|
+
</details>
|
|
343
|
+
|
|
344
|
+
<details>
|
|
345
|
+
<summary><b>Quantization</b> — float16/bfloat16/int8, plus ONNX int8/uint8</summary>
|
|
346
|
+
|
|
347
|
+
```python
|
|
348
|
+
from depth_estimation import AutoDepthModel, quantize_onnx
|
|
349
|
+
|
|
350
|
+
model = AutoDepthModel.from_pretrained("depth-anything-v2-vitb")
|
|
351
|
+
model.quantize(dtype="float16") # in-place GPU precision cast
|
|
352
|
+
|
|
353
|
+
model.export_onnx("model.onnx")
|
|
354
|
+
quantize_onnx("model.onnx", "model_uint8.onnx") # default weight_type="uint8", verify=True
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
`verify` defaults to `True` — quantization accuracy is **model-dependent, not reliably safe**: testing across the 28 registered variants found `uint8` produces badly wrong output for several real pretrained checkpoints, not just an edge case. See [docs/quantization.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/quantization.md) — including which formats are actually verified working (`int16`/`uint16` are **not**, despite being accepted by the underlying APIs, and `int8` needs `onnxruntime>=1.26.0` for models with `Conv2d` layers).
|
|
358
|
+
|
|
359
|
+
</details>
|
|
360
|
+
|
|
301
361
|
---
|
|
302
362
|
|
|
303
363
|
## Adding a New Model
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
# depth_estimation
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
+
<a href="https://github.com/shriarul5273/depth_estimation/actions/workflows/test.yml"><img alt="CI" src="https://github.com/shriarul5273/depth_estimation/actions/workflows/test.yml/badge.svg"></a>
|
|
4
5
|
<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
6
|
<a href="https://pypi.org/project/depth-estimation/"><img alt="PyPI" src="https://img.shields.io/pypi/v/depth-estimation"></a>
|
|
6
7
|
<a href="https://pypi.org/project/depth-estimation/"><img alt="Python" src="https://img.shields.io/pypi/pyversions/depth-estimation"></a>
|
|
8
|
+
<a href="https://pepy.tech/projects/depth-estimation"><img alt="PyPI Downloads" src="https://static.pepy.tech/personalized-badge/depth-estimation?period=total&units=INTERNATIONAL_SYSTEM&left_color=GREY&right_color=GREEN&left_text=downloads"></a>
|
|
7
9
|
<a href="https://huggingface.co/spaces/shriarul5273/Depth-Estimation-Compare-demo"><img alt="Demo" src="https://img.shields.io/badge/🤗%20Hugging%20Face-Demo-blue"></a>
|
|
8
10
|
</p>
|
|
9
11
|
|
|
@@ -223,7 +225,8 @@ See [docs/evaluation.md](https://github.com/shriarul5273/depth_estimation/blob/m
|
|
|
223
225
|
<summary><b>Fine-Tuning</b> — any trainable model, any depth dataset</summary>
|
|
224
226
|
|
|
225
227
|
```python
|
|
226
|
-
from depth_estimation import
|
|
228
|
+
from depth_estimation import DepthTrainer, DepthTrainingArguments, load_dataset
|
|
229
|
+
from depth_estimation.models.depth_anything_v2 import DepthAnythingV2Model
|
|
227
230
|
from depth_estimation.data.transforms import get_train_transforms, get_val_transforms
|
|
228
231
|
|
|
229
232
|
model = DepthAnythingV2Model.from_pretrained("depth-anything-v2-vits", for_training=True)
|
|
@@ -255,6 +258,59 @@ See [docs/data.md](https://github.com/shriarul5273/depth_estimation/blob/main/do
|
|
|
255
258
|
|
|
256
259
|
</details>
|
|
257
260
|
|
|
261
|
+
<details>
|
|
262
|
+
<summary><b>ONNX Export</b> — deploy outside PyTorch</summary>
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from depth_estimation import AutoDepthModel, export_onnx
|
|
266
|
+
|
|
267
|
+
model = AutoDepthModel.from_pretrained("depth-anything-v2-vitb")
|
|
268
|
+
export_onnx(model, "depth_anything_v2_vitb.onnx", input_size=518, verify=True)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
# CLI
|
|
273
|
+
depth-estimate export --model depth-anything-v2-vitb --output model.onnx --verify
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Verified working for `depth-anything-v1/v2/v3`, `depth-pro`, and `moge`. `zoedepth` and `marigold-dc` are **not exportable** (both wrap an opaque external pipeline) — `export_onnx()` raises a clear error immediately rather than a doomed attempt. Requires the optional `onnx` package: `pip install "depth-estimation[export]"`. GPU inference on the exported file works too via `onnxruntime-gpu`. See [docs/export.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/export.md) for the full supported-models table, known limitations, and GPU setup.
|
|
277
|
+
|
|
278
|
+
</details>
|
|
279
|
+
|
|
280
|
+
<details>
|
|
281
|
+
<summary><b>Pruning</b> — reduce effective parameter count</summary>
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
from depth_estimation import AutoDepthModel, prune_model, compute_sparsity
|
|
285
|
+
|
|
286
|
+
model = AutoDepthModel.from_pretrained("depth-anything-v2-vitb")
|
|
287
|
+
prune_model(model, amount=0.3) # zero out the smallest-magnitude 30% of weights
|
|
288
|
+
print(compute_sparsity(model)["overall"]) # ~0.3
|
|
289
|
+
|
|
290
|
+
model.export_onnx("pruned.onnx", verify=True) # pruned models export like any other
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
Pure PyTorch (`torch.nn.utils.prune`) — no special hardware or SDK. See [docs/pruning.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/pruning.md) for prune-aware fine-tuning and what pruning does/doesn't buy you (it zeros weights, it doesn't shrink tensors).
|
|
294
|
+
|
|
295
|
+
</details>
|
|
296
|
+
|
|
297
|
+
<details>
|
|
298
|
+
<summary><b>Quantization</b> — float16/bfloat16/int8, plus ONNX int8/uint8</summary>
|
|
299
|
+
|
|
300
|
+
```python
|
|
301
|
+
from depth_estimation import AutoDepthModel, quantize_onnx
|
|
302
|
+
|
|
303
|
+
model = AutoDepthModel.from_pretrained("depth-anything-v2-vitb")
|
|
304
|
+
model.quantize(dtype="float16") # in-place GPU precision cast
|
|
305
|
+
|
|
306
|
+
model.export_onnx("model.onnx")
|
|
307
|
+
quantize_onnx("model.onnx", "model_uint8.onnx") # default weight_type="uint8", verify=True
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
`verify` defaults to `True` — quantization accuracy is **model-dependent, not reliably safe**: testing across the 28 registered variants found `uint8` produces badly wrong output for several real pretrained checkpoints, not just an edge case. See [docs/quantization.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/quantization.md) — including which formats are actually verified working (`int16`/`uint16` are **not**, despite being accepted by the underlying APIs, and `int8` needs `onnxruntime>=1.26.0` for models with `Conv2d` layers).
|
|
311
|
+
|
|
312
|
+
</details>
|
|
313
|
+
|
|
258
314
|
---
|
|
259
315
|
|
|
260
316
|
## Adding a New Model
|
|
@@ -4,18 +4,17 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "depth_estimation"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.2"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name = "shriarul5273" },
|
|
10
10
|
]
|
|
11
11
|
description = "A Transformers-style Python library for monocular depth estimation — inference, evaluation, and fine-tuning"
|
|
12
12
|
readme = "README.md"
|
|
13
|
-
requires-python = ">=3.
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
14
|
license = "MIT"
|
|
15
15
|
license-files = ["LICENSE"]
|
|
16
16
|
classifiers = [
|
|
17
17
|
"Programming Language :: Python :: 3",
|
|
18
|
-
"Programming Language :: Python :: 3.9",
|
|
19
18
|
"Programming Language :: Python :: 3.10",
|
|
20
19
|
"Programming Language :: Python :: 3.11",
|
|
21
20
|
"Programming Language :: Python :: 3.12",
|
|
@@ -27,7 +26,7 @@ classifiers = [
|
|
|
27
26
|
]
|
|
28
27
|
keywords = ["depth-estimation", "monocular-depth", "computer-vision", "deep-learning", "pytorch", "fine-tuning", "training"]
|
|
29
28
|
dependencies = [
|
|
30
|
-
"torch
|
|
29
|
+
"torch>=2.0",
|
|
31
30
|
"torchvision>=0.15",
|
|
32
31
|
"Pillow>=9.0",
|
|
33
32
|
"numpy>=1.24",
|
|
@@ -53,6 +52,12 @@ Issues = "https://github.com/shriarul5273/depth_estimation/issues"
|
|
|
53
52
|
dev = [
|
|
54
53
|
"pytest>=7.0",
|
|
55
54
|
"pytest-cov",
|
|
55
|
+
"onnx>=1.14",
|
|
56
|
+
"onnxruntime",
|
|
57
|
+
"mypy>=1.10",
|
|
58
|
+
]
|
|
59
|
+
export = [
|
|
60
|
+
"onnx>=1.14",
|
|
56
61
|
]
|
|
57
62
|
|
|
58
63
|
[project.scripts]
|
|
@@ -60,3 +65,29 @@ depth-estimate = "depth_estimation.cli:main"
|
|
|
60
65
|
|
|
61
66
|
[tool.setuptools.packages.find]
|
|
62
67
|
where = ["src"]
|
|
68
|
+
|
|
69
|
+
[tool.pytest.ini_options]
|
|
70
|
+
markers = [
|
|
71
|
+
"slow: heavy or network-dependent tests, excluded by default (run with -m slow)",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[tool.ruff.lint]
|
|
75
|
+
# Keep Ruff's original default rule set explicit. Ruff 0.16 broadened its
|
|
76
|
+
# implicit defaults, which made unchanged code fail CI when the unpinned
|
|
77
|
+
# runner upgraded from 0.15.x.
|
|
78
|
+
select = ["E4", "E7", "E9", "F"]
|
|
79
|
+
|
|
80
|
+
[tool.ruff.lint.per-file-ignores]
|
|
81
|
+
# Model submodules are imported for their self-registration side effect
|
|
82
|
+
# (they call MODEL_REGISTRY.register(...) at import time) — not because
|
|
83
|
+
# their names are used directly here.
|
|
84
|
+
"src/depth_estimation/__init__.py" = ["F401"]
|
|
85
|
+
|
|
86
|
+
[tool.mypy]
|
|
87
|
+
python_version = "3.10"
|
|
88
|
+
ignore_missing_imports = true
|
|
89
|
+
# The codebase currently has ~290 pre-existing type errors (mostly missing
|
|
90
|
+
# annotations in older modules, not real bugs — verified by spot-checking
|
|
91
|
+
# several by hand). Fixing all of them is a separate, large effort; CI runs
|
|
92
|
+
# mypy in advisory (non-blocking) mode for now — see .github/workflows/test.yml.
|
|
93
|
+
# New code should still aim to be clean under this config.
|
|
@@ -27,77 +27,130 @@ from .models import omnivggt
|
|
|
27
27
|
from .models import vggt
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
def load_dataset(
|
|
30
|
+
def load_dataset(
|
|
31
|
+
name, split="train", root=None, download=True, transform=None, **kwargs
|
|
32
|
+
):
|
|
31
33
|
"""Load a depth dataset by name. See :mod:`depth_estimation.data` for details."""
|
|
32
34
|
from .data import load_dataset as _load
|
|
33
|
-
|
|
35
|
+
|
|
36
|
+
return _load(
|
|
37
|
+
name, split=split, root=root, download=download, transform=transform, **kwargs
|
|
38
|
+
)
|
|
34
39
|
|
|
35
40
|
|
|
36
41
|
def __getattr__(name):
|
|
37
42
|
"""Defer torch-heavy imports until first use."""
|
|
38
43
|
if name == "BaseDepthModel":
|
|
39
44
|
from .modeling_utils import BaseDepthModel
|
|
45
|
+
|
|
40
46
|
globals()["BaseDepthModel"] = BaseDepthModel
|
|
41
47
|
return BaseDepthModel
|
|
42
48
|
if name == "DepthProcessor":
|
|
43
49
|
from .processing_utils import DepthProcessor
|
|
50
|
+
|
|
44
51
|
globals()["DepthProcessor"] = DepthProcessor
|
|
45
52
|
return DepthProcessor
|
|
46
53
|
if name == "DepthPipeline":
|
|
47
54
|
from .pipeline_utils import DepthPipeline
|
|
55
|
+
|
|
48
56
|
globals()["DepthPipeline"] = DepthPipeline
|
|
49
57
|
return DepthPipeline
|
|
50
58
|
if name == "pipeline":
|
|
51
59
|
from .pipeline_utils import pipeline
|
|
60
|
+
|
|
52
61
|
globals()["pipeline"] = pipeline
|
|
53
62
|
return pipeline
|
|
54
63
|
# Training symbols
|
|
55
64
|
if name == "DepthTrainer":
|
|
56
65
|
from .trainer import DepthTrainer
|
|
66
|
+
|
|
57
67
|
globals()["DepthTrainer"] = DepthTrainer
|
|
58
68
|
return DepthTrainer
|
|
59
69
|
if name == "DepthTrainingArguments":
|
|
60
70
|
from .training_args import DepthTrainingArguments
|
|
71
|
+
|
|
61
72
|
globals()["DepthTrainingArguments"] = DepthTrainingArguments
|
|
62
73
|
return DepthTrainingArguments
|
|
63
74
|
if name == "CombinedDepthLoss":
|
|
64
75
|
from .losses import CombinedDepthLoss
|
|
76
|
+
|
|
65
77
|
globals()["CombinedDepthLoss"] = CombinedDepthLoss
|
|
66
78
|
return CombinedDepthLoss
|
|
67
79
|
if name == "ScaleInvariantLoss":
|
|
68
80
|
from .losses import ScaleInvariantLoss
|
|
81
|
+
|
|
69
82
|
globals()["ScaleInvariantLoss"] = ScaleInvariantLoss
|
|
70
83
|
return ScaleInvariantLoss
|
|
71
84
|
if name == "GradientLoss":
|
|
72
85
|
from .losses import GradientLoss
|
|
86
|
+
|
|
73
87
|
globals()["GradientLoss"] = GradientLoss
|
|
74
88
|
return GradientLoss
|
|
75
89
|
if name == "BerHuLoss":
|
|
76
90
|
from .losses import BerHuLoss
|
|
91
|
+
|
|
77
92
|
globals()["BerHuLoss"] = BerHuLoss
|
|
78
93
|
return BerHuLoss
|
|
79
94
|
if name == "get_train_transforms":
|
|
80
95
|
from .data.transforms import get_train_transforms
|
|
96
|
+
|
|
81
97
|
globals()["get_train_transforms"] = get_train_transforms
|
|
82
98
|
return get_train_transforms
|
|
83
99
|
if name == "get_val_transforms":
|
|
84
100
|
from .data.transforms import get_val_transforms
|
|
101
|
+
|
|
85
102
|
globals()["get_val_transforms"] = get_val_transforms
|
|
86
103
|
return get_val_transforms
|
|
87
104
|
# Video & streaming
|
|
88
105
|
if name == "VideoStream":
|
|
89
106
|
from .video import VideoStream
|
|
107
|
+
|
|
90
108
|
globals()["VideoStream"] = VideoStream
|
|
91
109
|
return VideoStream
|
|
92
110
|
if name == "process_video":
|
|
93
111
|
from .video import process_video
|
|
112
|
+
|
|
94
113
|
globals()["process_video"] = process_video
|
|
95
114
|
return process_video
|
|
96
115
|
# Visualization toolkit
|
|
97
116
|
if name == "viz":
|
|
98
117
|
from . import viz
|
|
118
|
+
|
|
99
119
|
globals()["viz"] = viz
|
|
100
120
|
return viz
|
|
121
|
+
# ONNX export
|
|
122
|
+
if name == "export_onnx":
|
|
123
|
+
from .export import export_onnx
|
|
124
|
+
|
|
125
|
+
globals()["export_onnx"] = export_onnx
|
|
126
|
+
return export_onnx
|
|
127
|
+
# Pruning
|
|
128
|
+
if name == "prune_model":
|
|
129
|
+
from .pruning import prune_model
|
|
130
|
+
|
|
131
|
+
globals()["prune_model"] = prune_model
|
|
132
|
+
return prune_model
|
|
133
|
+
if name == "compute_sparsity":
|
|
134
|
+
from .pruning import compute_sparsity
|
|
135
|
+
|
|
136
|
+
globals()["compute_sparsity"] = compute_sparsity
|
|
137
|
+
return compute_sparsity
|
|
138
|
+
if name == "make_pruning_permanent":
|
|
139
|
+
from .pruning import make_pruning_permanent
|
|
140
|
+
|
|
141
|
+
globals()["make_pruning_permanent"] = make_pruning_permanent
|
|
142
|
+
return make_pruning_permanent
|
|
143
|
+
# Quantization
|
|
144
|
+
if name == "quantize_model":
|
|
145
|
+
from .quantization import quantize_model
|
|
146
|
+
|
|
147
|
+
globals()["quantize_model"] = quantize_model
|
|
148
|
+
return quantize_model
|
|
149
|
+
if name == "quantize_onnx":
|
|
150
|
+
from .quantization import quantize_onnx
|
|
151
|
+
|
|
152
|
+
globals()["quantize_onnx"] = quantize_onnx
|
|
153
|
+
return quantize_onnx
|
|
101
154
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
102
155
|
|
|
103
156
|
|
|
@@ -126,6 +179,22 @@ __all__ = [
|
|
|
126
179
|
"process_video",
|
|
127
180
|
# Visualization
|
|
128
181
|
"viz",
|
|
182
|
+
# ONNX export
|
|
183
|
+
"export_onnx",
|
|
184
|
+
# Pruning
|
|
185
|
+
"prune_model",
|
|
186
|
+
"compute_sparsity",
|
|
187
|
+
"make_pruning_permanent",
|
|
188
|
+
# Quantization
|
|
189
|
+
"quantize_model",
|
|
190
|
+
"quantize_onnx",
|
|
129
191
|
]
|
|
130
192
|
|
|
131
|
-
|
|
193
|
+
try:
|
|
194
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
195
|
+
|
|
196
|
+
__version__ = version("depth_estimation")
|
|
197
|
+
except PackageNotFoundError:
|
|
198
|
+
# Package not installed (e.g. running from a source checkout without
|
|
199
|
+
# `pip install -e .`) — no metadata to read the version from.
|
|
200
|
+
__version__ = "0.0.0+unknown"
|