我正在尝试将保存的TensorFlow模型转换为ONNX格式,但出现以下错误
in _load_nodes
slot_variable = optimizer_object.add_slot(
AttributeError: '_UserObject' object has no attribute 'add_slot'
我使用Keras(2.6)保存带有model.save(os.path.join("models", 'modelData'))
的模型。然后,我使用python -m tf2onnx.convert --saved-model modelData --output model.onnx
转换模型
使用keras2onnx
对我不起作用,因为库太旧了(而且它们的存储库还是重定向到tf2onnx
)
我尝试使用python -m tf2onnx.convert --checkpoint checkpoint/keras_metadata.pb --output model.onnx --inputs input0:0,input1:0 --outputs output0:0
从检查点文件转换,但出现以下错误
saver = tf_import_meta_graph(model_path, clear_devices=True)
File "####\anaconda3\envs\##\lib\site-packages\tensorflow\python\training\saver.py", line 1465, in import_meta_graph
return _import_meta_graph_with_return_elements(meta_graph_or_file,
File "####\anaconda3\envs\##\lib\site-packages\tensorflow\python\training\saver.py", line 1481, in _import_meta_graph_with_return_elements
meta_graph_def = meta_graph.read_meta_graph_file(meta_graph_or_file)
File "####\anaconda3\envs\##\lib\site-packages\tensorflow\python\framework\meta_graph.py", line 643, in read_meta_graph_file
text_format.Merge(file_content.decode("utf-8"), meta_graph_def)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 1: invalid start byte
在保存模型之前,我是否应该对其执行一些特殊操作?这可能是版本不匹配吗?任何反馈都会有帮助
我通过在培训后立即转换模型解决了这个问题。我使用了下面的代码
但是,这并不能解决保存模型的转换问题
相关问题 更多 >
编程相关推荐