结构
矩阵乘
y = x@w
y = x.matmul(w)
y = torch.matmul(x, w)
元素乘
y = x*w
y = x.mul(w)
y = torch.mul(x, w)
线性层 (torch.nn.Linear):
torch.nn.Linear(in_features, out_features, bias=True, device=None, dtype=None)
PyTorch中的输入/输出: 都是tensor
self.in_features = in_features
self.out_features = out_features
self.weight = Parameter(torch.empty((out_features, in_features), **factory_kwargs))
def forward(self, input: Tensor) -> Tensor:
return F.linear(input, self.weight, self.bias)
Torch docs中的官方示例
m = nn.Linear(20, 30)
input = torch.randn(128, 20)
output = m(input)
print(output.size())
m1 = nn.Linear(20, 30)
m2 = nn.Linear(30, 40)
x = torch.randn(128, 20)
y1 = m1(x)
y2 = m2(y1)
x = torch.randn(128, 4096, 30, 20)
y = m1(x)
y = m2(y)
传统卷积:信号系统中考虑之前时刻的信号经过一些过程后对现在时刻系统输出的影响。
互相关 (cross-correlation):深度学习领域的“卷积”,考虑两个函数之间基于空间位置的相关性
互相关函数
曾经的面试问题: 卷积计算输出的数值越大,表示什么含义?
torch.nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)
编码时刻
无比经典的LeNet系列
Channel: 通道/过滤器(卷积核)
使用MNIST/CIFAR-10/fashionMNIST数据集,训练图像分类模型
https://marp.app/