Solved by maaft in post #2 
              
              
                Alright, I just stumbled across the model.named_modules() method that also returns the name of the layer. Here is the modified code to achieve the automatic replacement if anyone is interested: 
for name, module in model.named_modules():
    if(isinstance(module, nn.Conv2d)):
        kernel_size = m…