isl-org / MiDaS

Code for robust monocular depth estimation described in "Ranftl et. al., Towards Robust Monocular Depth Estimation: Mixing Datasets for Zero-shot Cross-dataset Transfer, TPAMI 2022"
MIT License
4.27k stars 599 forks source link

device "mps" for Apple silicon - strange output #184

Open RaceBo opened 1 year ago

RaceBo commented 1 year ago

I've tried to run MiDaS on Apple silicon with pytorch nightly with mps (metal performance shader) support.

I've change two lines of code to get this working: 28 - device = torch.device("cuda" if torch.cuda.is_available() else "mps") and 127 - mode="bilinear",

The change to "bilinear" is necessary because bicubic is not supported currently for the M1 native implementation. Influence on output quality is neglectable in my experience (I did a few comparing tests on "CPU" with only this parameter changed)

This way I could speed up inference by a whopping factor of 6. But: Output quality detoriates to not-usable. I've got virtually no experience with python and pytorch - I'm basically a hobbyist creator and dad who wants to have a depth map on selected gopro footage of his son to fake depth of field into it. So i do not know where to look at.

Legacy Midas V2 seems to work okay and delivers the same output on CPU and MPS: 000727v2cpu CPU 000727v2mps MPS

DPT however, output becomes unusable with mps: 000727dptmps MPS

000727dptcpu CPU

Any ideas? Can someone give me a hint?

duckheada commented 11 months ago

any updates?