fabio-sim / Depth-Anything-ONNX

ONNX-compatible Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data
Apache License 2.0
234 stars 23 forks source link

Error when input image size is not equals to 518 in V2 models #14

Closed tamirs9876 closed 2 months ago

tamirs9876 commented 2 months ago

Changing the input image size from 518x518 to another size which is a multiplier of 14, such as 364 or 560 result with an error:

Error in execution: Got invalid dimensions for input: l_x_ for the following indices
 index: 2 Got: 364 Expected: 518
 index: 3 Got: 364 Expected: 518
 Please fix either the inputs/outputs or the model.

Using input size other than 518 works as expected with Depth-Anything-ONNX V1 and also with the original Depth-Anything-V2 models.

fabio-sim commented 2 months ago

Hi @tamirs9876, thank you for your interest in Depth-Anything-ONNX.

I've added support for exporting dynamic shapes in #15.

tamirs9876 commented 2 months ago

Thanks, @fabio-sim, for your quick response!

I'm getting the same error as above after pulling the last commit (e25298b, clean master branch).

Here is the command I used: python dynamo.py infer .\weights\depth_anything_v2_vitl.onnx -i assets\sacre_coeur1.jpg -d cpu -w 252 -h 252

RuntimeError: Error in execution: Got invalid dimensions for input: l_x_ for the following indices
 index: 2 Got: 252 Expected: 518
 index: 3 Got: 252 Expected: 518
 Please fix either the inputs/outputs or the model.

If I omit the -w and -h parameters, I get the result as expected.

fabio-sim commented 2 months ago

Did you export .\weights\depth_anything_v2_vitl.onnx with dynamic axes? You can also try the already exported model here: https://github.com/fabio-sim/Depth-Anything-ONNX/releases/download/v2.0.0/depth_anything_v2_vitl_dynamic.onnx

tamirs9876 commented 2 months ago

Works as expected with *_dynamic.onnx models, thanks!