openvinotoolkit / openvino

OpenVINO™ is an open-source toolkit for optimizing and deploying AI inference
https://docs.openvino.ai
Apache License 2.0
7.21k stars 2.25k forks source link

Import compiled model in python #11809

Closed nieknaber closed 2 years ago

nieknaber commented 2 years ago

I want to import a compiled model in python, but something seems to go wrong.

I am using openvino version 2022.1

I have a model in IR representation (the .xml and .bin file) and first compile that with the compile tool:

compile_tool -m model.xml -d MYRIAD -VPU_NUMBER_OF_SHAVES 6 -VPU_NUMBER_OF_CMX_SLICES 6 -ip u8 -o model.blob

Then I want to import this compiled model in python. I do not want to compile the model myself in python from the .xml and .bin file because in this way I can choose the optimal number of shaves. I use the following python code:

with open("model.blob", "rb") as f:
    compiled_model = core.import_model(f.read(), "MYRIAD")

I however get the following error:

Traceback (most recent call last):
  File "test.py", line 25, in <module>
    compiled_model = core.import_model(f.read(), "MYRIAD")
  File "/home/pi/openvino/bin/armv7l/Release/lib/python_api/python3.7/openvino/runtime/ie_api.py", line 331, in import_model
    model_stream, device_name, {} if config is None else config
RuntimeError: [ GENERAL_ERROR ]  AssertionFailed: offset + sizeof(T) <= blob.size()

How can I correctly import a pre-compiled model in python?

Iffa-Intel commented 2 years ago

We do notice that the import method here only covers C++.

As for Python, Wand library probably can be used as a workaround, however, this would get a blob information using the library itself instead of OpenVINO-compiled .blob file.

We'll get back to your with more information asap.

jgespino commented 2 years ago

@nieknaber Have you tried using import_network?

I was able to load the blob to a MYRIAD device using the following:

from openvino.inference_engine import IECore
ie = IECore()

exec_net_imported = ie.import_network(model_file="face-detection-adas-0001.blob", device_name="MYRIAD")
jgespino commented 2 years ago

Closing, please start a new issue if additional assistance is needed.