我正在尝试将onnx模型转换为TensorFlow的.pb模型。但是当我执行prepare
函数时,出现以下错误:NotImplementedError: Einsum is not implemented.
有解决此问题的建议吗?谢谢!
顺便说一下,这是我用来转换模型的代码:
import onnx
from onnx_tf.backend import prepare
def onnx2pb(model, pb_output_path, opset_version=12):
tf_exp = prepare(onnx_model) # prepare tf representation
tf_exp.export_graph(pb_output_path) # export the model
onnx_input_path = './model.onnx'
pb_output_path = './model.pb'
onnx_model = onnx.load(onnx_input_path)
onnx2pb(onnx_model, pb_output_path)
>>> below are the error report
tf_exp = prepare(onnx_model) # prepare tf representation
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/onnx_tf/backend.py", line 66, in prepare
return cls.onnx_model_to_tensorflow_rep(model, strict)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/onnx_tf/backend.py", line 86, in onnx_model_to_tensorflow_rep
return cls._onnx_graph_to_tensorflow_rep(model.graph, opset_import, strict)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/onnx_tf/backend.py", line 143, in _onnx_graph_to_tensorflow_rep
output_ops = cls._onnx_node_to_tensorflow_op(onnx_node,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/onnx_tf/backend.py", line 254, in _onnx_node_to_tensorflow_op
exception.OP_UNIMPLEMENTED_EXCEPT(node.op_type)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/onnx_tf/common/exception.py", line 30, in __call__
super(OpUnimplementedException, self).__call__(op, version, domain)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/onnx_tf/common/exception.py", line 12, in __call__
raise self._func(self.get_message(*args, **kwargs))
NotImplementedError: Einsum is not implemented.
[Finished in 5.3s with exit code 1]
答案 0 :(得分:0)
我通过将torch.einsum
更改为相关矩阵乘法来解决了这个问题:)