Using Pretrained Resnet50 for MASKRCNN_RESNET50_FPN_V2

Hi, as the title suggests, I have a pretrained resnet50 model weights available, and I wanted to use those pretrained weights to fine tune the MASKRCNN_RESNET50_FPN_V2 model from torchvisions. I’ve successfully imported the weights, as it says “all keys matched successfully”. However, in this model, the resnet50 is the backbone weights only, as it also needs the FPN weights. I’m getting an error related to that:
File"…/feature_pyramid_network.py", line 185, in forward
names = list(x.keys())
AttributeError: ‘Tensor’ object has no attribute ‘keys’

I just don’t know how to fix this, do I just follow the implementation here? Thank you!

The input to FeaturePyramidNetwork.forward expects an OrderedDict[Tensor] containing the feature maps for each feature level, which is why the error is raised.
You could refer to this tutorial to see an example usage.

@ptrblck Thanks for the quick response and the link to the tutorial, but I still wasn’t able to solve the same error after trying the codes in the tutorial. I basically performed the same code as the tutorial for modifying the model for a new backbone, except that my backbone is loaded with my custom resnet50 weights.

I now understand that the FPN.forward expects the OrderedDict containing the feature maps, but how do I edit the feature maps and how do I decide how many feature maps, and which output size the feature maps should be? Sorry, I’m completely new to instance segmentation/object detection, so I’m not too familiar with this.