做了一个小测试,发现pytorch onnx tensorrt三个库的版本存在微妙的联系,在我之前的错误实验中,PyTorch==1.3.0/1.4.0;Onnx==1.6.0;tensorrt=7.0,用以下包含一个上采样层的代码做测试:
import torch
import torch.nn as nn
import torch.nn.functional as F
import os
class TestModel(nn.Module):
def __init__(self):
super(TestModel, self).__init__()
def forward(self, x):
x = F.interpolate(x, (256, 256), mode = 'bilinear')
return x
torch_model = TestModel()
dummy_input = torch.randn((1, 3, 256, 256))
torch_out = torch.onnx.export(torch_model,
dummy_input,
'test_model.onnx',
verbose=True,
opset_version=11,)
得到的Onnx模型:
%2 : Tensor = onnx::Constant[value=[ CPUFloatType{0} ]]()
%3 : Tensor = onnx::Constant[value= 1 3