This tutorial(https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html 9) 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

  
      github.com
  
  
    pytorch/vision/blob/e92b5155d7d78363826a822ccacf7c046d19245a/torchvision/models/detection/generalized_rcnn.py#L97 6

        if degenerate_boxes.any():
            # print the first degenrate box
            bb_idx = degenerate_boxes.any(dim=1).nonzero().view(-1)[0]
            degen_bb: List[float] = boxes[bb_idx].tolist()
            raise ValueError("All bounding boxes should have positive height and width."
                             " Found invaid box {} for target at index {}."
                             .format(degen_bb, target_idx))

features = self.backbone(images.tensors)
if isinstance(features, torch.Tensor):
    features = OrderedDict([('0', features)])
proposals, proposal_losses = self.rpn(images, features, targets)
detections, detector_losses = self.roi_heads(features, proposals, images.image_sizes, targets)
detections = self.transform.postprocess(detections, images.image_sizes, original_image_sizes)

losses = {}
losses.update(detector_losses)
losses.update(proposal_losses)

if torch.jit.is_scripting():
    if not self._has_warned: