Vision: IndexError: list index out of range

Created on 26 Mar 2020  路  6Comments  路  Source: pytorch/vision

馃悰 Bug

To Reproduce

Steps to reproduce the behavior:

  1. Run the TorchVision Object Detection Finetuning Tutorial.
  2. For the model, I used the instructions for
  1. Modifying the model to add a different backbone

But I keep getting the following error:

`---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
in
4 for epoch in range(num_epochs):
5 # train for one epoch, printing every 10 iterations
----> 6 train_one_epoch(model, optimizer, train_loader, device, epoch, print_freq=10)
7 # update the learning rate
8 lr_scheduler.step()

/Volumes/Samsung_T5/OneDrive - Coventry University/detector/faster_rcnn_v23/engine.py in train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq)
28 targets = [{k: v.to(device) for k, v in t.items()} for t in targets]
29
---> 30 loss_dict = model(imgs1, targets)
31
32 losses = sum(loss for loss in loss_dict.values())

~/opt/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py in __call__(self, input, *kwargs)
530 result = self._slow_forward(input, *kwargs)
531 else:
--> 532 result = self.forward(input, *kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)

~/opt/miniconda3/envs/torch/lib/python3.8/site-packages/torchvision/models/detection/generalized_rcnn.py in forward(self, images, targets)
69 features = OrderedDict([('0', features)])
70 proposals, proposal_losses = self.rpn(images, features, targets)
---> 71 detections, detector_losses = self.roi_heads(features, proposals, images.image_sizes, targets)
72 detections = self.transform.postprocess(detections, images.image_sizes, original_image_sizes)
73

~/opt/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py in __call__(self, input, *kwargs)
530 result = self._slow_forward(input, *kwargs)
531 else:
--> 532 result = self.forward(input, *kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)

~/opt/miniconda3/envs/torch/lib/python3.8/site-packages/torchvision/models/detection/roi_heads.py in forward(self, features, proposals, image_shapes, targets)
754 matched_idxs = None
755
--> 756 box_features = self.box_roi_pool(features, proposals, image_shapes)
757 box_features = self.box_head(box_features)
758 class_logits, box_regression = self.box_predictor(box_features)

~/opt/miniconda3/envs/torch/lib/python3.8/site-packages/torch/nn/modules/module.py in __call__(self, input, *kwargs)
530 result = self._slow_forward(input, *kwargs)
531 else:
--> 532 result = self.forward(input, *kwargs)
533 for hook in self._forward_hooks.values():
534 hook_result = hook(self, input, result)

~/opt/miniconda3/envs/torch/lib/python3.8/site-packages/torchvision/ops/poolers.py in forward(self, x, boxes, image_shapes)
186 rois = self.convert_to_roi_format(boxes)
187 if self.scales is None:
--> 188 self.setup_scales(x_filtered, image_shapes)
189
190 scales = self.scales

~/opt/miniconda3/envs/torch/lib/python3.8/site-packages/torchvision/ops/poolers.py in setup_scales(self, features, image_shapes)
159 # get the levels in the feature map by leveraging the fact that the network always
160 # downsamples by a factor of 2 at each level.
--> 161 lvl_min = -torch.log2(torch.tensor(scales[0], dtype=torch.float32)).item()
162 lvl_max = -torch.log2(torch.tensor(scales[-1], dtype=torch.float32)).item()
163 self.scales = scales

IndexError: list index out of range`

I tried different models and adjusted the actors and scales, but keep getting this error.

Environment

PyTorch version: 1.4.0
Is debug build: No
CUDA used to build PyTorch: None

OS: Mac OSX 10.15.3
GCC version: Could not collect
CMake version: Could not collect

Python version: 3.8
Is CUDA available: No
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA

Versions of relevant libraries:
[pip] numpy==1.18.1
[pip] torch==1.4.0
[pip] torchvision==0.5.0
[conda] blas                      1.0                         mkl  
[conda] mkl                       2019.4                      233  
[conda] mkl-service               2.3.0            py38hfbe908c_0  
[conda] mkl_fft                   1.0.15           py38h5e564d8_0  
[conda] mkl_random                1.1.0            py38h6440ff4_0  
[conda] pytorch                   1.4.0                   py3.8_0    pytorch
[conda] torchvision               0.5.0                  py38_cpu    pytorch

models question object detection

Most helpful comment

Had this same error occur while attempting to perform the same tutorial.. but with ResNet101 .. perhaps the docs should be updated or a note added to reflect this ?

I fixed the same error with just changing from

roi_pooler = torchvision.ops.MultiScaleRoIAlign(featmap_names=[0],
                                                        output_size=rpn_pooling_size,
                                                        sampling_ratio=2)

into

` roi_pooler = torchvision.ops.MultiScaleRoIAlign(featmap_names=["0"], output_size=rpn_pooling_size, sampling_ratio=2)

All 6 comments

Hi,

Make sure that the feature map names returned by your backbone are compatible with the RoIPooler, see https://github.com/pytorch/vision/blob/1c7aa0c0910d518971e694620b58485704a006a8/torchvision/models/detection/faster_rcnn.py#L202

I believe there might be a mismatch there (like, strings vs ints?)

@fmassa thank you very much! That seems to have resolved the issue.

Cool, closing it then

Had this same error occur while attempting to perform the same tutorial.. but with ResNet101 .. perhaps the docs should be updated or a note added to reflect this ?

I fixed the same error with just changing from

roi_pooler = torchvision.ops.MultiScaleRoIAlign(featmap_names=[0],
                                                        output_size=rpn_pooling_size,
                                                        sampling_ratio=2)

into

` roi_pooler = torchvision.ops.MultiScaleRoIAlign(featmap_names=["0"], output_size=rpn_pooling_size, sampling_ratio=2)

@EMCP could you please send a PR fixing the tutorial?

hi @EMCP Could you please share your fasterRCNN with resnet101 code? Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ibtingzon picture ibtingzon  路  3Comments

300LiterPropofol picture 300LiterPropofol  路  3Comments

Linardos picture Linardos  路  4Comments

chinglamchoi picture chinglamchoi  路  3Comments

Abolfazl-Mehranian picture Abolfazl-Mehranian  路  3Comments