How to update the resnet backbone of deeplabv3 with pretrained resnet weights?

I was wondering if it is possible to update the resnet part of deeplabv3 with the pretrain weights of resnet50?

import torch
import torchvision
import torchvision.models as models

model = models.segmentation.deeplabv3_resnet50(num_classes=21, pretrained=False)
res50 = torchvision.models.resnet50(pretrained=False)

doing something like below is not working correctly:

model.backbone.load_state_dict(res50.state_dict(), strict=False)
_IncompatibleKeys(missing_keys=[], unexpected_keys=['fc.weight', 'fc.bias'])

I think it’s working as expected, since apparently the classifier of the resnet seems to be replaced with the DeepLabHead, so you won’t be able to load the fc parameters into the backbone.

1 Like

oh I thought there was something wrong :smiley:
Thanks for clarification, I can confirm that the weights of the backbone are getting updated by checking