pytorch转onnx问题

 Fail to export the model in PyTorch

https://github.com/onnx/tutorials/blob/master/tutorials/PytorchAddExportSupport.md#fail-to-export-the-model-in-pytorch

1. RuntimeError: ONNX export failed: Couldn't export operator aten::rsqrt

 2. RuntimeError: ONNX export failed: Couldn't export operator aten::reshape

原因:pytorch-1.0.1不支持reshape操作

解决:~/anaconda3/envs/py36/lib/python3.6/site-packages/torch/onnx/symbolic.py

在该文件中添加代码

def reshape(g, self, shape):
    return view(g, self, shape)


def reshape_as(g, self, other):
    shape = g.op('Shape', other)
    return reshape(g, self, shape)

 3. ONNX export failed on ATen operator group_norm because torch.onnx.symbolic.group_norm does not exist

解决:~/anaconda3/envs/py36/lib/python3.6/site-packages/torch/onnx/symbolic.py

@parse_args('v', 'i', 'v', 'v', 'f', 'i')
def group_norm(g, input, num_groups, weight, bias, eps, cudnn_enabled):
    return g.op("ATen", input, weight, bias, num_groups_i=num_groups,
                eps_f=eps, cudnn_enabled_i=cudnn_enabled, operator_s="group_norm")

 

转载于:https://www.cnblogs.com/haiyang21/p/11543951.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值