I want to change the weights of first layer of resnet model maually
the first layer is :
(conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
and the weights shape is:
[64, 3, 7, 7]
You could reassign a new nn.Parameter
to your weights or just set the values depending on your use case.
Here is a small example how to assign new parameters:
with torch.no_grad():
model.conv1.weight = nn.Parameter(torch.randn(64, 3, 7, 7))
# or
model.conv1.weight.copy_(torch.randn(64, 3, 7, 7))