好奇怪啊.torch中conv2d没有将核旋转180的习惯,但反卷积却有
import torch
import torch.nn.functional as F
model = torch.nn.ConvTranspose2d(in_channels=1, out_channels=1, kernel_size=3,stride=1,padding=0)
x = torch.tensor([[[1,2],[3,4]]], dtype=torch.float32).unsqueeze(0)
model.weight.data = torch.tensor([[[[1,2,3],[4,5,6],[7,8,9]]]], dtype=torch.float32)
model.bias.data = torch.zeros(1)
print(model(x))
kernel=torch.tensor([[[[1,2,3],[4,5,6],[7,8,9]]]], dtype=torch.float32)
print(x)
print(kernel)
print(kernel.shape)
s=F.conv_transpose2d(x, kernel, stride=1, padding=0)
print(s)
kernel=torch.tensor([[[[1,1,1],[1,1,1],[1,1,1]]]], dtype=torch.float32)
print(kernel.shape)
s=F.conv_transpose2d(x, kernel, stride=2, padding=0)
print(s)
x = torch.tensor([[[12,16],[24,28]]], dtype=torch.float32).unsqueeze(0)
kernel=torch.tensor([[[[2,1],[1,1]]]], dtype=torch.float32)
s=F.conv2d(x,kernel)
print(s)