import torch
import torch.nn.functional as F
input = torch.tensor([[1, 2, 0, 3, 1],
[0, 1, 2, 3, 1],
[1, 2, 1, 0, 0],
[5, 2, 3, 1, 1],
[2, 1, 0, 1, 1]])
kernel = torch.tensor([[1, 2, 1],
[0, 1, 0],
[2, 1, 0]])
print(input.shape)
print(kernel.shape)
input = torch.reshape(input, (1, 1, 5, 5))
kernel = torch.reshape(kernel, (1, 1, 3, 3))
print(input.shape)
print(kernel.shape)
output = F.conv2d(input, kernel, stride=1)
print(output)
input_1 = torch.tensor([[1, 2, 0, 3, 1],
[0, 1, 2, 3, 1],
[1, 2, 1, 0, 0],
[5, 2, 3, 1, 1],
[2, 1, 0, 1, 1]])
kernel_1 = torch.tensor([[1, 2, 1],
[0, 1, 0],
[2, 1, 0]])
print(input_1.shape)
print(kernel_1.shape)
input_1 = torch.reshape(input_1, (1, 1, 5, 5))
kernel_1 = torch.reshape(kernel_1, (1, 1, 3, 3))
output_1 = F.conv2d(input_1, kernel_1, stride=2)
print(output_1)
input_2 = torch.tensor([[1, 2, 0, 3, 1],
[0, 1, 2, 3, 1],
[1, 2, 1, 0, 0],
[5, 2, 3, 1, 1],
[2, 1, 0, 1, 1]])
kernel_2 = torch.tensor([[1, 2, 1],
[0, 1, 0],
[2, 1, 0]])
print(input_2.shape)
print(kernel_2.shape)
input_2 = torch.reshape(input_2, (1, 1, 5, 5))
kernel_2 = torch.reshape(kernel_2, (1, 1, 3, 3))
print(input_2.shape)
print(kernel_2.shape)
output_2 = F.conv2d(input_2, kernel_2, stride=1, padding=1)
print(output_2)