Hi Lavish!



 lavish619:

So how can I change the layer configuration without changing the weights keeping the kernel size same.


If it were me, I would probably do:
for i in range(23):
    saveWeight = self.resnet.layer3[i].conv2
    self.resnet.layer3[i].conv2 = nn.Conv2d (256, 256,
                                            kernel_size=3,
                                            stride=1, 
                                            padding=2,
                                            dilation=2, 
                                            bias=False)
    with torch.no_grad():
        self.resnet.layer3[i].conv2.weight.copy_ (saveWeight)


I think that the following would also work (but I haven’t tried it):
for i in range(23):
    self.resnet.layer3[i].conv2.dilation = (2, 2)


The issue is that I don’t know whether Conv2d does something
non-trivial with dilation when its constructor is called (other than
just self.dilation = dilation), and even if this scheme works
now, I don’t know whether it would be guaranteed to work in the future.
Best.
K. Frank