Output of resnet_fpn_backbone (pretrained)

Alex_Dob: <p>Im trying to get an output from a pretrained resnet_fpn_backbone for processing in object detection. Im using the finetuning model from torchvision (fasterrcnn_resnet50_fpn) to test pretraining. Unfortunately i failed several times and i don’t know what to change.</p>
<p>I used the following code (left out imports):</p>
<pre><code class="lang-auto">#MAKE MODEL

class Identity(nn.Module):
    def __init__(self):
        super(Identity, self).__init__()
        
    def forward(self, x):
        return x

model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
model.rpn = Identity()
model.roi_heads = Identity()

#MAKE INPUT-TEST-DATA

images = torch.rand(2, 3, 600, 1200)

boxes = np.array([[[0.29, 0.10, 0.43, 0.58],[0.24, 0.17, 0.33, 0.48]],[[0.04, 0.10, 0.63, 0.58],[0.29, 0.16, 0.43, 0.78]]])
boxes = boxes.astype(np.float32)
boxes = torch.from_numpy(boxes)
labels = torch.randint(1, 91, (2, 2))
images = list(image for image in images)
targets = []
for i in range(len(images)):
    d = {}
    d['boxes'] = boxes[i]
    d['labels'] = labels[i]
    targets.append(d)

#TEST MODEL (in model.train())

output = model(images, targets)     #I fail here!
print(output)
</code></pre>
<p>This is the error i receive:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/7/1/711b7c5cd3342faf676ac8dc0c9177c09b273091.png" data-download-href="https://discuss.pytorch.org/uploads/default/711b7c5cd3342faf676ac8dc0c9177c09b273091" title="Screenshot 2021-11-15 112310"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/7/1/711b7c5cd3342faf676ac8dc0c9177c09b273091_2_690x172.png" alt="Screenshot 2021-11-15 112310" data-base62-sha1="g8AQdpb92lPDfc0mpFwLWjZ6Rix" width="690" height="172" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/7/1/711b7c5cd3342faf676ac8dc0c9177c09b273091_2_690x172.png, https://discuss.pytorch.org/uploads/default/optimized/3X/7/1/711b7c5cd3342faf676ac8dc0c9177c09b273091_2_1035x258.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/7/1/711b7c5cd3342faf676ac8dc0c9177c09b273091_2_1380x344.png 2x" data-dominant-color="2C2C2C"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2021-11-15 112310</span><span class="informations">1483×370 53 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

Alex_Dob: <p>I also tried using this instead:</p>
<pre><code class="lang-auto">model = torchvision.models.detection.backbone_utils.resnet_fpn_backbone('resnet50',pretrained=True)
output = model(images, targets)
</code></pre>
<p>But it throws following error:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/4/8/486f34df6f073f3fbb3f7d4a2f9904f301efcc0a.png" data-download-href="https://discuss.pytorch.org/uploads/default/486f34df6f073f3fbb3f7d4a2f9904f301efcc0a" title="Screenshot 2021-11-15 115544"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/4/8/486f34df6f073f3fbb3f7d4a2f9904f301efcc0a_2_690x93.png" alt="Screenshot 2021-11-15 115544" data-base62-sha1="akMDtKU6dYj7ogfpNEEHsCwDCc2" width="690" height="93" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/4/8/486f34df6f073f3fbb3f7d4a2f9904f301efcc0a_2_690x93.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/8/486f34df6f073f3fbb3f7d4a2f9904f301efcc0a_2_1035x139.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/8/486f34df6f073f3fbb3f7d4a2f9904f301efcc0a_2_1380x186.png 2x" data-dominant-color="2C2C2C"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2021-11-15 115544</span><span class="informations">1475×200 28.7 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>