如何转换 SimpleTransformers? ONNX 模型到 keras
我目前正在尝试使用 onnx2keras 转换 onnx 模型。但是,我面临以下错误:
AttributeError Traceback (most recent call last)
<ipython-input-10-8e8800d4ffef> in <module>()
6
7 onnx_model = onnx.load('onnx_model.onnx')
----> 8 k_model = onnx_to_keras(onnx_model,['input_ids'])
9
10 tf.keras.models.save_model(k_model,'kerasModel.h5',overwrite=True,include_optimizer=True)
/usr/local/lib/python3.7/dist-packages/onnx2keras/converter.py in onnx_to_keras(onnx_model, input_names, input_shapes, name_policy, verbose, change_ordering)
168 layers[node_input] = weights[node_input]
169 else:
--> 170 raise AttributeError('Current node is not in weights / model inputs / layers.')
171 else:
172 logger.debug('... found all, continue')
AttributeError: Current node is not in weights / model inputs / layers.
这是我的代码:
import onnx2keras
from onnx2keras import onnx_to_keras
import keras
import onnx
import tensorflow as tf
onnx_model = onnx.load('onnx_model.onnx')
k_model = onnx_to_keras(onnx_model,['input_ids'])
tf.keras.models.save_model(k_model,'kerasModel.h5',overwrite=True,include_optimizer=True)
我还使用以下代码找到了 onnx 模型中的节点:
input_all = [node.name for node in onnx_model.graph.input]
print(input_all)
这是 'input_all' = ['input_ids', 'attention_mask', 'token_type_ids'] 的输出
可以有人为我的问题提供解决方案。谢谢
I am currently trying to convert the onnx model using onnx2keras. However, I am facing the error below:
AttributeError Traceback (most recent call last)
<ipython-input-10-8e8800d4ffef> in <module>()
6
7 onnx_model = onnx.load('onnx_model.onnx')
----> 8 k_model = onnx_to_keras(onnx_model,['input_ids'])
9
10 tf.keras.models.save_model(k_model,'kerasModel.h5',overwrite=True,include_optimizer=True)
/usr/local/lib/python3.7/dist-packages/onnx2keras/converter.py in onnx_to_keras(onnx_model, input_names, input_shapes, name_policy, verbose, change_ordering)
168 layers[node_input] = weights[node_input]
169 else:
--> 170 raise AttributeError('Current node is not in weights / model inputs / layers.')
171 else:
172 logger.debug('... found all, continue')
AttributeError: Current node is not in weights / model inputs / layers.
Here is my code:
import onnx2keras
from onnx2keras import onnx_to_keras
import keras
import onnx
import tensorflow as tf
onnx_model = onnx.load('onnx_model.onnx')
k_model = onnx_to_keras(onnx_model,['input_ids'])
tf.keras.models.save_model(k_model,'kerasModel.h5',overwrite=True,include_optimizer=True)
I have also found the nodes from onnx model using below code:
input_all = [node.name for node in onnx_model.graph.input]
print(input_all)
This is the output of 'input_all' = ['input_ids', 'attention_mask', 'token_type_ids']
Can someone provide a solution for my problem. Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论