Torch 转 ONNX遇到UnsupportedOperatorError: Exporting the operator ::resolve_conj to ONNX opset version
import torch
from torch import nn
class BadFirst(nn.Module):
def __init__(self):
super().__init__()
def forward(self, x):
x_firsts = x[:, 0]
## 在转换onnx时,一定要注释或删除model结构中所有的print
print(f"x_firsts: {x_firsts}") # removing this line fixes the issue.
return x_firsts
m = BadFirst().eval()
x = torch.rand(10, 5)
res = m(x) # this works
torch.onnx.export(m, x, "m.onnx") # this fails due to a resolve_conj op
如果model中存在print则会出现以下错误。
解决办法:注释或删除model结构中所有的print