参考
https://zhuanlan.zhihu.com/p/37683646
2.与Global Max Pooling
都是压缩信息。只不过方式不同,SEnet实验证明,average稍微好一点
参考:https://www.zhihu.com/question/358913301/answer/922183264
3.与 Average Pooling
输入(H, W, C)
GAP输出:(1, 1, C):相当于信息压缩,关注全局特征
AP(after_pooling_size, after_pooling_size, C):信息提取,保留纹理信息,关注局部特征。
在数学关系上可以把GAP理解成AP的一种特例
4.torch 实现:
1.Global Average PoolingGlobal Average Pooling(GAP)出自 Network in networkGAP 输入(H, W, C)-->(1, 1, C)直接在HW上pooling,将信息压缩到一个点。优点:和FC相比无训练参数,所以可以防止过拟合参考https://zhuanlan.zhihu.com/p/376836...
https://www.zhihu.com/question/358913301
https://blog.csdn.net/qq_16234613/article/details/79520929
https://www.cnblogs.com/hutao722/p/10008581.html
Adaptive
Pool
ing
可通过输入大小input_size自适应控制输出大小output_size,
而一般的Avg
Pool
ing
/
Max
Pool
ing
则是通过kernel_size、stride、padd
ing
来计算output_size,公式如下:
outputsize=ceil((inputsize+2∗padd
ing
−kernelsize)/stride)+1output_s
池化层简述池化层的分类最大/均值池化中值池化组合池化Spatial Pyramid
Pool
ing
Global
Average
/
Max
Pool
ing
参考文献
池化层(
Pool
ing
Layer)是CNN中常见的一种操作,池化层通常也叫做子采样(subsampl
ing
)或降采样(Downsampl
ing
),在构建CNN网络时,往往是用在卷积层之后,通过池化层来降低卷积层输出的特征维度,在有效减少网络参数的同时还可以防止过拟合现象。
说到池化操作,就会想到我们经常用的池化操作,即最大池化(
Max
在一些论文中,我们可能会看到全局平均池化操作,但是我们从pytorch官方文档中却找不到这个API,那我们应该怎么办?
利用现有的
pool
ing
API实现全局平均池化的效果。
首先我们简单理解全局平均池化操作。
如果有一批特征图,其尺寸为 [ B, C, H, W], 我们经过全局平均池化之后,尺寸变为[B, C, 1, 1]。
也就是说,全局平均池化其实就是对每...
参考:https://blog.csdn.net/JN
ing
Wei/article/details/80064451(全局池化)
https://blog.csdn.net/williamyi96/article/details/77530995(
Global
Average
Pool
ing
对全连接层的可替代性分析)
https://blog.c...
If you want a
global
average
pool
ing
layer, you can usenn.AdaptiveAvg
Pool
2d(1). In Keras you can just use
Global
Average
Pool
ing
2D.
Pytorch官方文档:
torch.nn.AdaptiveAvg
Pool
2d(output_size)[SOURCE]
Appli...
假如特征图是512,7,7,要变成512,1,1,使用GAP
avg
pool
= nn.Avg
Pool
2d(7, stride=1) #Avg
Pool
2d(kernel_size=7, stride=1, padd
ing
=0),kernel大小为7*7
avg
pool
= F.adaptive_avg_
pool
2d(
feature
_map, (1,1))
对于输入信号的输入通道,提供2维最大池化(
max
pool
ing
)操作
class torch.nn.
Max
Pool
2d(kernel_size, stride=None, padd
ing
=0, dilation=1, return_indices=False, ceil_mode=False)
参数kernel_size,stride, padd
ing
,dilation数据类型: 可以是一个i...
1
Max
Pool
torch.nn.
Max
Pool
1d(kernel_size, stride=None, padd
ing
=0, dilation=1, return_indices=False, ceil_mode=False)
torch.nn.
Max
Pool
2d(kernel_size, stride=None, padd
ing
=0, dilation=1, return_indices=...
对torch.nn.
Max
Pool
1d各参数(kernel_size、stride、ceil_mode、dilation、padd
ing
)的小白文分析:含官方定义和初步翻译、用代码测试并画图举例讲解各参数的作用。
另外讨论了torch.nn.
Max
Pool
1d与torch.
max
的区别。
class ConvNet(nn.Module):
def __init__(self, num_classes=10):
super(ConvNet, self).__init__()
self.conv1 = nn.Conv2d(3, 64, kernel_size=3, padd
ing
=1)
self.bn1 = nn.BatchNorm2d(64)
self.relu1 = nn.ReLU(inplace=True)
self.conv2 = nn.Conv2d(64, 64, kernel_size=3, padd
ing
=1)
self.bn2 = nn.BatchNorm2d(64)
self.relu2 = nn.ReLU(inplace=True)
self.
pool
1 = nn.
Max
Pool
2d(kernel_size=2, stride=2)
self.conv3 = nn.Conv2d(64, 128, kernel_size=3, padd
ing
=1)
self.bn3 = nn.BatchNorm2d(128)
self.relu3 = nn.ReLU(inplace=True)
self.conv4 = nn.Conv2d(128, 128, kernel_size=3, padd
ing
=1)
self.bn4 = nn.BatchNorm2d(128)
self.relu4 = nn.ReLU(inplace=True)
self.
pool
2 = nn.
Max
Pool
2d(kernel_size=2, stride=2)
self.conv5 = nn.Conv2d(128, 256, kernel_size=3, padd
ing
=1)
self.bn5 = nn.BatchNorm2d(256)
self.relu5 = nn.ReLU(inplace=True)
self.conv6 = nn.Conv2d(256, 256, kernel_size=3, padd
ing
=1)
self.bn6 = nn.BatchNorm2d(256)
self.relu6 = nn.ReLU(inplace=True)
self.
pool
3 = nn.
Max
Pool
2d(kernel_size=2, stride=2)
self.avg
pool
= nn.AdaptiveAvg
Pool
2d((1, 1))
self.
fc
= nn.Linear(256, num_classes)
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu1(x)
x = self.conv2(x)
x = self.bn2(x)
x = self.relu2(x)
x = self.
pool
1(x)
x = self.conv3(x)
x = self.bn3(x)
x = self.relu3(x)
x = self.conv4(x)
x = self.bn4(x)
x = self.relu4(x)
x = self.
pool
2(x)
x = self.conv5(x)
x = self.bn5(x)
x = self.relu5(x)
x = self.conv6(x)
x = self.bn6(x)
x = self.relu6(x)
x = self.
pool
3(x)
x = self.avg
pool
(x)
x = x.view(x.size(0), -1)
x = self.
fc
(x)
return x
该网络实现了6个卷积层,每个卷积层后跟一个 Batch Normalization 和一个 ReLU 层,经过两个卷积层后,特征的空间分辨率降低两倍,特征的 channel 数量提升两倍。在最后的输出层,使用
Global
Average
Pool
ing
操作,把特征层转换为一个特征向量,然后使用全连接神经网络完成最终的预测。
Error when checking input: expected input_1 to have 3 dimensions, but got array with shape (37, 30)
22587
论文阅读DRIVEVLM: The Convergence of Autonomous Driving and Large Vision-Language Models
CSDN-Ada助手:
docker/ nvidia-docker
CSDN-Ada助手: