How torch.nn.Conv2d compute the convolution matrix using its default filter.
I have a small problem to know how the calculation is performed and how to use my own filter (mask vector), and why we use unsqueeze from the model.
My code:
inputconv = torch.randn(3, 4, 4)
inputconv.unsqueeze_(0)
mm = torch.nn.Conv2d(3, 3, kernel_size=2, padding=0, stride=(2, 1))
print(inputconv)
print('Conv2d: ')
print(mm(inputconv))
output:
tensor([[[[ 0.8845, 0.2022, -0.8536, -0.5750],
[-0.6650, 0.1512, 1.4356, 0.4598],
[ 0.1666, 1.8639, 0.2500, -0.3754],
[-1.1593, 0.1265, 1.1665, -0.6877]],[[-0.3083, -0.7364, 1.6745, -1.6611], [ 0.7673, -0.9379, 0.0095, -0.4120], [ 0.8867, 0.0865, 0.1563, -0.0828], [ 0.8034, -0.6904, -0.4510, -0.6925]], [[-0.4779, -0.7025, -0.1098, 0.6809], [ 0.3011, 0.3318, -0.7675, -0.8880], [ 0.9923, -1.5812, -0.1318, 0.2460], [-0.0436, -0.1883, -0.1694, 0.3716]]]])
Conv2d:
tensor([[[[-0.1268, 0.0031, -0.3460],
[-0.0473, -0.3350, -0.1950]],[[ 0.1417, -0.8431, -0.4891], [ 0.9959, -0.2300, 0.1318]], [[ 0.0118, -0.4037, -0.5443], [ 0.3780, -0.5303, -0.3546]]]])
My question is how to custom filters using tensor variables: example tf = torch.Tensor([[1, 0, -1], [1, 0, -1], [1, 0, -1]])
Thank you all in advance!