Initialize weights to CNN


I have some initial weights that I want to initialize a CNN layer with. The weights are of the shape (3,8,12). I defined a CNN layer as

conv1 = nn.Conv2d(3,8,kernel_size=(3,3), stride = 2)

I just guessed this initialization and that’s why I am getting the following error:

RuntimeError: Given weight of size [1, 3, 8, 12], expected bias to be 1-dimensional with 1 elements, but got bias of size [8] instead

My input is of size (3,244,244). Kindly let me know how can I initialize the CNN layer so that it accepts the weights.

Can you check

if the above doesn’t work
can you check the links below[1%2C+3%2C+8%2C+12]%2C+expected+bias+to+be+1-dimensional+with+1+elements%2C+but+got+bias+of+size+[8]+instead&oq=RuntimeError%3A+Given+weight+of+size+[1%2C+3%2C+8%2C+12]%2C+expected+bias+to+be+1-dimensional+with+1+elements%2C+but+got+bias+of+size+[8]+instead&aqs=chrome..69i57j69i58&sourceid=chrome&ie=UTF-8

With best regards,

Not sure where 12 came from. Your conv1 layer has 3 input channels, 8 output channels, kernel size of 3x3 and stride 2. Thus, you have 8 kernels, each has 3x(3x3) weights and 1 bias

Use conv1.bias.shape and conv1.weight.shape after initialization to get correct dimensions.