Open fewjative opened 3 months ago
I would guess this is a rounding/value-of-out-bounds issue. So values that are too low (i.e. < 0) in this case are being wrapped around to the max value (255) which appears as that white outline.
I'm not familiar with the huggingface stuff, but judging from that code sample, I don't think there's anything you can do to fix it (the error is happening inside the 'depthpipe' code). However on that same page they have a larger Using the model yourself section that you can copy and modify to fix the problem. The main change you'd want to make is on the second last line:
# Original code
formatted = (output * 255 / np.max(output)).astype("uint8")
# Change to:
formatted = (255 * ((output - np.min(output)) / (np.max(output) - np.min(output)))).astype("uint8")
This should help account for the error of values dropping below zero causing that white line.
The other potential change is to switch the interpolation mode from "bicubic" to "bilinear" in the torch.nn.functional.interpolate(...)
part. This change alone might take care of the problem in this case actually, but the first fix is the more important one, though I'd recommend both.
Thanks for the ideas @heyoeyo
Both of the ideas you suggested ended up resolving the problem for me.
Problem: Harsh white lines surround object Expected: No white harshlines, they don't make sense from a depth POV either
I'm using the code found here: https://huggingface.co/docs/transformers/main/en/model_doc/depth_anything_v2
Running on an Nvidia 4090. Happens both locally and when I run the code on the cloud too via Replicate.
Output
Input image ( real photo, non AI )