I also tried using this instead:
model = torchvision.models.detection.backbone_utils.resnet_fpn_backbone('resnet50',pretrained=True)
output = model(images, targets)

But it throws following error:

Screenshot 2021-11-15 1155441475×200 28.7 KB