-
Notifications
You must be signed in to change notification settings - Fork 30k
Add Prompt Depth Anything Model #35401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
qubvel
merged 61 commits into
huggingface:main
from
haotongl:modeling_prompt_depth_anything
Mar 20, 2025
Merged
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
24151d8
add prompt depth anything model by modular transformer
haotongl 7e6dcaa
add prompt depth anything docs and imports
haotongl dfa7d67
update code style according transformers doc
haotongl 8509440
update code style: import order issue is fixed by custom_init_isort
haotongl 2fa72ef
fix depth shape from B,1,H,W to B,H,W which is as the same as Depth A…
haotongl d13a55f
move prompt depth anything to vision models in _toctree.yml
haotongl 6cd1bbf
update backbone test; there is no need for resnet18 backbone test
haotongl 76299f4
update init file & pass RUN_SLOW tests
haotongl 2315dd1
update len(prompt_depth) to prompt_depth.shape[0]
haotongl c423e91
fix torch_int/model_doc
haotongl 739c07f
fix typo
haotongl 5c046e8
update PromptDepthAnythingImageProcessor
haotongl f3a8aa4
fix typo
haotongl c2647ca
fix typo for prompt depth anything doc
haotongl ea67b90
update promptda overview image link of huggingface repo
haotongl b2379d6
fix some typos in promptda doc
haotongl b9a44fb
Update image processing to include pad_image, prompt depth position, …
haotongl dfee43f
add copy disclaimer for prompt depth anything image processing
haotongl db9f301
fix some format typos in image processing and conversion scripts
haotongl 8d0a435
fix nn.ReLU(False) to nn.ReLU()
haotongl 89956c4
rename residual layer as it's a sequential layer
haotongl c713a5e
move size compute to a separate line/variable for easier debug in mod…
haotongl 777c367
fix modular format for prompt depth anything
haotongl cc8f4ac
update modular prompt depth anything
haotongl 0848054
fix scale to meter and some internal funcs warp
haotongl 25e1144
fix code style in image_processing_prompt_depth_anything.py
haotongl 3c8f6c0
fix issues in image_processing_prompt_depth_anything.py
haotongl cf24f48
fix issues in image_processing_prompt_depth_anything.py
haotongl fcd5107
fix issues in prompt depth anything
haotongl d9f6ecf
update converting script similar to mllamma
haotongl 357cc12
update testing for modeling prompt depth anything
haotongl f79f912
update testing for image_processing_prompt_depth_anything
haotongl 2aa3363
fix assertion in image_processing_prompt_depth_anything
haotongl 17bd168
Update src/transformers/models/prompt_depth_anything/modular_prompt_d…
haotongl 1d7a6d0
Update src/transformers/models/prompt_depth_anything/modular_prompt_d…
haotongl ab381ca
Update src/transformers/models/prompt_depth_anything/image_processing…
haotongl a509ad1
Update src/transformers/models/prompt_depth_anything/image_processing…
haotongl 188b88d
Update src/transformers/models/prompt_depth_anything/image_processing…
haotongl 9d48d97
Update docs/source/en/model_doc/prompt_depth_anything.md
haotongl c033e6c
Update docs/source/en/model_doc/prompt_depth_anything.md
haotongl c2693f8
update some testing
haotongl d957f56
fix testing
haotongl b34e35a
fix
haotongl 27e2e49
add return doc for forward of prompt depth anything
haotongl cc9c0b7
Update src/transformers/models/prompt_depth_anything/modular_prompt_d…
haotongl e8ac526
Update tests/models/prompt_depth_anything/test_modeling_prompt_depth_…
haotongl 0ffa387
fix prompt depth order
haotongl 51acb23
fix format for testing prompt depth anything
haotongl 149225b
fix minor issues in prompt depth anything doc
haotongl f094257
fix format for modular prompt depth anything
haotongl a6089ff
revert format for modular prompt depth anything
haotongl 2caf27c
revert format for modular prompt depth anything
haotongl 2e957c4
Merge branch 'main' into modeling_prompt_depth_anything
haotongl fca03fb
update format for modular prompt depth anything
haotongl f16f9b4
fix parallel testing errors
haotongl 47178a6
fix doc for prompt depth anything
haotongl d1b4793
Merge branch 'main' into modeling_prompt_depth_anything
haotongl fe7ec93
Add header
qubvel 95abf26
Fix imports
qubvel 92b23f0
Merge branch 'main' into pr/haotongl/35401
qubvel e7330fc
Licence header
qubvel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<!--Copyright 2024 The HuggingFace Team. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
|
||
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | ||
rendered properly in your Markdown viewer. | ||
|
||
--> | ||
|
||
# Prompt Depth Anything | ||
|
||
## Overview | ||
|
||
The Prompt Depth Anything model was introduced in [Prompting Depth Anything for 4K Resolution Accurate Metric Depth Estimation](https://arxiv.org/abs/2412.14015) by Haotong Lin, Sida Peng, Jingxiao Chen, Songyou Peng, Jiaming Sun, Minghuan Liu, Hujun Bao, Jiashi Feng, Xiaowei Zhou, Bingyi Kang. | ||
|
||
|
||
The abstract from the paper is as follows: | ||
|
||
*Prompts play a critical role in unleashing the power of language and vision foundation models for specific tasks. For the first time, we introduce prompting into depth foundation models, creating a new paradigm for metric depth estimation termed Prompt Depth Anything. Specifically, we use a low-cost LiDAR as the prompt to guide the Depth Anything model for accurate metric depth output, achieving up to 4K resolution. Our approach centers on a concise prompt fusion design that integrates the LiDAR at multiple scales within the depth decoder. To address training challenges posed by limited datasets containing both LiDAR depth and precise GT depth, we propose a scalable data pipeline that includes synthetic data LiDAR simulation and real data pseudo GT depth generation. Our approach sets new state-of-the-arts on the ARKitScenes and ScanNet++ datasets and benefits downstream applications, including 3D reconstruction and generalized robotic grasping.* | ||
|
||
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/model_doc/prompt_depth_anything_architecture.jpg" | ||
alt="drawing" width="600"/> | ||
|
||
<small> Prompt Depth Anything overview. Taken from the <a href="https://arxiv.org/pdf/2412.14015">original paper</a>.</small> | ||
|
||
## Usage example | ||
|
||
The Transformers library allows you to use the model with just a few lines of code: | ||
|
||
```python | ||
>>> import torch | ||
>>> import requests | ||
>>> import numpy as np | ||
|
||
>>> from PIL import Image | ||
>>> from transformers import AutoImageProcessor, AutoModelForDepthEstimation | ||
|
||
>>> url = "https://github.com/DepthAnything/PromptDA/blob/main/assets/example_images/image.jpg?raw=true" | ||
>>> image = Image.open(requests.get(url, stream=True).raw) | ||
|
||
>>> image_processor = AutoImageProcessor.from_pretrained("depth-anything/prompt-depth-anything-vits-hf") | ||
>>> model = AutoModelForDepthEstimation.from_pretrained("depth-anything/prompt-depth-anything-vits-hf") | ||
|
||
>>> prompt_depth_url = "https://github.com/DepthAnything/PromptDA/blob/main/assets/example_images/arkit_depth.png?raw=true" | ||
>>> prompt_depth = Image.open(requests.get(prompt_depth_url, stream=True).raw) | ||
>>> # the prompt depth can be None, and the model will output a monocular relative depth. | ||
|
||
>>> # prepare image for the model | ||
>>> inputs = image_processor(images=image, return_tensors="pt", prompt_depth=prompt_depth) | ||
|
||
>>> with torch.no_grad(): | ||
... outputs = model(**inputs) | ||
|
||
>>> # interpolate to original size | ||
>>> post_processed_output = image_processor.post_process_depth_estimation( | ||
... outputs, | ||
... target_sizes=[(image.height, image.width)], | ||
... ) | ||
|
||
>>> # visualize the prediction | ||
>>> predicted_depth = post_processed_output[0]["predicted_depth"] | ||
>>> depth = predicted_depth * 1000 | ||
>>> depth = depth.detach().cpu().numpy() | ||
>>> depth = Image.fromarray(depth.astype("uint16")) # mm | ||
Comment on lines
+67
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this go in |
||
``` | ||
|
||
## Resources | ||
|
||
A list of official Hugging Face and community (indicated by 🌎) resources to help you get started with Prompt Depth Anything. | ||
|
||
- [Prompt Depth Anything Demo](https://huggingface.co/spaces/depth-anything/PromptDA) | ||
- [Prompt Depth Anything Interactive Results](https://promptda.github.io/interactive.html) | ||
|
||
If you are interested in submitting a resource to be included here, please feel free to open a Pull Request and we'll review it! The resource should ideally demonstrate something new instead of duplicating an existing resource. | ||
|
||
## PromptDepthAnythingConfig | ||
|
||
[[autodoc]] PromptDepthAnythingConfig | ||
|
||
## PromptDepthAnythingForDepthEstimation | ||
|
||
[[autodoc]] PromptDepthAnythingForDepthEstimation | ||
- forward | ||
|
||
## PromptDepthAnythingImageProcessor | ||
|
||
[[autodoc]] PromptDepthAnythingImageProcessor | ||
- preprocess | ||
- post_process_depth_estimation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,6 +219,7 @@ | |
plbart, | ||
poolformer, | ||
pop2piano, | ||
prompt_depth_anything, | ||
prophetnet, | ||
pvt, | ||
pvt_v2, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2024 The HuggingFace Team. All rights reserved. | ||
NielsRogge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from typing import TYPE_CHECKING | ||
|
||
from ...utils import _LazyModule | ||
from ...utils.import_utils import define_import_structure | ||
|
||
|
||
if TYPE_CHECKING: | ||
from .configuration_prompt_depth_anything import PromptDepthAnythingConfig | ||
from .image_processing_prompt_depth_anything import PromptDepthAnythingImageProcessor | ||
from .modeling_prompt_depth_anything import ( | ||
PromptDepthAnythingForDepthEstimation, | ||
PromptDepthAnythingPreTrainedModel, | ||
) | ||
else: | ||
import sys | ||
|
||
_file = globals()["__file__"] | ||
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.