depth-estimation 0.0.5__tar.gz → 0.0.7__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.0.5/src/depth_estimation.egg-info → depth_estimation-0.0.7}/PKG-INFO +49 -10
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/README.md +48 -9
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/pyproject.toml +4 -1
- depth_estimation-0.0.7/src/depth_estimation/__init__.py +63 -0
- depth_estimation-0.0.7/src/depth_estimation/cli.py +389 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/auto/processing_auto.py +2 -2
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_anything_v1/__init__.py +15 -2
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_anything_v2/__init__.py +15 -2
- depth_estimation-0.0.7/src/depth_estimation/models/depth_anything_v3/__init__.py +50 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_pro/__init__.py +15 -2
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/marigold_dc/__init__.py +15 -2
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/midas/__init__.py +15 -2
- depth_estimation-0.0.7/src/depth_estimation/models/moge/__init__.py +27 -0
- depth_estimation-0.0.7/src/depth_estimation/models/moge/configuration_moge.py +98 -0
- depth_estimation-0.0.7/src/depth_estimation/models/moge/modeling_moge.py +1503 -0
- depth_estimation-0.0.7/src/depth_estimation/models/omnivggt/__init__.py +27 -0
- depth_estimation-0.0.7/src/depth_estimation/models/omnivggt/configuration_omnivggt.py +62 -0
- depth_estimation-0.0.7/src/depth_estimation/models/omnivggt/modeling_omnivggt.py +1357 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/pixel_perfect_depth/__init__.py +15 -2
- depth_estimation-0.0.7/src/depth_estimation/models/vggt/__init__.py +27 -0
- depth_estimation-0.0.7/src/depth_estimation/models/vggt/configuration_vggt.py +71 -0
- depth_estimation-0.0.7/src/depth_estimation/models/vggt/modeling_vggt.py +1133 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/zoedepth/__init__.py +15 -2
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/registry.py +6 -1
- {depth_estimation-0.0.5 → depth_estimation-0.0.7/src/depth_estimation.egg-info}/PKG-INFO +49 -10
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation.egg-info/SOURCES.txt +11 -0
- depth_estimation-0.0.7/src/depth_estimation.egg-info/entry_points.txt +2 -0
- depth_estimation-0.0.5/src/depth_estimation/__init__.py +0 -40
- depth_estimation-0.0.5/src/depth_estimation/models/depth_anything_v3/__init__.py +0 -29
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/LICENSE +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/setup.cfg +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/configuration_utils.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/modeling_utils.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/__init__.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/auto/__init__.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/auto/modeling_auto.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_anything_v1/configuration_depth_anything_v1.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_anything_v1/modeling_depth_anything_v1.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_anything_v2/configuration_depth_anything_v2.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_anything_v2/modeling_depth_anything_v2.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_anything_v3/configuration_depth_anything_v3.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_anything_v3/modeling_depth_anything_v3.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_pro/configuration_depth_pro.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/depth_pro/modeling_depth_pro.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/marigold_dc/configuration_marigold_dc.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/marigold_dc/modeling_marigold_dc.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/midas/configuration_midas.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/midas/modeling_midas.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/pixel_perfect_depth/configuration_ppd.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/pixel_perfect_depth/modeling_ppd.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/zoedepth/configuration_zoedepth.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/models/zoedepth/modeling_zoedepth.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/output.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/pipeline_utils.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/pipelines/__init__.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/pipelines/depth_estimation.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation/processing_utils.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation.egg-info/dependency_links.txt +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation.egg-info/requires.txt +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/src/depth_estimation.egg-info/top_level.txt +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/tests/test_auto.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/tests/test_config.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/tests/test_model.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/tests/test_pipeline.py +0 -0
- {depth_estimation-0.0.5 → depth_estimation-0.0.7}/tests/test_processor.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: depth_estimation
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.7
|
|
4
4
|
Summary: A Transformers-style Python library for monocular depth estimation
|
|
5
5
|
Author: shriarul5273
|
|
6
6
|
License-Expression: MIT
|
|
@@ -49,24 +49,26 @@ Dynamic: license-file
|
|
|
49
49
|
|
|
50
50
|
A **Python library** for monocular depth estimation.
|
|
51
51
|
|
|
52
|
-
Provides a unified, modular API for running inference, comparing, and integrating depth estimation models — supporting **
|
|
52
|
+
Provides a unified, modular API for running inference, comparing, and integrating depth estimation models — supporting **12 model families** with **28 variants** and designed to accommodate new models with minimal friction.
|
|
53
53
|
|
|
54
54
|
## Installation
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
57
|
pip install depth-estimation
|
|
58
|
-
|
|
59
|
-
# With dev dependencies
|
|
60
|
-
pip install "depth-estimation[dev]"
|
|
61
|
-
|
|
62
|
-
# With all optional model dependencies
|
|
63
|
-
pip install "depth-estimation[all]"
|
|
64
58
|
```
|
|
65
59
|
|
|
66
60
|
For a full list of core and optional dependencies, see [docs/dependencies.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/dependencies.md).
|
|
67
61
|
|
|
68
62
|
## Quick Start
|
|
69
63
|
|
|
64
|
+
| | Pipeline API | Auto Classes |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| **Setup** | One call, model + processor bundled | Load model and processor separately |
|
|
67
|
+
| **Inference** | Pass image path directly | Call `processor()`, `model()`, `postprocess()` manually |
|
|
68
|
+
| **Control** | Low — handles everything for you | High — you control each step |
|
|
69
|
+
| **Output** | `DepthOutput` with `.depth`, `.colored_depth`, `.metadata` | Raw depth tensor |
|
|
70
|
+
| **Best for** | Quick inference, scripts, demos | Custom pipelines, research, fine-grained control |
|
|
71
|
+
|
|
70
72
|
### Pipeline API (Recommended)
|
|
71
73
|
|
|
72
74
|
```python
|
|
@@ -85,7 +87,7 @@ meta = result.metadata # dict with model info
|
|
|
85
87
|
```python
|
|
86
88
|
from depth_estimation import AutoDepthModel, AutoProcessor
|
|
87
89
|
|
|
88
|
-
# Works with any of the
|
|
90
|
+
# Works with any of the 25 supported variants
|
|
89
91
|
model = AutoDepthModel.from_pretrained("zoedepth")
|
|
90
92
|
processor = AutoProcessor.from_pretrained("zoedepth")
|
|
91
93
|
|
|
@@ -106,7 +108,7 @@ for r in results:
|
|
|
106
108
|
|
|
107
109
|
## Supported Models
|
|
108
110
|
|
|
109
|
-
|
|
111
|
+
12 model families · 28 variants — see [docs/models.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/models.md) for the full list.
|
|
110
112
|
|
|
111
113
|
## Architecture
|
|
112
114
|
|
|
@@ -130,6 +132,43 @@ Input → Processor.preprocess() → Model.forward() → Processor.postprocess()
|
|
|
130
132
|
|
|
131
133
|
That's it — `AutoDepthModel`, `AutoProcessor`, and `pipeline()` will automatically resolve your model.
|
|
132
134
|
|
|
135
|
+
## CLI
|
|
136
|
+
|
|
137
|
+
After installing the package, a `depth-estimate` command is available.
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# Single image → saves demo10_depth.png
|
|
141
|
+
depth-estimate predict demo10.png --model depth-anything-v2-vitb
|
|
142
|
+
|
|
143
|
+
# Batch (directory or glob) → saves to results/
|
|
144
|
+
depth-estimate predict "images/*.jpg" --model depth-anything-v2-vitb --output-dir results/
|
|
145
|
+
|
|
146
|
+
# Video → saves side-by-side RGB | depth as MP4
|
|
147
|
+
depth-estimate predict video.mp4 --model depth-anything-v2-vitb --output depth_video.mp4
|
|
148
|
+
|
|
149
|
+
# Save raw float32 array (.npy) alongside the PNG
|
|
150
|
+
depth-estimate predict demo10.png --model depth-anything-v2-vitb --format both
|
|
151
|
+
|
|
152
|
+
# Change colormap
|
|
153
|
+
depth-estimate predict demo10.png --model depth-anything-v2-vitb --colormap inferno
|
|
154
|
+
|
|
155
|
+
# List all available models
|
|
156
|
+
depth-estimate list-models
|
|
157
|
+
|
|
158
|
+
# Show config details for a model
|
|
159
|
+
depth-estimate info depth-anything-v2-vitb
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Global flags** (`--device`, `--quiet`, `--verbose`) go before the subcommand:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
depth-estimate --device cpu --quiet predict demo10.png --model depth-anything-v2-vitb
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
All subcommands support `--json` for machine-readable output.
|
|
169
|
+
|
|
170
|
+
For full documentation see [docs/cli.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/cli.md).
|
|
171
|
+
|
|
133
172
|
## Running Tests
|
|
134
173
|
|
|
135
174
|
```bash
|
|
@@ -2,24 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
A **Python library** for monocular depth estimation.
|
|
4
4
|
|
|
5
|
-
Provides a unified, modular API for running inference, comparing, and integrating depth estimation models — supporting **
|
|
5
|
+
Provides a unified, modular API for running inference, comparing, and integrating depth estimation models — supporting **12 model families** with **28 variants** and designed to accommodate new models with minimal friction.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
pip install depth-estimation
|
|
11
|
-
|
|
12
|
-
# With dev dependencies
|
|
13
|
-
pip install "depth-estimation[dev]"
|
|
14
|
-
|
|
15
|
-
# With all optional model dependencies
|
|
16
|
-
pip install "depth-estimation[all]"
|
|
17
11
|
```
|
|
18
12
|
|
|
19
13
|
For a full list of core and optional dependencies, see [docs/dependencies.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/dependencies.md).
|
|
20
14
|
|
|
21
15
|
## Quick Start
|
|
22
16
|
|
|
17
|
+
| | Pipeline API | Auto Classes |
|
|
18
|
+
|---|---|---|
|
|
19
|
+
| **Setup** | One call, model + processor bundled | Load model and processor separately |
|
|
20
|
+
| **Inference** | Pass image path directly | Call `processor()`, `model()`, `postprocess()` manually |
|
|
21
|
+
| **Control** | Low — handles everything for you | High — you control each step |
|
|
22
|
+
| **Output** | `DepthOutput` with `.depth`, `.colored_depth`, `.metadata` | Raw depth tensor |
|
|
23
|
+
| **Best for** | Quick inference, scripts, demos | Custom pipelines, research, fine-grained control |
|
|
24
|
+
|
|
23
25
|
### Pipeline API (Recommended)
|
|
24
26
|
|
|
25
27
|
```python
|
|
@@ -38,7 +40,7 @@ meta = result.metadata # dict with model info
|
|
|
38
40
|
```python
|
|
39
41
|
from depth_estimation import AutoDepthModel, AutoProcessor
|
|
40
42
|
|
|
41
|
-
# Works with any of the
|
|
43
|
+
# Works with any of the 25 supported variants
|
|
42
44
|
model = AutoDepthModel.from_pretrained("zoedepth")
|
|
43
45
|
processor = AutoProcessor.from_pretrained("zoedepth")
|
|
44
46
|
|
|
@@ -59,7 +61,7 @@ for r in results:
|
|
|
59
61
|
|
|
60
62
|
## Supported Models
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
12 model families · 28 variants — see [docs/models.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/models.md) for the full list.
|
|
63
65
|
|
|
64
66
|
## Architecture
|
|
65
67
|
|
|
@@ -83,6 +85,43 @@ Input → Processor.preprocess() → Model.forward() → Processor.postprocess()
|
|
|
83
85
|
|
|
84
86
|
That's it — `AutoDepthModel`, `AutoProcessor`, and `pipeline()` will automatically resolve your model.
|
|
85
87
|
|
|
88
|
+
## CLI
|
|
89
|
+
|
|
90
|
+
After installing the package, a `depth-estimate` command is available.
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Single image → saves demo10_depth.png
|
|
94
|
+
depth-estimate predict demo10.png --model depth-anything-v2-vitb
|
|
95
|
+
|
|
96
|
+
# Batch (directory or glob) → saves to results/
|
|
97
|
+
depth-estimate predict "images/*.jpg" --model depth-anything-v2-vitb --output-dir results/
|
|
98
|
+
|
|
99
|
+
# Video → saves side-by-side RGB | depth as MP4
|
|
100
|
+
depth-estimate predict video.mp4 --model depth-anything-v2-vitb --output depth_video.mp4
|
|
101
|
+
|
|
102
|
+
# Save raw float32 array (.npy) alongside the PNG
|
|
103
|
+
depth-estimate predict demo10.png --model depth-anything-v2-vitb --format both
|
|
104
|
+
|
|
105
|
+
# Change colormap
|
|
106
|
+
depth-estimate predict demo10.png --model depth-anything-v2-vitb --colormap inferno
|
|
107
|
+
|
|
108
|
+
# List all available models
|
|
109
|
+
depth-estimate list-models
|
|
110
|
+
|
|
111
|
+
# Show config details for a model
|
|
112
|
+
depth-estimate info depth-anything-v2-vitb
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Global flags** (`--device`, `--quiet`, `--verbose`) go before the subcommand:
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
depth-estimate --device cpu --quiet predict demo10.png --model depth-anything-v2-vitb
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
All subcommands support `--json` for machine-readable output.
|
|
122
|
+
|
|
123
|
+
For full documentation see [docs/cli.md](https://github.com/shriarul5273/depth_estimation/blob/main/docs/cli.md).
|
|
124
|
+
|
|
86
125
|
## Running Tests
|
|
87
126
|
|
|
88
127
|
```bash
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "depth_estimation"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.7"
|
|
8
8
|
authors = [
|
|
9
9
|
{ name = "shriarul5273" },
|
|
10
10
|
]
|
|
@@ -62,5 +62,8 @@ all = [
|
|
|
62
62
|
"depth_estimation[transformers,diffusers]",
|
|
63
63
|
]
|
|
64
64
|
|
|
65
|
+
[project.scripts]
|
|
66
|
+
depth-estimate = "depth_estimation.cli:main"
|
|
67
|
+
|
|
65
68
|
[tool.setuptools.packages.find]
|
|
66
69
|
where = ["src"]
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""
|
|
2
|
+
depth_estimation — A Transformers-style Python library for monocular depth estimation.
|
|
3
|
+
|
|
4
|
+
Provides a unified, modular API for running, comparing, and integrating
|
|
5
|
+
depth estimation models.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from .output import DepthOutput
|
|
9
|
+
from .configuration_utils import BaseDepthConfig
|
|
10
|
+
from .registry import MODEL_REGISTRY
|
|
11
|
+
|
|
12
|
+
# Auto classes
|
|
13
|
+
from .models.auto import AutoDepthModel, AutoProcessor
|
|
14
|
+
|
|
15
|
+
# Ensure model modules are imported so they self-register.
|
|
16
|
+
# These are now torch-free — modeling classes are loaded lazily on first use.
|
|
17
|
+
from .models import depth_anything_v1 # noqa: F401
|
|
18
|
+
from .models import depth_anything_v2 # noqa: F401
|
|
19
|
+
from .models import depth_anything_v3 # noqa: F401
|
|
20
|
+
from .models import zoedepth # noqa: F401
|
|
21
|
+
from .models import midas # noqa: F401
|
|
22
|
+
from .models import depth_pro # noqa: F401
|
|
23
|
+
from .models import pixel_perfect_depth # noqa: F401
|
|
24
|
+
from .models import marigold_dc # noqa: F401
|
|
25
|
+
from .models import moge # noqa: F401
|
|
26
|
+
from .models import omnivggt # noqa: F401
|
|
27
|
+
from .models import vggt # noqa: F401
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def __getattr__(name):
|
|
31
|
+
"""Defer torch-heavy imports until first use."""
|
|
32
|
+
if name == "BaseDepthModel":
|
|
33
|
+
from .modeling_utils import BaseDepthModel
|
|
34
|
+
globals()["BaseDepthModel"] = BaseDepthModel
|
|
35
|
+
return BaseDepthModel
|
|
36
|
+
if name == "DepthProcessor":
|
|
37
|
+
from .processing_utils import DepthProcessor
|
|
38
|
+
globals()["DepthProcessor"] = DepthProcessor
|
|
39
|
+
return DepthProcessor
|
|
40
|
+
if name == "DepthPipeline":
|
|
41
|
+
from .pipeline_utils import DepthPipeline
|
|
42
|
+
globals()["DepthPipeline"] = DepthPipeline
|
|
43
|
+
return DepthPipeline
|
|
44
|
+
if name == "pipeline":
|
|
45
|
+
from .pipeline_utils import pipeline
|
|
46
|
+
globals()["pipeline"] = pipeline
|
|
47
|
+
return pipeline
|
|
48
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
"DepthOutput",
|
|
53
|
+
"BaseDepthConfig",
|
|
54
|
+
"BaseDepthModel",
|
|
55
|
+
"DepthProcessor",
|
|
56
|
+
"DepthPipeline",
|
|
57
|
+
"pipeline",
|
|
58
|
+
"AutoDepthModel",
|
|
59
|
+
"AutoProcessor",
|
|
60
|
+
"MODEL_REGISTRY",
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
__version__ = "0.0.7"
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Command-line interface for depth_estimation.
|
|
3
|
+
|
|
4
|
+
Entry point: depth-estimate
|
|
5
|
+
Subcommands: predict, list-models, info, benchmark
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import argparse
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import List, Optional
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
|
+
# Helpers
|
|
18
|
+
# ---------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
VIDEO_EXTENSIONS = {".mp4", ".avi", ".mov", ".mkv", ".webm", ".flv", ".wmv"}
|
|
21
|
+
IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".bmp", ".tiff", ".tif", ".webp"}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _die(msg: str) -> None:
|
|
25
|
+
print(f"Error: {msg}", file=sys.stderr)
|
|
26
|
+
sys.exit(1)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _save_result(result, output_path: Path, fmt: str, source_path: Optional[Path] = None) -> None:
|
|
30
|
+
"""Save a DepthOutput to disk in the requested format."""
|
|
31
|
+
import cv2
|
|
32
|
+
import numpy as np
|
|
33
|
+
|
|
34
|
+
if fmt in ("png", "both"):
|
|
35
|
+
if result.colored_depth is not None:
|
|
36
|
+
png_path = output_path.with_suffix(".png")
|
|
37
|
+
bgr = cv2.cvtColor(result.colored_depth, cv2.COLOR_RGB2BGR)
|
|
38
|
+
cv2.imwrite(str(png_path), bgr)
|
|
39
|
+
|
|
40
|
+
if fmt in ("npy", "both"):
|
|
41
|
+
npy_path = output_path.with_suffix(".npy")
|
|
42
|
+
np.save(str(npy_path), result.depth)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _resolve_output_path(source: Path, output_arg: Optional[str], output_dir: Optional[str]) -> Path:
|
|
46
|
+
"""Work out where to write the output file."""
|
|
47
|
+
if output_arg:
|
|
48
|
+
return Path(output_arg)
|
|
49
|
+
base = output_dir or source.parent
|
|
50
|
+
return Path(base) / (source.stem + "_depth")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _print_table(headers: List[str], rows: List[List[str]]) -> None:
|
|
54
|
+
"""Print a plain-text table with aligned columns."""
|
|
55
|
+
col_widths = [len(h) for h in headers]
|
|
56
|
+
for row in rows:
|
|
57
|
+
for i, cell in enumerate(row):
|
|
58
|
+
col_widths[i] = max(col_widths[i], len(str(cell)))
|
|
59
|
+
|
|
60
|
+
fmt = " ".join(f"{{:<{w}}}" for w in col_widths)
|
|
61
|
+
sep = " ".join("-" * w for w in col_widths)
|
|
62
|
+
print(fmt.format(*headers))
|
|
63
|
+
print(sep)
|
|
64
|
+
for row in rows:
|
|
65
|
+
print(fmt.format(*[str(c) for c in row]))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# ---------------------------------------------------------------------------
|
|
69
|
+
# predict
|
|
70
|
+
# ---------------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
def _collect_images(source: str) -> List[Path]:
|
|
73
|
+
"""Expand source (file, directory, or glob) to a list of image paths."""
|
|
74
|
+
import glob as _glob
|
|
75
|
+
|
|
76
|
+
# Glob pattern
|
|
77
|
+
if any(c in source for c in ("*", "?", "[")):
|
|
78
|
+
paths = [Path(p) for p in _glob.glob(source, recursive=True)]
|
|
79
|
+
return sorted(p for p in paths if p.suffix.lower() in IMAGE_EXTENSIONS)
|
|
80
|
+
|
|
81
|
+
p = Path(source)
|
|
82
|
+
|
|
83
|
+
if p.is_dir():
|
|
84
|
+
return sorted(
|
|
85
|
+
f for f in p.iterdir() if f.suffix.lower() in IMAGE_EXTENSIONS
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
if p.is_file():
|
|
89
|
+
return [p]
|
|
90
|
+
|
|
91
|
+
_die(f"Source not found: {source}")
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _run_predict(args: argparse.Namespace) -> None:
|
|
95
|
+
source = args.source
|
|
96
|
+
model_id = args.model
|
|
97
|
+
colormap = args.colormap
|
|
98
|
+
fmt = args.format
|
|
99
|
+
batch_size = args.batch_size
|
|
100
|
+
device = args.device
|
|
101
|
+
quiet = args.quiet
|
|
102
|
+
output_arg = args.output
|
|
103
|
+
output_dir = args.output_dir
|
|
104
|
+
|
|
105
|
+
# ---- Video branch ----
|
|
106
|
+
src_path = Path(source)
|
|
107
|
+
if src_path.is_file() and src_path.suffix.lower() in VIDEO_EXTENSIONS:
|
|
108
|
+
_run_predict_video(src_path, model_id, output_arg, colormap, fmt, device, quiet)
|
|
109
|
+
return
|
|
110
|
+
|
|
111
|
+
# ---- Image branch ----
|
|
112
|
+
image_paths = _collect_images(source)
|
|
113
|
+
if not image_paths:
|
|
114
|
+
_die(f"No images found at: {source}")
|
|
115
|
+
|
|
116
|
+
if not quiet:
|
|
117
|
+
print(f"Loading model: {model_id}")
|
|
118
|
+
|
|
119
|
+
from depth_estimation import pipeline as _pipeline
|
|
120
|
+
pipe = _pipeline("depth-estimation", model=model_id, device=device)
|
|
121
|
+
|
|
122
|
+
if output_dir:
|
|
123
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
124
|
+
|
|
125
|
+
# Process in batches
|
|
126
|
+
total = len(image_paths)
|
|
127
|
+
for i in range(0, total, batch_size):
|
|
128
|
+
batch_paths = image_paths[i : i + batch_size]
|
|
129
|
+
batch_inputs = [str(p) for p in batch_paths]
|
|
130
|
+
|
|
131
|
+
results = pipe(batch_inputs, batch_size=batch_size, colorize=(fmt in ("png", "both")), colormap=colormap)
|
|
132
|
+
|
|
133
|
+
if not isinstance(results, list):
|
|
134
|
+
results = [results]
|
|
135
|
+
|
|
136
|
+
for path, result in zip(batch_paths, results):
|
|
137
|
+
out_path = _resolve_output_path(path, output_arg if total == 1 else None, output_dir)
|
|
138
|
+
_save_result(result, out_path, fmt, source_path=path)
|
|
139
|
+
if not quiet:
|
|
140
|
+
saved = out_path.with_suffix(".png") if fmt in ("png", "both") else out_path.with_suffix(".npy")
|
|
141
|
+
print(f" [{i + batch_paths.index(path) + 1}/{total}] {path.name} -> {saved}")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _run_predict_video(
|
|
145
|
+
src_path: Path,
|
|
146
|
+
model_id: str,
|
|
147
|
+
output_arg: Optional[str],
|
|
148
|
+
colormap: str,
|
|
149
|
+
fmt: str,
|
|
150
|
+
device: Optional[str],
|
|
151
|
+
quiet: bool,
|
|
152
|
+
) -> None:
|
|
153
|
+
import cv2
|
|
154
|
+
import numpy as np
|
|
155
|
+
|
|
156
|
+
out_video_path = Path(output_arg) if output_arg else src_path.parent / (src_path.stem + "_depth.mp4")
|
|
157
|
+
|
|
158
|
+
if not quiet:
|
|
159
|
+
print(f"Loading model: {model_id}")
|
|
160
|
+
|
|
161
|
+
from depth_estimation import pipeline as _pipeline
|
|
162
|
+
pipe = _pipeline("depth-estimation", model=model_id, device=device)
|
|
163
|
+
|
|
164
|
+
cap = cv2.VideoCapture(str(src_path))
|
|
165
|
+
if not cap.isOpened():
|
|
166
|
+
_die(f"Cannot open video: {src_path}")
|
|
167
|
+
|
|
168
|
+
fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
|
|
169
|
+
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
170
|
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
171
|
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
|
172
|
+
|
|
173
|
+
# Side-by-side doubles width
|
|
174
|
+
out_w = width * 2
|
|
175
|
+
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
|
|
176
|
+
writer = cv2.VideoWriter(str(out_video_path), fourcc, fps, (out_w, height))
|
|
177
|
+
|
|
178
|
+
if not quiet:
|
|
179
|
+
print(f"Processing video: {src_path.name} ({total_frames} frames)")
|
|
180
|
+
|
|
181
|
+
frame_idx = 0
|
|
182
|
+
while True:
|
|
183
|
+
ret, frame_bgr = cap.read()
|
|
184
|
+
if not ret:
|
|
185
|
+
break
|
|
186
|
+
|
|
187
|
+
frame_rgb = cv2.cvtColor(frame_bgr, cv2.COLOR_BGR2RGB)
|
|
188
|
+
result = pipe(frame_rgb, colorize=True, colormap=colormap)
|
|
189
|
+
|
|
190
|
+
if result.colored_depth is not None:
|
|
191
|
+
depth_bgr = cv2.cvtColor(result.colored_depth, cv2.COLOR_RGB2BGR)
|
|
192
|
+
depth_resized = cv2.resize(depth_bgr, (width, height))
|
|
193
|
+
else:
|
|
194
|
+
depth_arr = (result.depth * 255).astype(np.uint8)
|
|
195
|
+
depth_bgr = cv2.applyColorMap(depth_arr, cv2.COLORMAP_INFERNO)
|
|
196
|
+
depth_resized = cv2.resize(depth_bgr, (width, height))
|
|
197
|
+
|
|
198
|
+
combined = np.concatenate([frame_bgr, depth_resized], axis=1)
|
|
199
|
+
writer.write(combined)
|
|
200
|
+
|
|
201
|
+
frame_idx += 1
|
|
202
|
+
if not quiet and frame_idx % 10 == 0:
|
|
203
|
+
pct = int(frame_idx / max(total_frames, 1) * 100)
|
|
204
|
+
print(f" {frame_idx}/{total_frames} frames ({pct}%)", end="\r")
|
|
205
|
+
|
|
206
|
+
cap.release()
|
|
207
|
+
writer.release()
|
|
208
|
+
if not quiet:
|
|
209
|
+
print(f"\nSaved: {out_video_path}")
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# ---------------------------------------------------------------------------
|
|
213
|
+
# list-models
|
|
214
|
+
# ---------------------------------------------------------------------------
|
|
215
|
+
|
|
216
|
+
def _run_list_models(args: argparse.Namespace) -> None:
|
|
217
|
+
# Import triggers all model self-registrations
|
|
218
|
+
from depth_estimation import MODEL_REGISTRY
|
|
219
|
+
import depth_estimation # noqa: F401
|
|
220
|
+
|
|
221
|
+
variants = MODEL_REGISTRY.list_variants()
|
|
222
|
+
|
|
223
|
+
if args.json:
|
|
224
|
+
rows = []
|
|
225
|
+
for v in sorted(variants):
|
|
226
|
+
model_type = MODEL_REGISTRY.resolve_model_type(v)
|
|
227
|
+
config_cls = MODEL_REGISTRY.get_config_cls(v)
|
|
228
|
+
cfg = config_cls() if not hasattr(config_cls, "from_variant") else config_cls.from_variant(v)
|
|
229
|
+
rows.append({
|
|
230
|
+
"variant": v,
|
|
231
|
+
"model_type": model_type,
|
|
232
|
+
"is_metric": getattr(cfg, "is_metric", False),
|
|
233
|
+
"backbone": getattr(cfg, "backbone", "—"),
|
|
234
|
+
})
|
|
235
|
+
print(json.dumps(rows, indent=2))
|
|
236
|
+
return
|
|
237
|
+
|
|
238
|
+
headers = ["Variant", "Model Type", "Type", "Backbone"]
|
|
239
|
+
rows = []
|
|
240
|
+
for v in sorted(variants):
|
|
241
|
+
model_type = MODEL_REGISTRY.resolve_model_type(v)
|
|
242
|
+
config_cls = MODEL_REGISTRY.get_config_cls(v)
|
|
243
|
+
try:
|
|
244
|
+
cfg = config_cls.from_variant(v) if hasattr(config_cls, "from_variant") else config_cls()
|
|
245
|
+
except Exception:
|
|
246
|
+
cfg = config_cls()
|
|
247
|
+
depth_type = "metric" if getattr(cfg, "is_metric", False) else "relative"
|
|
248
|
+
backbone = getattr(cfg, "backbone", "—")
|
|
249
|
+
rows.append([v, model_type, depth_type, backbone])
|
|
250
|
+
|
|
251
|
+
_print_table(headers, rows)
|
|
252
|
+
print(f"\n{len(variants)} variants across {len(MODEL_REGISTRY.list_model_types())} model families.")
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
# ---------------------------------------------------------------------------
|
|
256
|
+
# info
|
|
257
|
+
# ---------------------------------------------------------------------------
|
|
258
|
+
|
|
259
|
+
def _run_info(args: argparse.Namespace) -> None:
|
|
260
|
+
from depth_estimation import MODEL_REGISTRY
|
|
261
|
+
import depth_estimation # noqa: F401
|
|
262
|
+
|
|
263
|
+
model_id = args.model_id
|
|
264
|
+
|
|
265
|
+
try:
|
|
266
|
+
model_type = MODEL_REGISTRY.resolve_model_type(model_id)
|
|
267
|
+
except ValueError as e:
|
|
268
|
+
_die(str(e))
|
|
269
|
+
|
|
270
|
+
config_cls = MODEL_REGISTRY.get_config_cls(model_id)
|
|
271
|
+
try:
|
|
272
|
+
cfg = config_cls.from_variant(model_id) if hasattr(config_cls, "from_variant") else config_cls()
|
|
273
|
+
except Exception:
|
|
274
|
+
cfg = config_cls()
|
|
275
|
+
|
|
276
|
+
info = {
|
|
277
|
+
"variant": model_id,
|
|
278
|
+
"model_type": model_type,
|
|
279
|
+
"backbone": getattr(cfg, "backbone", "—"),
|
|
280
|
+
"depth_type": "metric" if getattr(cfg, "is_metric", False) else "relative",
|
|
281
|
+
"input_size": getattr(cfg, "input_size", "—"),
|
|
282
|
+
"patch_size": getattr(cfg, "patch_size", "—"),
|
|
283
|
+
"embed_dim": getattr(cfg, "embed_dim", "—"),
|
|
284
|
+
"num_heads": getattr(cfg, "num_heads", "—"),
|
|
285
|
+
"num_layers": getattr(cfg, "num_layers", "—"),
|
|
286
|
+
"max_depth": getattr(cfg, "max_depth", None),
|
|
287
|
+
"min_depth": getattr(cfg, "min_depth", None),
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if args.json:
|
|
291
|
+
print(json.dumps(info, indent=2))
|
|
292
|
+
return
|
|
293
|
+
|
|
294
|
+
print(f"\nModel: {model_id}")
|
|
295
|
+
print("-" * 40)
|
|
296
|
+
for k, v in info.items():
|
|
297
|
+
if k == "variant":
|
|
298
|
+
continue
|
|
299
|
+
label = k.replace("_", " ").title()
|
|
300
|
+
if v is not None:
|
|
301
|
+
print(f" {label:<16} {v}")
|
|
302
|
+
print()
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
# ---------------------------------------------------------------------------
|
|
306
|
+
# benchmark (stub)
|
|
307
|
+
# ---------------------------------------------------------------------------
|
|
308
|
+
|
|
309
|
+
def _run_benchmark(args: argparse.Namespace) -> None:
|
|
310
|
+
print("benchmark: not yet implemented (depends on the evaluation suite).")
|
|
311
|
+
print("Coming in v0.1.1.")
|
|
312
|
+
sys.exit(0)
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
# ---------------------------------------------------------------------------
|
|
316
|
+
# Argument parser
|
|
317
|
+
# ---------------------------------------------------------------------------
|
|
318
|
+
|
|
319
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
320
|
+
parser = argparse.ArgumentParser(
|
|
321
|
+
prog="depth-estimate",
|
|
322
|
+
description="depth_estimation CLI — run depth estimation models from the command line.",
|
|
323
|
+
)
|
|
324
|
+
parser.add_argument("--device", default=None, help="Device: cuda, cpu, mps (auto-detected if omitted).")
|
|
325
|
+
parser.add_argument("--quiet", "-q", action="store_true", help="Suppress progress output.")
|
|
326
|
+
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose logging.")
|
|
327
|
+
|
|
328
|
+
sub = parser.add_subparsers(dest="subcommand", metavar="SUBCOMMAND")
|
|
329
|
+
sub.required = True
|
|
330
|
+
|
|
331
|
+
# ---- predict ----
|
|
332
|
+
p_predict = sub.add_parser(
|
|
333
|
+
"predict",
|
|
334
|
+
help="Run depth estimation on an image, directory, glob, or video.",
|
|
335
|
+
)
|
|
336
|
+
p_predict.add_argument("source", help="Image path, directory, glob pattern (quoted), or video file.")
|
|
337
|
+
p_predict.add_argument("--model", "-m", required=True, help="Model variant ID (e.g. depth-anything-v2-vitb).")
|
|
338
|
+
p_predict.add_argument("--output", "-o", default=None, help="Output file path (single image / video).")
|
|
339
|
+
p_predict.add_argument("--output-dir", default=None, help="Output directory for batch predictions.")
|
|
340
|
+
p_predict.add_argument(
|
|
341
|
+
"--colormap", default="Spectral_r", help="Matplotlib colormap name (default: Spectral_r)."
|
|
342
|
+
)
|
|
343
|
+
p_predict.add_argument(
|
|
344
|
+
"--format",
|
|
345
|
+
choices=["png", "npy", "both"],
|
|
346
|
+
default="png",
|
|
347
|
+
help="Output format: png (colored), npy (raw float32), or both (default: png).",
|
|
348
|
+
)
|
|
349
|
+
p_predict.add_argument("--batch-size", type=int, default=1, help="Batch size for image processing (default: 1).")
|
|
350
|
+
|
|
351
|
+
# ---- list-models ----
|
|
352
|
+
p_list = sub.add_parser("list-models", help="List all available model variants.")
|
|
353
|
+
p_list.add_argument("--json", action="store_true", help="Output as JSON.")
|
|
354
|
+
|
|
355
|
+
# ---- info ----
|
|
356
|
+
p_info = sub.add_parser("info", help="Show configuration details for a model variant.")
|
|
357
|
+
p_info.add_argument("model_id", help="Model variant ID (e.g. depth-anything-v2-vitb).")
|
|
358
|
+
p_info.add_argument("--json", action="store_true", help="Output as JSON.")
|
|
359
|
+
|
|
360
|
+
# ---- benchmark ----
|
|
361
|
+
sub.add_parser("benchmark", help="(Coming soon) Evaluate a model on a standard dataset.")
|
|
362
|
+
|
|
363
|
+
return parser
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
# ---------------------------------------------------------------------------
|
|
367
|
+
# Entry point
|
|
368
|
+
# ---------------------------------------------------------------------------
|
|
369
|
+
|
|
370
|
+
def main() -> None:
|
|
371
|
+
parser = _build_parser()
|
|
372
|
+
args = parser.parse_args()
|
|
373
|
+
|
|
374
|
+
if args.verbose:
|
|
375
|
+
import logging
|
|
376
|
+
logging.basicConfig(level=logging.INFO)
|
|
377
|
+
|
|
378
|
+
dispatch = {
|
|
379
|
+
"predict": _run_predict,
|
|
380
|
+
"list-models": _run_list_models,
|
|
381
|
+
"info": _run_info,
|
|
382
|
+
"benchmark": _run_benchmark,
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
dispatch[args.subcommand](args)
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
if __name__ == "__main__":
|
|
389
|
+
main()
|
|
@@ -5,7 +5,6 @@ AutoProcessor — Automatic processor resolution via the global registry.
|
|
|
5
5
|
from typing import Any, Optional
|
|
6
6
|
|
|
7
7
|
from ...registry import MODEL_REGISTRY
|
|
8
|
-
from ...processing_utils import DepthProcessor
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
class AutoProcessor:
|
|
@@ -25,7 +24,7 @@ class AutoProcessor:
|
|
|
25
24
|
)
|
|
26
25
|
|
|
27
26
|
@staticmethod
|
|
28
|
-
def from_pretrained(model_id: str, **kwargs: Any)
|
|
27
|
+
def from_pretrained(model_id: str, **kwargs: Any):
|
|
29
28
|
"""Create a DepthProcessor configured for the given model.
|
|
30
29
|
|
|
31
30
|
Args:
|
|
@@ -46,4 +45,5 @@ class AutoProcessor:
|
|
|
46
45
|
else:
|
|
47
46
|
config = config_cls()
|
|
48
47
|
|
|
48
|
+
from ...processing_utils import DepthProcessor
|
|
49
49
|
return DepthProcessor.from_config(config)
|