keras-onnx icon indicating copy to clipboard operation
keras-onnx copied to clipboard

Unable to convert a keras model to onnx

Open Marwen-Bhj opened this issue 4 years ago • 2 comments

I've trained a mobilenetv2 model on a custom dataset using Keras. After training I saved my model using model.save, I tried converting it to onnx using this script:

from tensorflow.python.keras.models import load_model
import onnx
import keras2onnx

onnx_model_name = 'sw-mobilenetv2.onnx'

model = load_model('swmodel.h5')
onnx_model = keras2onnx.convert_keras(model, model.name)
onnx.save_model(onnx_model, onnx_model_name)

and I recieve this error :

Exception has occurred: OSError
SavedModel file does not exist at: model.h5/{saved_model.pbtxt|saved_model.pb}
  File "/home/marwen/MobileNetV2/keras-onnx.py", line 7, in <module>
    model = load_model('model.h5')

Marwen-Bhj avatar Dec 10 '20 23:12 Marwen-Bhj

The error occurs in load_model which is keras API, seems not related to keras2onnx issue.

jiafatom avatar Dec 12 '20 21:12 jiafatom

This error mostly occurs because you do not have the file in the directory. Please check if the file is present and the name is right.

vinesin avatar Dec 18 '20 21:12 vinesin