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

Converting to CoreML results in error “Core ML only supports tensors with rank <= 5. Layer "x.9", with type "reshape", outputs a rank 6 tensor." #201

Open zeman-88 opened 1 year ago

zeman-88 commented 1 year ago

I'm trying to convert MiDaS dpt_swin2_tiny_256 to CoreML, but when I do, at the convert() step, CoreML tools says: "Core ML only supports tensors with rank <= 5. Layer "x.9", with type "reshape", outputs a rank 6 tensor."

I have tried other 3.1 models, and many of the fail to convert with that error. Whereas the 2.x models convert just fine with the same code that gives issues for the 3.1 models.

I'm not sure which layer is "x.9" to go in the code and try to fix this. The only "reshape()" call I found is in the vit.py file, which shouldn't even be used for Swin2.

How can I solve this?

xbbkok commented 1 year ago

@zeman-88 I also have this problem,Could you please tell me how to solve that?

guopeng1994 commented 1 year ago

finally! i converted successfully. i'm using colab. i found same error when i try to convert model in coremltools=6.3.0(and 6.0.0, 6.1.0,6.2.0 both have convert errors) which 6.3.0 gives me RuntimeError: PyTorch convert function for op 'unflatten' not implemented. so i go to coremltools official github and found then i also found a new release version named 7.0b1 of coremltools, so i decided to use the latest version. after i installed 7.0b1, i copy the changed content to my python cached package source to specific file(coremltools/converters/mil/frontend/torch/ops.py) which added the unflatten func.

after that i restart colab to make changes effect. then run convert script. OHHHHH! it succeed! image

This took me a day and a half...