|

楼主 |
发表于 2024-5-15 11:53:22
|
显示全部楼层
使用Conv2d进行简单二维卷积运算
import torch
import torch.nn as nn
# With square kernels and equal stride
m= nn.Conv2d(1, 1, 1, stride=1)
input = torch.randn(1,1,2,2)
input = torch.tensor([[[[ 1., 2.],[ 3., 4.]]]])
m.weight = torch.nn.Parameter(torch.ones(1,1,1,1))
m.bias = torch.nn.Parameter(torch.zeros(1))
output = m(input)
print(input)
print(m.weight)
print(m.bias)
print(output)
|
|