luxonis / blobconverter

Web-based tool to convert model into MyriadX blob
MIT License
15 stars 5 forks source link

ONNX to Blob: Broadcast shape rank must be 1, but has 0 #53

Closed aiManny closed 1 year ago

aiManny commented 1 year ago

I'm getting this error when trying to convert a custom .onnx to .blob:

Command failed with exit code 1, command: /app/venvs/venv2022_1/bin/python /app/model_compiler/openvino_2022.1/converter.py --precisions FP16 --output_dir /tmp/blobconverter/6d616109005a4cef9ef6da961548085b --download_dir /tmp/blobconverter/6d616109005a4cef9ef6da961548085b --name maskrcnn_30 --model_root /tmp/blobconverter/6d616109005a4cef9ef6da961548085b

This is the full console output:

========== Converting maskrcnn_30 to IR (FP16) Conversion command: /app/venvs/venv2022_1/bin/python -- /app/venvs/venv2022_1/bin/mo --framework=onnx --data_type=FP16 --output_dir=/tmp/blobconverter/6d616109005a4cef9ef6da961548085b/maskrcnn_30/FP16 --model_name=maskrcnn_30 --input= --input_model=/tmp/blobconverter/6d616109005a4cef9ef6da961548085b/maskrcnn_30/FP16/maskrcnn_30.onnx

Model Optimizer arguments: Common parameters:

[ ERROR ] Traceback (most recent call last): File "/app/venvs/venv2022_1/lib/python3.8/site-packages/openvino/tools/mo/main.py", line 533, in main ret_code = driver(argv) File "/app/venvs/venv2022_1/lib/python3.8/site-packages/openvino/tools/mo/main.py", line 489, in driver graph, ngraph_function = prepare_ir(argv) File "/app/venvs/venv2022_1/lib/python3.8/site-packages/openvino/tools/mo/main.py", line 394, in prepare_ir ngraph_function = moc_pipeline(argv, moc_front_end) File "/app/venvs/venv2022_1/lib/python3.8/site-packages/openvino/tools/mo/moc_frontend/pipeline.py", line 147, in moc_pipeline ngraph_function = moc_front_end.convert(input_model) RuntimeError: While validating ONNX node '<Node(ConstantOfShape): /rpn/anchor_generator/ConstantOfShape>': Check 'broadcast_shape_rank.compatible(1)' failed at core/shape_inference/include/broadcast_shape_inference.hpp:171: While validating node 'v3::Broadcast Broadcast_2895 (Constant_2894[0]:i64{}, /rpn/anchor_generator/Constant_12_output_0[0]:i64{}) -> (dynamic...)' with friendly_name 'Broadcast_2895': Broadcast shape rank must be 1, but has 0

[ ERROR ] ---------------- END OF BUG REPORT -------------- [ ERROR ] -------------------------------------------------

I used this configuration when trying to convert:

image

My maskrcnn_30.onnx was converted from a custom pytorch .pt with the following function call:

image

Is this an internal issue with my original model?

Erol444 commented 1 year ago

Hi @aiManny , I just updated the bug report template for blobconverter. Copied text, as it's relevant here:


Note: Blobconverter is a simple wrapper around the OpenVINO tools, specifically:

Most of the time, if the blobconverter returns an error, it's an error thrown by Model Optimizer / Compile tool, NOT by blobconverter itself. So please don't report such issues here, but on OpenVINO github: https://github.com/openvinotoolkit/openvino

For converting model to blob, see documentation here: https://docs.luxonis.com/en/latest/pages/model_conversion/

aiManny commented 1 year ago

@Erol444 thank you very much for the speedy reply!

That actually helped a bunch. I'm able to solve by upgrading to openvino==2022.3.0 I can successfully generate IR files using:

mo --input_model "./saved_models/cube/maskrcnn_30.onnx" --input_shape=[1,3,352,640] --mean_values=[0,0,0] --scale_values=[255,255,255] --output_dir "./saved_models/cube"

I'm now trying to convert IR format to a .blob in my custom script pytorch2blob.py.

image

But there seems to be a server issue:

Downloading /home/aimanny/.cache/blobconverter/maskrcnn_30_openvino_2022.3.0_6shave.blob...
Traceback (most recent call last):
  File "pytorch2blob.py", line 93, in <module>
    blob_path = blobconverter.from_openvino(
  File "/home/aimanny/.virtualenvs/pytorch/lib/python3.8/site-packages/blobconverter/__init__.py", line 477, in from_openvino
    return compile_blob(blob_name=Path(xml_name).stem, req_data={"name": Path(xml_name).stem}, req_files=files, **kwargs)
  File "/home/aimanny/.virtualenvs/pytorch/lib/python3.8/site-packages/blobconverter/__init__.py", line 322, in compile_blob
    response.raise_for_status()
  File "/home/aimanny/.virtualenvs/pytorch/lib/python3.8/site-packages/requests/models.py", line 1021, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: https://blobconverter.luxonis.com/compile?version=2022.3.0&no_cache=False

Would this still be an openVINO issue?

Erol444 commented 1 year ago

Hi @aiManny , No, that would be blobconverter issue - it doesn't support OpenVINO 2022.3, as depthai library itself doesn't support it either. I think it's because OpenVINO stopped their support for Myriad X about that time (Intel also deprecated NCS2). So you'd need to use one of these versions:

image

aiManny commented 1 year ago

I see. Downgrading to any version below 2022.3.0 reproduces the initial error. I probably just need to migrate this issue to the openVINO side.

I appreciate your time @Erol444! I'll be sure to post when I find a solution.

ammar-bitar commented 1 year ago

(...) I think it's because OpenVINO stopped their support for Myriad X about that time (Intel also deprecated NCS2). (...)

Just FYI, it seems a LTS release will come out with version 2022.3.1 which includes NCS2 (see: https://www.intel.com/content/www/us/en/developer/articles/release-notes/openvino-2022-3-lts-relnotes.html )

Erol444 commented 1 year ago

@ammar-bitar thanks for notifying us! We will be looking into this, and add support for it in case it works as expected.