openvinotoolkit / openvino

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

[Android] Error: Unknown model format #11721

Closed sergiossm closed 2 years ago

sergiossm commented 2 years ago
System information (version)
Detailed description

I'm trying to build the Android app following the instructions in this post by @likholat.

Everything goes smoothly: OpenVINO is built for Android with no issues and all modules and libraries are successfully imported into the Android project as well.

However, the app crashes on my device when trying to read the model, in this line:

CNNNetwork net = core.ReadNetwork(modelDir + "/" + MODEL_XML);

It throws the following error: InferenceEngineException: ReadNetwork: Unknown model format! Cannot find reader for model format: xml and read the model: /storage/emulated/0/Android/data/com.example.androidopenvino/files/Documents/face-detection-adas-0001.xml. Please check that reader library exists in your PATH.

The reader library seems to have been imported into the project, so I have no idea what might be causing the error.

Screenshot 2022-05-20 at 10 22 09

Does anyone have a solution or is facing the same issue?

Issue submission checklist
jgespino commented 2 years ago

@sergiossm I haven't tried this myself but looking at the guide you shared your OpenVINO version and downloaded model version are not compatible.

Download model “face-detection-adas-0001” from Open Model Zoo: git clone --depth 1 https://github.com/openvinotoolkit/open_model_zoo cd open_model_zoo/tools/downloader python3 -m pip install -r requirements.in python3 downloader.py --name face-detection-adas-0001

Following the guide, it's cloning the master branch of Open Model Zoo which contains models in IRv11 format that was introduced in OpenVINO 2022.1 release. I suggest cloning the Open Model Zoo 2021.4.2. branch to match your build or rebuild OpenVINO using the 2022.1 branch.

git clone --depth 1 https://github.com/openvinotoolkit/open_model_zoo -b 2021.4.2

sergiossm commented 2 years ago

Thank you for the quick reply @jgespino, it worked! I appreciate your help.

Closing.

sergiossm commented 2 years ago

Reopening because OpenVINO branch 2022.1 won't create file inference_engine_java.jar. Instead, it generates a libinference_engine_java.so file along with the rest of the prebuilt libraries.

On the left, the .jar file containing all classes in the Intel OpenVINO package. On the right, the prebuilt libraries generated after building OpenVINO for Android using branch 2022.1.

Screenshot from 2022-05-21 14-06-00

Android Studio doesn't recognize the .so library even though I included the libinference_engine_java.so file in the jniLibs/arm64-v8a folder.

Screenshot from 2022-05-21 14-09-56(1)

I tried using the inference_engine_java.jar library from the 2021.4.1 OpenVINO built but it obviously crashes. Any solutions?

jgespino commented 2 years ago

@sergiossm Could you share your cmake command? I will try to build OpenVINO 2022.1 for Android using these instructions and get back to you.

jgespino commented 2 years ago

@sergiossm I built both OpenVINO 2021.4.2 and OpenVINO 2022.1 from source and included the java-api from OpenVINO Contrib repository. I verified that the .jar file is not generated with OpenVINO 2022.1 release. Given that the OpenVINO contrib repository may not be stable, I recommend you continue using OpenVINO 2021.4.2 release with the guide you shared as it's been verified to work with such version.

I will open a bug with the development team to further investigate.

Regards, Jesus

sergiossm commented 2 years ago

@jgespino I didn't have time to re-build it this week, thank you for doing it yourself. Also, thanks for confirming this, I'll stay tuned for updates.

jgespino commented 2 years ago

@sergiossm No problem, I have filed a bug with the development team. I will keep you posted.

Ref. 85905

sergiossm commented 2 years ago

@jgespino Something interesting happened. I updated my machine from Ubuntu 18.04 to 20.04 and tried building OpenVINO 2021.4.1 and 2021.4.2. For neither version, the inference_engine_java.jar file was generated. But when trying on Colab (which runs Ubuntu 18.04, if I'm not mistaken), the build did generate the mentioned file.

Just saying this in case you find it helpful.

jgespino commented 2 years ago

@sergiossm There are additional steps needed to build the java_api.jar file with OpenVINO 2022.1 release. Could you please try the following and let me know if it works for you?

git clone -b 2022.1 https://github.com/openvinotoolkit/openvino_contrib
cd openvino_contrib/modules/java_api/
gradle build

The java_api.jar file will be located in openvino_contrib/modules/java_api/build/libs. If you run into a "no signature of method: org.gradle.api.internal.tasks.RealizableTaskCollection.configureEach())" then you need to upgrade gradle. This is the guide I followed to upgrade gradle.

Ref: https://github.com/openvinotoolkit/openvino_contrib/tree/2022.1/modules/java_api/samples#build-openvino-java-bindings