hysts HF staff commited on
Commit
6eb061b
·
1 Parent(s): 0c17caf
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.jpg filter=lfs diff=lfs merge=lfs -text
.pre-commit-config.yaml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0
4
+ hooks:
5
+ - id: check-executables-have-shebangs
6
+ - id: check-json
7
+ - id: check-merge-conflict
8
+ - id: check-shebang-scripts-are-executable
9
+ - id: check-toml
10
+ - id: check-yaml
11
+ - id: end-of-file-fixer
12
+ - id: mixed-line-ending
13
+ args: ["--fix=lf"]
14
+ - id: requirements-txt-fixer
15
+ - id: trailing-whitespace
16
+ - repo: https://github.com/astral-sh/ruff-pre-commit
17
+ rev: v0.9.6
18
+ hooks:
19
+ - id: ruff
20
+ args: ["--fix"]
21
+ - id: ruff-format
22
+ - repo: https://github.com/pre-commit/mirrors-mypy
23
+ rev: v1.15.0
24
+ hooks:
25
+ - id: mypy
26
+ args: ["--ignore-missing-imports"]
27
+ additional_dependencies:
28
+ [
29
+ "types-python-slugify",
30
+ "types-pytz",
31
+ "types-PyYAML",
32
+ "types-requests",
33
+ ]
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.10
.vscode/extensions.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "recommendations": [
3
+ "ms-python.python",
4
+ "charliermarsh.ruff",
5
+ "streetsidesoftware.code-spell-checker",
6
+ "tamasfe.even-better-toml"
7
+ ]
8
+ }
.vscode/settings.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "files.insertFinalNewline": false,
4
+ "[python]": {
5
+ "editor.defaultFormatter": "charliermarsh.ruff",
6
+ "editor.formatOnType": true,
7
+ "editor.codeActionsOnSave": {
8
+ "source.fixAll.ruff": "explicit",
9
+ "source.organizeImports": "explicit"
10
+ }
11
+ },
12
+ "[jupyter]": {
13
+ "files.insertFinalNewline": false
14
+ },
15
+ "notebook.output.scrolling": true,
16
+ "notebook.formatOnSave.enabled": true
17
+ }
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 hysts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
  title: DepthPro Transformers
3
- emoji: 📊
4
- colorFrom: blue
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 5.16.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
  title: DepthPro Transformers
3
+ emoji:
4
+ colorFrom: red
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 4.44.1
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ import pathlib
4
+
5
+ import gradio as gr
6
+ import matplotlib as mpl
7
+ import numpy as np
8
+ import PIL.Image
9
+ import spaces
10
+ import torch
11
+ from gradio_imageslider import ImageSlider
12
+ from transformers import DepthProForDepthEstimation, DepthProImageProcessorFast
13
+
14
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
+ image_processor = DepthProImageProcessorFast.from_pretrained("apple/DepthPro-hf")
16
+ model = DepthProForDepthEstimation.from_pretrained("apple/DepthPro-hf").to(device)
17
+
18
+ cmap = mpl.colormaps.get_cmap("Spectral_r")
19
+
20
+
21
+ @spaces.GPU(duration=10)
22
+ @torch.inference_mode()
23
+ def run(image: PIL.Image.Image) -> tuple[tuple[PIL.Image.Image, PIL.Image.Image], str, str, str, str]:
24
+ inputs = image_processor(images=image, return_tensors="pt").to(device)
25
+ outputs = model(**inputs)
26
+ post_processed_output = image_processor.post_process_depth_estimation(
27
+ outputs,
28
+ target_sizes=[(image.height, image.width)],
29
+ )
30
+ depth_raw = post_processed_output[0]["predicted_depth"]
31
+ depth_min = depth_raw.min().item()
32
+ depth_max = depth_raw.max().item()
33
+
34
+ inverse_depth = 1 / depth_raw
35
+
36
+ normalized_inverse_depth = (inverse_depth - inverse_depth.min()) / (inverse_depth.max() - inverse_depth.min())
37
+ normalized_inverse_depth = normalized_inverse_depth * 255.0
38
+ normalized_inverse_depth = normalized_inverse_depth.detach().cpu().numpy()
39
+ normalized_inverse_depth = PIL.Image.fromarray(normalized_inverse_depth.astype("uint8"))
40
+
41
+ colored_inverse_depth = PIL.Image.fromarray(
42
+ (cmap(np.array(normalized_inverse_depth))[:, :, :3] * 255).astype(np.uint8)
43
+ )
44
+
45
+ field_of_view = post_processed_output[0]["field_of_view"].item()
46
+ focal_length = post_processed_output[0]["focal_length"].item()
47
+
48
+ return (
49
+ (image, colored_inverse_depth),
50
+ f"{field_of_view:.2f}",
51
+ f"{focal_length:.2f}",
52
+ f"{depth_min:.2f}",
53
+ f"{depth_max:.2f}",
54
+ )
55
+
56
+
57
+ with gr.Blocks(css="style.css") as demo:
58
+ gr.Markdown("# DepthPro")
59
+ with gr.Row():
60
+ with gr.Column():
61
+ input_image = gr.Image(type="pil")
62
+ run_button = gr.Button()
63
+ with gr.Column():
64
+ output_image = ImageSlider()
65
+ with gr.Row():
66
+ output_field_of_view = gr.Textbox(label="Field of View")
67
+ output_focal_length = gr.Textbox(label="Focal Length")
68
+ output_depth_min = gr.Textbox(label="Depth Min")
69
+ output_depth_max = gr.Textbox(label="Depth Max")
70
+ gr.Examples(
71
+ examples=sorted(pathlib.Path("images").glob("*.jpg")),
72
+ inputs=input_image,
73
+ fn=run,
74
+ outputs=[
75
+ output_image,
76
+ output_field_of_view,
77
+ output_focal_length,
78
+ output_depth_min,
79
+ output_depth_max,
80
+ ],
81
+ )
82
+
83
+ run_button.click(
84
+ fn=run,
85
+ inputs=input_image,
86
+ outputs=[
87
+ output_image,
88
+ output_field_of_view,
89
+ output_focal_length,
90
+ output_depth_min,
91
+ output_depth_max,
92
+ ],
93
+ )
94
+
95
+ if __name__ == "__main__":
96
+ demo.queue().launch()
images/cats.jpg ADDED

Git LFS Details

  • SHA256: 114e83cc896e9df6476fd682c8d0dc8fafb76e8cf1da5f6396280040081ee1ca
  • Pointer size: 131 Bytes
  • Size of remote file: 681 kB
images/pexels-yan-krukov-5792907.jpg ADDED

Git LFS Details

  • SHA256: 0500121b9044cb1d4c7913e48ebe5e2374848d57d6a2905f3b7c9469f959f2fe
  • Pointer size: 131 Bytes
  • Size of remote file: 648 kB
pyproject.toml ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "depthpro-transformers"
3
+ version = "0.1.0"
4
+ description = ""
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "gradio<5",
9
+ "gradio-imageslider>=0.0.20",
10
+ "hf-transfer>=0.1.9",
11
+ "matplotlib>=3.10.0",
12
+ "spaces>=0.32.0",
13
+ "torch==2.4.0",
14
+ "torchvision>=0.19.0",
15
+ "transformers",
16
+ ]
17
+
18
+ [tool.ruff]
19
+ line-length = 119
20
+
21
+ [tool.ruff.lint]
22
+ select = ["ALL"]
23
+ ignore = [
24
+ "COM812", # missing-trailing-comma
25
+ "D203", # one-blank-line-before-class
26
+ "D213", # multi-line-summary-second-line
27
+ "E501", # line-too-long
28
+ "SIM117", # multiple-with-statements
29
+ ]
30
+ extend-ignore = [
31
+ "D100", # undocumented-public-module
32
+ "D101", # undocumented-public-class
33
+ "D102", # undocumented-public-method
34
+ "D103", # undocumented-public-function
35
+ "D104", # undocumented-public-package
36
+ "D105", # undocumented-magic-method
37
+ "D107", # undocumented-public-init
38
+ "EM101", # raw-string-in-exception
39
+ "FBT001", # boolean-type-hint-positional-argument
40
+ "FBT002", # boolean-default-value-positional-argument
41
+ "PD901", # pandas-df-variable-name
42
+ "PGH003", # blanket-type-ignore
43
+ "PLR0913", # too-many-arguments
44
+ "PLR0915", # too-many-statements
45
+ "TRY003", # raise-vanilla-args
46
+ ]
47
+ unfixable = [
48
+ "F401", # unused-import
49
+ ]
50
+
51
+ [tool.ruff.lint.pydocstyle]
52
+ convention = "google"
53
+
54
+ [tool.ruff.lint.per-file-ignores]
55
+ "*.ipynb" = ["T201"]
56
+
57
+ [tool.ruff.format]
58
+ docstring-code-format = true
59
+
60
+ [tool.uv.sources]
61
+ transformers = { git = "https://github.com/huggingface/transformers" }
requirements.txt ADDED
@@ -0,0 +1,258 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml -o requirements.txt
3
+ aiofiles==23.2.1
4
+ # via gradio
5
+ annotated-types==0.7.0
6
+ # via pydantic
7
+ anyio==4.8.0
8
+ # via
9
+ # gradio
10
+ # httpx
11
+ # starlette
12
+ certifi==2025.1.31
13
+ # via
14
+ # httpcore
15
+ # httpx
16
+ # requests
17
+ charset-normalizer==3.4.1
18
+ # via requests
19
+ click==8.1.8
20
+ # via
21
+ # typer
22
+ # uvicorn
23
+ contourpy==1.3.1
24
+ # via matplotlib
25
+ cycler==0.12.1
26
+ # via matplotlib
27
+ exceptiongroup==1.2.2
28
+ # via anyio
29
+ fastapi==0.115.8
30
+ # via gradio
31
+ ffmpy==0.5.0
32
+ # via gradio
33
+ filelock==3.17.0
34
+ # via
35
+ # huggingface-hub
36
+ # torch
37
+ # transformers
38
+ # triton
39
+ fonttools==4.56.0
40
+ # via matplotlib
41
+ fsspec==2025.2.0
42
+ # via
43
+ # gradio-client
44
+ # huggingface-hub
45
+ # torch
46
+ gradio==4.44.1
47
+ # via
48
+ # depthpro-transformers (pyproject.toml)
49
+ # gradio-imageslider
50
+ # spaces
51
+ gradio-client==1.3.0
52
+ # via gradio
53
+ gradio-imageslider==0.0.20
54
+ # via depthpro-transformers (pyproject.toml)
55
+ h11==0.14.0
56
+ # via
57
+ # httpcore
58
+ # uvicorn
59
+ hf-transfer==0.1.9
60
+ # via depthpro-transformers (pyproject.toml)
61
+ httpcore==1.0.7
62
+ # via httpx
63
+ httpx==0.28.1
64
+ # via
65
+ # gradio
66
+ # gradio-client
67
+ # spaces
68
+ huggingface-hub==0.28.1
69
+ # via
70
+ # gradio
71
+ # gradio-client
72
+ # tokenizers
73
+ # transformers
74
+ idna==3.10
75
+ # via
76
+ # anyio
77
+ # httpx
78
+ # requests
79
+ importlib-resources==6.5.2
80
+ # via gradio
81
+ jinja2==3.1.5
82
+ # via
83
+ # gradio
84
+ # torch
85
+ kiwisolver==1.4.8
86
+ # via matplotlib
87
+ markdown-it-py==3.0.0
88
+ # via rich
89
+ markupsafe==2.1.5
90
+ # via
91
+ # gradio
92
+ # jinja2
93
+ matplotlib==3.10.0
94
+ # via
95
+ # depthpro-transformers (pyproject.toml)
96
+ # gradio
97
+ mdurl==0.1.2
98
+ # via markdown-it-py
99
+ mpmath==1.3.0
100
+ # via sympy
101
+ networkx==3.4.2
102
+ # via torch
103
+ numpy==2.2.3
104
+ # via
105
+ # contourpy
106
+ # gradio
107
+ # matplotlib
108
+ # pandas
109
+ # torchvision
110
+ # transformers
111
+ nvidia-cublas-cu12==12.1.3.1
112
+ # via
113
+ # nvidia-cudnn-cu12
114
+ # nvidia-cusolver-cu12
115
+ # torch
116
+ nvidia-cuda-cupti-cu12==12.1.105
117
+ # via torch
118
+ nvidia-cuda-nvrtc-cu12==12.1.105
119
+ # via torch
120
+ nvidia-cuda-runtime-cu12==12.1.105
121
+ # via torch
122
+ nvidia-cudnn-cu12==9.1.0.70
123
+ # via torch
124
+ nvidia-cufft-cu12==11.0.2.54
125
+ # via torch
126
+ nvidia-curand-cu12==10.3.2.106
127
+ # via torch
128
+ nvidia-cusolver-cu12==11.4.5.107
129
+ # via torch
130
+ nvidia-cusparse-cu12==12.1.0.106
131
+ # via
132
+ # nvidia-cusolver-cu12
133
+ # torch
134
+ nvidia-nccl-cu12==2.20.5
135
+ # via torch
136
+ nvidia-nvjitlink-cu12==12.8.61
137
+ # via
138
+ # nvidia-cusolver-cu12
139
+ # nvidia-cusparse-cu12
140
+ nvidia-nvtx-cu12==12.1.105
141
+ # via torch
142
+ orjson==3.10.15
143
+ # via gradio
144
+ packaging==24.2
145
+ # via
146
+ # gradio
147
+ # gradio-client
148
+ # huggingface-hub
149
+ # matplotlib
150
+ # spaces
151
+ # transformers
152
+ pandas==2.2.3
153
+ # via gradio
154
+ pillow==10.4.0
155
+ # via
156
+ # gradio
157
+ # gradio-imageslider
158
+ # matplotlib
159
+ # torchvision
160
+ psutil==5.9.8
161
+ # via spaces
162
+ pydantic==2.10.6
163
+ # via
164
+ # fastapi
165
+ # gradio
166
+ # spaces
167
+ pydantic-core==2.27.2
168
+ # via pydantic
169
+ pydub==0.25.1
170
+ # via gradio
171
+ pygments==2.19.1
172
+ # via rich
173
+ pyparsing==3.2.1
174
+ # via matplotlib
175
+ python-dateutil==2.9.0.post0
176
+ # via
177
+ # matplotlib
178
+ # pandas
179
+ python-multipart==0.0.20
180
+ # via gradio
181
+ pytz==2025.1
182
+ # via pandas
183
+ pyyaml==6.0.2
184
+ # via
185
+ # gradio
186
+ # huggingface-hub
187
+ # transformers
188
+ regex==2024.11.6
189
+ # via transformers
190
+ requests==2.32.3
191
+ # via
192
+ # huggingface-hub
193
+ # spaces
194
+ # transformers
195
+ rich==13.9.4
196
+ # via typer
197
+ ruff==0.9.6
198
+ # via gradio
199
+ safetensors==0.5.2
200
+ # via transformers
201
+ semantic-version==2.10.0
202
+ # via gradio
203
+ shellingham==1.5.4
204
+ # via typer
205
+ six==1.17.0
206
+ # via python-dateutil
207
+ sniffio==1.3.1
208
+ # via anyio
209
+ spaces==0.32.0
210
+ # via depthpro-transformers (pyproject.toml)
211
+ starlette==0.45.3
212
+ # via fastapi
213
+ sympy==1.13.3
214
+ # via torch
215
+ tokenizers==0.21.0
216
+ # via transformers
217
+ tomlkit==0.12.0
218
+ # via gradio
219
+ torch==2.4.0
220
+ # via
221
+ # depthpro-transformers (pyproject.toml)
222
+ # torchvision
223
+ torchvision==0.19.0
224
+ # via depthpro-transformers (pyproject.toml)
225
+ tqdm==4.67.1
226
+ # via
227
+ # huggingface-hub
228
+ # transformers
229
+ transformers @ git+https://github.com/huggingface/transformers@336dc69d63d56f232a183a3e7f52790429b871ef
230
+ # via depthpro-transformers (pyproject.toml)
231
+ triton==3.0.0
232
+ # via torch
233
+ typer==0.15.1
234
+ # via gradio
235
+ typing-extensions==4.12.2
236
+ # via
237
+ # anyio
238
+ # fastapi
239
+ # gradio
240
+ # gradio-client
241
+ # huggingface-hub
242
+ # pydantic
243
+ # pydantic-core
244
+ # rich
245
+ # spaces
246
+ # torch
247
+ # typer
248
+ # uvicorn
249
+ tzdata==2025.1
250
+ # via pandas
251
+ urllib3==2.3.0
252
+ # via
253
+ # gradio
254
+ # requests
255
+ uvicorn==0.34.0
256
+ # via gradio
257
+ websockets==12.0
258
+ # via gradio-client
style.css ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ display: block;
4
+ }
5
+
6
+ #duplicate-button {
7
+ margin: auto;
8
+ color: #fff;
9
+ background: #1565c0;
10
+ border-radius: 100vh;
11
+ }
uv.lock ADDED
The diff for this file is too large to render. See raw diff