Hi I want to copy  weights of  a network to another network and freeze that weights and the second network just updates the layers that differs from first networks(second network has some layers exactly the same as first network and some different layers and I want to copy the weights of first network in similar layers and freeze them and then train the second network to find different layers’ weights).
copy:
def weights_init_receive(m):
    model2.conv1=copy.deepcopy(model.conv1)
    model2.conv2=copy.deepcopy(model.conv2)
    model2.conv3=copy.deepcopy(model.conv3)

require grad:
for name, param in model2.named_parameters():
  if param.requires_grad and 'conv1' in name:
    param.requires_grad = False
  if param.requires_grad and 'conv2' in name:
    param.requires_grad = False
  if param.requires_grad and 'conv3' in name:
    param.requires_grad = False 

set optimizer:
torch.optim.Adam(filter(lambda p: p.requires_grad, model2.parameters()), lr=0.1)
Adam (
Parameter Group 0
    amsgrad: False
    betas: (0.9, 0.999)
    eps: 1e-08
    lr: 0.1
    weight_decay: 0
)

now my problem is this!!!
I have 3 conv layer that their requires_grad=True
new layers does not change at all…
how could I fix it?
and I got this error after loss.backward()
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn