NVIDIA-AI-IOT / torch2trt

An easy to use PyTorch to TensorRT converter
MIT License
4.55k stars 671 forks source link

Error converting custom Faster-RCNN model to tensorrt. (int object is not iterable) #247

Open ankitkpr93 opened 4 years ago

ankitkpr93 commented 4 years ago

Hi, I have been trying to convert the Resnet18_fpn customized Faster-RCNN network using following code.

import torch
import torchvision
import torch2trt
import tensorrt as trt

model = get_model_instance('resnet18_fpn', num_classes)
model = model.cuda().eval().half()

class ModelWrapper(torch.nn.Module):
    def __init__(self, model):
        super(ModelWrapper, self).__init__()
        self.model = model
    def forward(self, x):
        return self.model(x)['out']

model_w = ModelWrapper(model).half()
data = torch.ones((1, 3, 720, 1280)).cuda().half()
model_trt = torch2trt.torch2trt(model_w, [data], fp16_mode=True)

This code is throwing following error.

Traceback (most recent call last):
  File "inference.py", line 113, in <module>
    main()
  File "inference.py", line 110, in main
    inference_video(args.dataset_path,args.model_name,args.checkpoint_path,args.score_threshold,args.video_path)
  File "inference.py", line 55, in inference_video
    model_trt = torch2trt(model_w, [data], fp16_mode=True)
  File "/usr/local/lib/python2.7/dist-packages/torch2trt/torch2trt.py", line 377, in torch2trt
    outputs = module(*inputs)
  File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "inference.py", line 51, in forward
    return self.model(x)['out']
  File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "build/bdist.linux-aarch64/egg/torchvision/models/detection/generalized_rcnn.py", line 46, in forward
  File "/usr/local/lib/python2.7/dist-packages/torch/tensor.py", line 411, in <lambda>
    return iter(imap(lambda i: self[i], range(self.size(0))))
  File "/usr/local/lib/python2.7/dist-packages/torch2trt/torch2trt.py", line 202, in wrapper
    converter['converter'](ctx)
  File "/usr/local/lib/python2.7/dist-packages/torch2trt/converters/getitem.py", line 34, in convert_tensor_getitem
    num_ellipsis = input.ndim - num_slice_types(slices)
  File "/usr/local/lib/python2.7/dist-packages/torch2trt/converters/getitem.py", line 18, in num_slice_types
    for s in slices:
TypeError: 'int' object is not iterable
MrunaliniN commented 4 years ago

I am also facing this same issue. Any help is appreciated.

julayelei commented 4 years ago

I'm also having the same issue!

IU971001 commented 4 years ago

I also face this issue

izillio commented 4 years ago

Same problem.

jugi92 commented 4 years ago

same

z-bingo commented 4 years ago

same problem

lrh454830526 commented 4 years ago

Same problem!So,Anyone can help?

danielzgsilva commented 3 years ago

I also am facing this issue. Has anyone found a solution?

Ekta246 commented 3 years ago

Was anyone successful? Got the same error!

Yuuuuuuuuuuuuuuuuuummy commented 3 years ago

me too :(

Yuuuuuuuuuuuuuuuuuummy commented 3 years ago

me too :(

akum04 commented 3 years ago

Any solution to the issue... I'm struggling to convert the fasterrcnn_resnet50_fpn... here is the script I used and the error message I got.

import torch
from torch2trt import torch2trt
from torchvision.models.detection import fasterrcnn_resnet50_fpn

# create some regular pytorch model...
model = fasterrcnn_resnet50_fpn(pretrained=True).eval().cuda()

# create example data
x = torch.ones((1, 3, 224, 224)).cuda()

# convert to TensorRT feeding sample data as input
model_trt = torch2trt(model, [x])
/miniconda3/envs/deep_learning/lib/python3.6/site-packages/torchvision/ops/boxes.py:101: 
UserWarning: This overload of nonzero is deprecated:
        nonzero()
Consider using one of the following signatures instead:
        nonzero(*, bool as_tuple) (Triggered internally at  /opt/conda/conda-bld/pytorch_1595629427286/work/torch/csrc/utils/python_arg_parser.cpp:766.)
  keep = keep.nonzero().squeeze(1)
Warning: Encountered known unsupported method torch.Tensor.__iter__
Traceback (most recent call last):
  File "./test/model2trt.py", line 12, in <module>
    model_trt = torch2trt(model, [x])
  File "/home/arunkumar/miniconda3/envs/deep_learning/lib/python3.6/site-packages/torch2trt-0.1.0-py3.6.egg/torch2trt/torch2trt.py", line 531, in torch2trt
  File "/home/arunkumar/miniconda3/envs/deep_learning/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/arunkumar/miniconda3/envs/deep_learning/lib/python3.6/site-packages/torchvision/models/detection/generalized_rcnn.py", line 74, in forward
    for img in images:
  File "/home/arunkumar/miniconda3/envs/deep_learning/lib/python3.6/site-packages/torch/tensor.py", line 456, in <lambda>
    return iter(map(lambda i: self[i], range(self.size(0))))
  File "/home/arunkumar/miniconda3/envs/deep_learning/lib/python3.6/site-packages/torch2trt-0.1.0-py3.6.egg/torch2trt/torch2trt.py", line 285, in wrapper
  File "/home/arunkumar/miniconda3/envs/deep_learning/lib/python3.6/site-packages/torch2trt-0.1.0-py3.6.egg/torch2trt/converters/getitem.py", line 34, in convert_tensor_getitem
  File "/home/arunkumar/miniconda3/envs/deep_learning/lib/python3.6/site-packages/torch2trt-0.1.0-py3.6.egg/torch2trt/converters/getitem.py", line 18, in num_slice_types
TypeError: 'int' object is not iterable
dongwangGithub commented 3 years ago

how to solve?

ira7bar commented 3 years ago

Take a look at the TensorRTx repository, which contains TensorRT implementations of many models, including Faster-RCNN.

senecobis commented 2 years ago

same issue, any update ?

jihad-akl commented 1 year ago

Any update ?

cullenwren-volair commented 6 months ago

Any updates here? It'd be great to have Faster-RCNN supported