onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Load model from mn

When Raspberry Pi 4B uses onnxruntime1.6.0 to load the model.onnx model, the following error occurs:

insert image description here

reason:

Because the exported ONNX model file is not compatible with the current version of ONNX Runtime, I initially exported the model as follows:

import tensorflow as tf
from keras import models

keras_model = models.load_model("mnist_model.h5")
# Save the Keras model as SavedModel format
tf.saved_model.save(keras_model, 'saved_model_dir')

Then I will get a folder:
insert image description here
Then I opened the black window of the Raspberry Pi in the path of the folder generated above, and then entered the following command:

python3 -m tf2onnx.convert --saved-model saved_model_dir --output mnist_model.onnx

Then the onnx model is generated:
insert image description here
but the above error occurs when it is running. The correct way is to specify the format version of the ONNX model file when exporting the ONNX model. The following command line should be used:

python3 -m tf2onnx.convert --saved-model saved_model_dir --output mnist_model.onnx --opset=10

Among them, saved_model_dir should be the path of the saved TensorFlow model folder. –opset=10 means that the format version of the specified ONNX model is 10. This version depends on your onnxruntime. Mine is onnxruntime1.6.0, so the corresponding It is version 10.

Guess you like

Origin blog.csdn.net/weixin_46235937/article/details/130339284