onnx / tutorials

Tutorials for creating and using ONNX models
Apache License 2.0
3.34k stars 626 forks source link

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

Open anshu1106 opened 6 years ago

anshu1106 commented 6 years ago

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

fernandotorch commented 6 years ago

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

houseroad commented 6 years ago

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

mbenami commented 5 years ago

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

any recommend? Thanks

lxy5513 commented 5 years ago

try use pytorch==0.4.0 package

it occured error when my pytorch=0.4.1

mbenami commented 5 years ago

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