Initialise pytorch convolution layer with my own values
I want to know if there's a way to initialize pytorch convolution filter with my own values.
eg, I have a tuple [-0.8423, 0.3778][-3.1070, -2.6518]
and I want to initialize a 2X2 filter with these values, how do I do that? I looked up some answers but they were mostly using torch normal distribution and others. Nothing that I can't specify.
Let me know.
You can directly assign values to weigts:
conv = nn.Conv2d(1, 1, kernel_size=2)
with torch.no_grad():
conv.weight.data = torch.tensor([[-0.8423, 0.3778],[-3.1070, -2.6518]]) # you might need to play a bit with the dimensionality of this tensor