NVIDIA-AI-IOT / torch2trt

An easy to use PyTorch to TensorRT converter
MIT License
4.57k stars 673 forks source link

TypeError: add_pooling_nd(): incompatible function arguments #867

Open AlessandroDalponte opened 1 year ago

AlessandroDalponte commented 1 year ago

Hello,

I'm trying to optimize an i3d anomaly detection model, but I'm getting this error:

File "run.py", line 89, in run_model(args=args) File "run.py", line 69, in run_model trt_model = torch2trt(model, input_trt, max_batch_size=args.batch_size) File "/home/pc01/Desktop/nvidia_torch2trt/torch2trt/torch2trt.py", line 779, in torch2trt outputs = module(inputs) File "/home/pc01/miniforge3/envs/nvidia_rt/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1212, in _call_impl result = forward_call(input, kwargs) File "/home/pc01/Desktop/nvidia_torch2trt/models/i3d_pytorch.py", line 331, in forward x = self._modulesend_point # use _modules to work with dataparallel File "/home/pc01/miniforge3/envs/nvidia_rt/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1212, in _call_impl result = forward_call(*input, *kwargs) File "/home/pc01/Desktop/nvidia_torch2trt/models/i3d_pytorch.py", line 45, in forward return super(MaxPool3dSamePadding, self).forward(x) File "/home/pc01/miniforge3/envs/nvidia_rt/lib/python3.8/site-packages/torch/nn/modules/pooling.py", line 244, in forward return F.max_pool3d(input, self.kernel_size, self.stride, File "/home/pc01/Desktop/nvidia_torch2trt/torch2trt/torch2trt.py", line 310, in wrapper converter"converter" File "/home/pc01/Desktop/nvidia_torch2trt/torch2trt/converters/max_pool3d.py", line 33, in convert_max_pool3d layer = ctx.network.add_pooling_nd( File "/home/pc01/Desktop/nvidia_torch2trt/torch2trt/torch2trt.py", line 400, in wrapper ret = attr(args, kwargs) TypeError: add_pooling_nd(): incompatible function arguments. The following argument types are supported:

  1. (self: tensorrt.tensorrt.INetworkDefinition, input: tensorrt.tensorrt.ITensor, type: tensorrt.tensorrt.PoolingType, window_size: tensorrt.tensorrt.Dims) -> tensorrt.tensorrt.IPoolingLayer ​ Invoked with: <tensorrt.tensorrt.INetworkDefinition object at 0x7f1e5ce9ce70>; kwargs: input=<tensorrt.tensorrt.ITensor object at 0x7f1e5cd781b0>, type=<PoolingType.MAX: 0>, window_size=([1, 3, 3], [1, 3, 3], [1, 3, 3])

This is the link to the i3d model I'm using: https://github.com/piergiaj/pytorch-i3d/blob/master/pytorch_i3d.py

The code in the link above contains classes and methods for creating the network's architecture. I don't know if the "incompatible function arguments" are caused by the way in which the network's architecture is being created, or if it's just the architecture itself, or something else.

To instantiate the model, I'm running:


from models.pytorch_i3d import InceptionI3d from torch2trt.torch2trt import torch2trt

model = InceptionI3d(400, in_channels=3) model.load_state_dict(torch.load(weights)) model.train(False) model.eval().to(device)

input_trt = [torch.ones((batch_size, 3, 16, 224, 224)).cuda()] trt_model = torch2trt(model, input_trt, max_batch_size=batch_size)


Now I'm only trying with batch_size = 1. The weights I'm using can be downloaded from this link: https://github.com/rtvad-ml/i3d-dev/blob/master/models/rgb_imagenet.pt

Thanks in advance.

xjw00654 commented 1 year ago

just change the kernel_size to the (tuple, tuple) format in your model definition. It would work :D