我在Pytorch 1.0
(扩展名为.pth)中有经过预训练的模型(https://github.com/zraurum/EAST-pretrained-model)
我试图通过Pytorch 1.0
将onnx 1.3.0
模型转换为tensorflow 1.12
import onnx
import torch
import torch._C as _C
from onnx_tf.backend import prepare
from torch.autograd import Variable
OperatorExportTypes = _C._onnx.OperatorExportTypes
from models.east.east_model import East
trained_model = East().cpu()
trained_model.load_state_dict(torch.load('./models/east/model/epoch5300.pth', map_location='cpu'), strict=False)
dummy_input = Variable(torch.randn(1, 3, 672, 1280))
torch.onnx.export(trained_model, dummy_input, "output/east.onnx", operator_export_type=OperatorExportTypes.RAW)
model = onnx.load('output/ep_180_sim_autoencoder.onnx')
# from onnx to tensorflow
tf_rep = prepare(model)
tf_rep.export_graph('output/ep_180_sim_autoencoder.pb')
错误:
回溯(最近通话最近): 在第22行的文件“ convert_east.py”中 tf_rep = prepare(模型) 文件“ /home/www/frompytorchtoonnx/venvt/src/onnx-tf/onnx_tf/backend.py”, 第53行,准备中 super(TensorflowBackend,cls).prepare(model,device,** kwargs) 文件“ /home/www/frompytorchtoonnx/venvt/lib/python3.5/site-packages/onnx/backend/base.py”, 第74行,准备中 onnx.checker.check_model(模型) 文件“ /home/www/frompytorchtoonnx/venvt/lib/python3.5/site-packages/onnx/checker.py”, 第82行,在check_model中 C.check_model(model.SerializeToString()) onnx.onnx_cpp2py_export.checker.ValidationError:域'org.pytorch.prim'没有opset导入
上下文:错误的节点规范:输出:“ 31” op_type:“常量”属性{名称:“ value”整数:1整数:1类型:整数}域: “ org.pytorch.prim”
虚拟环境包含以下库:
absl-py==0.7.0
astor==0.7.1
gast==0.2.2
grpcio==1.18.0
h5py==2.9.0
Keras-Applications==1.0.6
Keras-Preprocessing==1.0.5
Markdown==3.0.1
numpy==1.16.0
onnx==1.3.0
-e git+https://github.com/onnx/onnx-tensorflow@c4a75b09e85ffb7b5afda14b64194ca972f957bf#egg=onnx_tf
Pillow==5.4.1
pkg-resources==0.0.0
protobuf==3.6.1
PyYAML==3.13
six==1.12.0
tensorboard==1.12.2
tensorflow==1.12.0
termcolor==1.1.0
torch==1.0.0
torchvision==0.2.1
typing==3.6.6
typing-extensions==3.7.2
Werkzeug==0.14.1