Error converting custom Faster-RCNN model to tensorrt. (int object is not iterable)
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
I am also facing this same issue. Any help is appreciated.
I'm also having the same issue!
I also face this issue
Same problem.
same
same problem
Same problem!So,Anyone can help?
I also am facing this issue. Has anyone found a solution?
Was anyone successful? Got the same error!
me too :(
me too :(
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
how to solve?
Take a look at the TensorRTx repository, which contains TensorRT implementations of many models, including Faster-RCNN.
same issue, any update ?
Any update ?
Any updates here? It'd be great to have Faster-RCNN supported