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")

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM