How to Convert FC layers to CONV layers in a pretrained model like VGG?

Hi,
I want to convert the FC layers in the VGG-16 model to a CONV layers while keeping and using the pretrained weights. How should I act on this?

Thanks,
Saeed

Hi, you mean how to convert fc weights to conv kernel’s weight? if so I did like below.

fc_net.conv.load_state_dict({"weight": resnet.fc.state_dict()["weight"].view(1000, 2048, 1, 1),
                             "bias": resnet.fc.state_dict()["bias"]})
1 Like

Great,
Will give it a try.

Thanks