[error] torchvision object detection finetuning tutorial

This tutorial(https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html) contains codes for not only 1) finetuning but also 2)modifying the model to add a different backbone.

In the code given for the second option, I think there is a typo in it.
There is a code like below:

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

However, this code gives an error.
If the output of the backbone network is Tensor type, then its featmap_names should be [‘0’] rather than [0]. Because of this, if you just execute the given code it makes ‘out of range’ error since it cannot find any matching feature having 0 as a key (not ‘0’)

This is related to this line

I executed the code on Colab and it finished without raising an error.
Are you getting an error using your custom code or the tutorial directly?

I used the code directly on Colab environment. What I did is copy the suggested code and replace ‘get_instance_segmentation_model’ method with the copied code.

The following messages are the exact error message that I get.

/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py:2854: UserWarning: The default behavior for interpolate/upsample with float scale_factor will change in 1.6.0 to align with other frameworks/libraries, and use scale_factor directly, instead of relying on the computed output size. If you wish to keep the old behavior, please set recompute_scale_factor=True. See the documentation of nn.Upsample for details. 
  warnings.warn("The default behavior for interpolate/upsample with float scale_factor will change "
/pytorch/torch/csrc/utils/python_arg_parser.cpp:756: UserWarning: This overload of nonzero is deprecated:
	nonzero(Tensor input, *, Tensor out)
Consider using one of the following signatures instead:
	nonzero(Tensor input, *, bool as_tuple)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-9-1ea96e94502e> in <module>()
      4 for epoch in range(num_epochs):
      5     # train for one epoch, printing every 10 iterations
----> 6     train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
      7     # update the learning rate
      8     lr_scheduler.step()

7 frames
/usr/local/lib/python3.6/dist-packages/torchvision/ops/poolers.py in setup_scales(self, features, image_shapes)
    157         # get the levels in the feature map by leveraging the fact that the network always
    158         # downsamples by a factor of 2 at each level.
--> 159         lvl_min = -torch.log2(torch.tensor(scales[0], dtype=torch.float32)).item()
    160         lvl_max = -torch.log2(torch.tensor(scales[-1], dtype=torch.float32)).item()
    161         self.scales = scales

IndexError: list index out of range

And Recently I find a similar question that has been asked before.

It might be related to the version issue. But I think at least it should have no error on Colab.

I got the same warning message when running torchvision_finetuning_instance_segmentation tutorial in colab.

1 Like