-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
Add Prompt Depth Anything Model #35401
Add Prompt Depth Anything Model #35401
Conversation
@NielsRogge @qubvel @pcuenca Could you help review this PR when you have some time? Thanks so much in advance! Let me know if you have any questions or suggestions. 😊 |
tests/models/prompt_depth_anything/test_modeling_prompt_depth_anything.py
Outdated
Show resolved
Hide resolved
Hi @haotongl! Thanks for working on the model integration to transformers 🤗 I'm on holidays until Jan 3rd, and I'll do a review after that if it's still necessary. |
src/transformers/models/prompt_depth_anything/modeling_prompt_depth_anything.py
Outdated
Show resolved
Hide resolved
src/transformers/models/prompt_depth_anything/modeling_prompt_depth_anything.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Joshua Lochner <admin@xenova.com>
Hi, @xenova @NielsRogge ! All suggestions have been addressed. Could you please take another look and provide any further suggestions, or go ahead and merge this PR? Thanks! |
Yes, only members can run slow tests |
This comment contains run-slow, running the specified jobs: ['models/prompt_depth_anything'] ... |
run-slow: prompt_depth_anything |
This comment contains run-slow, running the specified jobs: ['models/prompt_depth_anything'] ... |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Thank you! All checks have passed. @qubvel |
Thanks for fixing the tests! Waiting for the final review form @ArthurZucker |
Friendly ping @ArthurZucker 🤗 |
@ArthurZucker Hey, just a friendly ping to see if you’ve had a chance to look at the PR. Appreciate your help when you get a moment! |
Super sorry i will get to this soon 😭 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
>>> # 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this go in image_processor.visualize_detph_estimation
directly? 🤗
} | ||
|
||
|
||
ORIGINAL_TO_CONVERTED_KEY_MAPPING = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice thanks! 🤗
if is_vision_available(): | ||
pass | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if is_vision_available(): | |
pass |
@@ -0,0 +1,379 @@ | |||
from typing import List, Optional, Tuple, Union |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is missing a licence! 🤗
A few small conflicts to fix |
run-slow: prompt_depth_anything |
This comment contains run-slow, running the specified jobs: This comment contains run-slow, running the specified jobs: models: ['models/prompt_depth_anything'] |
Thanks for supporting! @qubvel @ArthurZucker |
Thanks for adding the model @haotongl! Can you please update model cards in HF repos to include the |
Sure, here is an example of the model card for another depth estimation model https://huggingface.co/apple/DepthPro-hf |
@qubvel Thanks for your help! Should I open a new PR to update the doc? |
I mean for these models: https://huggingface.co/depth-anything/prompt-depth-anything-vits-hf model cards have not a 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 |
https://huggingface.co/depth-anything/prompt-depth-anything-vits-hf |
Yes, this one looks good, thanks! |
What does this PR do?
This PR adds the Prompt Depth Anything Model. Prompt Depth Anything builds upon Depth Anything V2 and incorporates metric prompt depth to enable accurate and high-resolution metric depth estimation.
The implementation leverages Modular Transformers. The main file can be found here.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.