I’m trying to add a fourth channel to a pre-trained Resnet.
When I copy the weights over, the Parameter loses its leaf node characteristics.
I’ve tried to set needs gradients etc. but no luck.
What do i need to do to make the newly copied weights a leaf_node ?
Thanks!
Here’s the example code:
model_ft = models.resnet18(pretrained=True)
#load the weigths into the new convolution, copy the last plane of the orig into the new
new_input_conv = nn.Conv2d(4, 64, kernel_size=7, stride=2, padding=3, bias=False)
new_input_conv.weight[:,0] = model_ft.conv1.weight[:,0].clone()
new_input_conv.weight[:,1] = model_ft.conv1.weight[:,1].clone()
new_input_conv.weight[:,2] = model_ft.conv1.weight[:,2].clone()
new_input_conv.weight[:,3] = model_ft.conv1.weight[:,2].clone()

new_input_conv.weight.is_leaf

Out[1]: False