Load initial weights to one layer of the Convnet manually

Hello guys, I have a network of multiple layers, and I am trying to initialize the weights of the first layer manually, let us say I want to set the filters of the first layers to x=[1 2 3, 1 2 3, 1 2 3]. Or any other values I choose. How can I do that without effecting the weights in the others layers.

1 Like

Supposing that the first layer is an nn.Linear layer…

model.first_layer.weight.data = torch.Tensor([1, 2, 3, 1, 2, 3, 1, 2, 3])
model.first_layer.bias.data = ...

If you check the docs, then you can find the names for the weights of other layer types.

4 Likes

Thanks, It worked :slight_smile: