Torch 转 ONNX遇到UnsupportedOperatorError: Exporting the operator ::resolve_conj to ONNX opset version

Torch 转 ONNX遇到UnsupportedOperatorError: Exporting the operator ::resolve_conj to ONNX opset version

import torch
from torch import nnclass BadFirst(nn.Module):def __init__(self):super().__init__()def forward(self, x):x_firsts = x[:, 0]## 在转换onnx时,一定要注释或删除model结构中所有的printprint(f"x_firsts: {x_firsts}") # removing this line fixes the issue.return x_firstsm = 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


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部