torch2trt icon indicating copy to clipboard operation
torch2trt copied to clipboard

AdaptivaAvgPool2d : 'NoneType' object has no attribute 'stride'

Open aoaforever opened this issue 2 years ago • 8 comments

Hello, I have a problem. Did the torch2trt support to convert AdaptivaAvgPool2d? I found the source code for convert AdaptiveAvgPool2d, but it doesn't work.

class net(nn.Module): def init(self): super(net, self).init() self.global_aver_polling=nn.AdaptiveAvgPool2d((1,1)) def forward(self,x): out=self.global_aver_polling(x) return out if name == 'main': img = torch.randn(1, 32, 640, 360).cuda() net2 = net().cuda().eval() net2_trt=torch2trt(net2,[img]) with torch.no_grad(): net2_trt(img)

Traceback (most recent call last): File "test_conv_time.py", line 154, in net2_trt=torch2trt(net2,[img]) File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.3.0-py3.6-linux-aarch64.egg/torch2trt/torch2trt.py", line 553, in torch2trt outputs = module(*inputs) File "/home/nvidia/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "test_conv_time.py", line 102, in forward out=self.global_aver_polling(x) File "/home/nvidia/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.3.0-py3.6-linux-aarch64.egg/torch2trt/torch2trt.py", line 300, in wrapper converter"converter" File "/usr/local/lib/python3.6/dist-packages/torch2trt-0.3.0-py3.6-linux-aarch64.egg/torch2trt/converters/AdaptiveAvgPool2d.py", line 22, in convert_AdaptiveAvgPool2d layer.stride = stride AttributeError: 'NoneType' object has no attribute 'stride'

aoaforever avatar Oct 01 '21 03:10 aoaforever

I have tested it again, and I found that it has a error:"[TensorRT] ERROR: Parameter check failed at: ../builder/Network.cpp::addPoolingNd::731, condition: allDimsGtEq(windowSize, 1) && volume(windowSize) < MAX_KERNEL_DIMS_PRODUCT "

So, the follow url should be helpful: (The same or similar issue because of the TensorRT version is too low??) https://github.com/onnx/onnx-tensorrt/issues/333

The url gives two solution: 1.use double avgpooling 2.update the TensorRT version to 7.* or newer.

But my TensorRT version is 7.1, so why the issue also happens??

aoaforever avatar Oct 18 '21 02:10 aoaforever

My task is the imgae superresolution, but I now notice that this torch2trt doesn't support dynamic input. please see this link: https://github.com/NVIDIA-AI-IOT/torch2trt/issues/317

And no offense, I will try this repositories : https://github.com/grimoire/torch2trt_dynamic

aoaforever avatar Oct 20 '21 08:10 aoaforever

I have the same problem

superddr avatar Nov 24 '21 04:11 superddr

I have the same problem. I think it fails when the input size is too big

RolandGao avatar Oct 05 '22 20:10 RolandGao

I have the same problem

fanOfJava avatar Oct 08 '22 08:10 fanOfJava

I have the same issue

gabe-scorebreak avatar May 29 '23 15:05 gabe-scorebreak

I have the same problem

A-janjan avatar Aug 24 '23 16:08 A-janjan

https://github.com/grimoire/torch2trt_dynamic solves this, thanks @aoaforever

lebionick avatar Apr 02 '24 21:04 lebionick