tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

RuntimeError: ONNX export failed: Couldn't export operator aten::avg_pool2d

Open anshu1106 opened this issue 6 years ago • 5 comments

How to take care of this error?

/anaconda3/lib/python3.6/site-packages/torch/onnx/symbolic.py:69: UserWarning: ONNX export failed on avg_pool2d because ceil_mode not supported

RuntimeError: ONNX export failed: Couldn't export operator aten::avg_pool2d

anshu1106 avatar May 21 '18 09:05 anshu1106

The problem is on your network declaration. You are trying to export your model but the parameter ceil_mode=True is not supported for the transformation.

Go to the declaration of your network and change it to e.g.: nn.AvgPool2d(2, stride=2, ceil_mode=False),)

You can find more info in the documentation: https://pytorch.org/docs/master/nn.html#avgpool2d

fernandotorch avatar Jun 08 '18 14:06 fernandotorch

Because the symbolic (translation) function is missing, try to follow the (almost up to date) tutorial to extend the support here: https://github.com/onnx/tutorials/blob/master/tutorials/PytorchAddExportSupport.md

houseroad avatar Aug 28 '18 00:08 houseroad

Hi @fgtoralesch I try to add ceil_mode=False as you say but somehow I still get this error

any recommend? Thanks

mbenami avatar Nov 29 '18 15:11 mbenami

try use pytorch==0.4.0 package

it occured error when my pytorch=0.4.1

lxy5513 avatar Jan 09 '19 10:01 lxy5513

I had the same issue In my case, the error was when I use:

import torch.nn.functional as F
...
 def forward(self, x):
    feat = self.base(x)
    feat = F.avg_pool2d(feat, feat.size()[2:])

when I define in my network:

class Model(nn.Module):
    def __init__():
        ...
        self.avg_pool2d = nn.AvgPool2d(kernel_size=k_s, ceil_mode=False)
        ...
    def forward(self, x):
        ...
        feat = self.avg_pool2d(feat, feat.size()[2:])
        ...

everything work

mbenami avatar Jan 09 '19 11:01 mbenami