from torch.autograd import Variable
import torch.onnx
import torchvision
dummpy_input = Variable(torch.randn(1,3,224,224)).cuda()
model = torchvision.models.vgg16(pretrained=True).cuda()
torch.onnx.export(model, dummpy_input, "vgg.proto", verbose=True)
import onnx
# Load the ONNX model
model = onnx.load("vgg.proto")
# Check that the IR is well formed
onnx.checker.check_model(model)
# Print a human readable representation of the graph
onnx.helper.printable_graph(model.graph)
# ...continuing from above
import onnx_caffe2.backend as backend
import numpy as np
rep = backend.prepare(model, device="CUDA:0")
outputs = rep.run(np.random.randn(1, 3, 224, 224).astype(np.float32))
print(outputs[0])Import Error: no module named 'past'
统一模型文件定义及权重拷贝
解决 : pip3 install future
cited: https://www.cnblogs.com/huolifeng/p/6412183.html
ValueError: Don't know how to translate op Unsqueeze
解决 : https://blog.csdn.net/rock4you/article/details/89045181