Incorrect Conv2D Output


I was trying to understand and mimic conv2D. However, I am not able to comprehend the output value of the conv2d.
I am defining my input and also assigning the custom weights to the conv2d.
Below is the code:

import torch

m = torch.nn.Conv2d(1, 1, 3, stride= 1)
input = torch.randn(1, 1, 3, 3)

input = torch.randint(0,2,(1,1,3,3), dtype= torch.float32)
weight = torch.randint(0,2,(1,1,3,3), dtype= torch.float32)
print("Default Conv Weight ", weight
true_output = m(input)
print("Assigned Conv Weight ", m.weight)
print("Conv Weight ", weight)
print("Conv input ", input)
print('True Output',true_output)
print('True Output Shape', true_output.shape)

Output Image:


From the output image, I was expecting the output to be 3, but it shows 3.16. I am not sure what is happening under the module.
@HDCharles @jcaip @jerryzh168


You are not considering the bias which will be added to your output activation.

1 Like

Yes, I completely missed that. Thanks