【发布时间】:2021-11-11 07:14:45
【问题描述】:
我正在尝试将保存的 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
在保存模型之前,我应该对模型做些什么特别的事情吗?这可能是一些版本不匹配吗?任何反馈都会有所帮助。
【问题讨论】:
标签: python tensorflow keras onnx tf2onnx