IndexError: list index out of range
See original GitHub issue🐛 Bug
To Reproduce
Steps to reproduce the behavior:
- Run the TorchVision Object Detection Finetuning Tutorial.
- For the model, I used the instructions for
- Modifying the model to add a different backbone
But I keep getting the following error:
`--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-16-159df024665a> in <module> 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
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
into
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#L202I believe there might be a mismatch there (like, strings vs ints?)