DepthAnything / Depth-Anything-V2

Depth Anything V2. A More Capable Foundation Model for Monocular Depth Estimation
https://depth-anything-v2.github.io
Apache License 2.0
3.29k stars 259 forks source link

Hugging face metric models dont produce depths #136

Open Eirikalb opened 1 month ago

Eirikalb commented 1 month ago

It seems that the hugging face models for metric depth are not producing depth values. https://huggingface.co/depth-anything/Depth-Anything-V2-Metric-Indoor-Base-hf If I download the raw model weights from this repo it also works nicely but would be nice to be able to use the transformers library.

If I use the disparity models they work just fine:

depth_estimator_v2_s = pipeline(task="depth-estimation", model="depth-anything/Depth-Anything-V2-Small-hf", device="cuda")
depth_anything_v2_s = np.array(depth_estimator_v2_s(rgb_image)["depth"])
fig,ax = plt.subplots(1,2,figsize=(20,10))
ax[0].imshow(1/depth_anything_v2_s )
ax[1].hist(1/depth_anything_v2_s .flatten(), bins=100)

image

depth_anything_v2_metric = pipeline("depth-estimation", model="depth-anything/Depth-Anything-V2-Metric-Indoor-Base-hf", device="cuda")
depth_anything_v2_metric_depth = np.array(depth_anything_v2_metric(rgb_image)["depth"])
fig,ax = plt.subplots(1,2,figsize=(20,10))
ax[0].imshow(depth_anything_v2_metric_depth)
ax[1].hist(depth_anything_v2_metric_depth.flatten(), bins=100)

image

MoAbbasid commented 3 weeks ago

Im facing the same issues, the transformers metric depth models do not work, let me know if you find a workaround.

MoAbbasid commented 3 weeks ago

inferring with:

pipe = pipeline("depth-estimation", model="depth-anything/Depth-Anything-V2-Small-hf") 

produces a deoth map, like: image

but

pipe = pipeline("depth-estimation", model="depth-anything/Depth-Anything-V2-Metric-Indoor-Small-hf")   

does not produce a decent depth map: image

same with the Outdoor versions of these models

HumayounMustafa commented 1 week ago

@MoAbbasid it does produce a depth map with indoor and outdoor models as well, the issue was closed in #148. Just install transformers 4.45 , I have created a notebook in which you can test. https://colab.research.google.com/drive/1OoWfDRX3LEcIj7mni-f_-S8J-te3gkk0?usp=sharing

HumayounMustafa commented 1 week ago

@Eirikalb if you update to transformers 4.45 then you get a depth map and values as well, if you use transformers 4.44 then the depth map is black and contains 0s I guess. I've just displayed the first row of the depth map Screenshot from 2024-09-06 12-27-47 Screenshot from 2024-09-06 12-28-14 Screenshot from 2024-09-06 12-28-40