pytorch学习笔记-高阶篇(池化层)
本篇主要记录一下一些卷积神经网络中池化层和采样相关知识
一、下采样(降维)
1.原始 sub sampling
最初的降维的下采样没有复杂的机制,只是简单的隔行采样
1.最大池化 max pooling
同样用一个小窗口扫描整个feature map,比较特殊的是最大池化指的是取小窗口中最大值作为采样值
2.平均池化 Avg pooling
x = torch.randn([1, 16, 14, 14])
# Out[4]: torch.Size([1, 16, 14, 14])
layer = nn.MaxPool2d(kernel_size=2, stride=2)
out = layer(x)
# Out[8]: torch.Size([1, 16, 7, 7])
out = F.avg_pool2d(x, 2, stride=2)
# Out[12]: torch.Size([1, 16, 7, 7])
二、上采样(放大)
out = F.interpolate(x, scale_factor=2, mode='nearest')
# Out[14]: torch.Size([1, 16, 28, 28])
out = F.interpolate(x, scale_factor=3, mode='nearest')
# Out[16]: torch.Size([1, 16, 42, 42])
三、ReLu
# 3.ReLu
x.shape
# Out[17]: torch.Size([1, 16, 14, 14])
# 输出的维度和输入一致,可以共用空间以节省空间
layer = nn.ReLU(inplace=True)
out = layer(x)
# Out[19]: torch.Size([1, 16, 14, 14])
out = F.relu(x)
# Out[21]: torch.Size([1, 16, 14, 14])
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 不听话的兔子君!