1. Global Average Pooling
Global Average Pooling(GAP)出自 Network in network
GAP 输入(H, W, C)-->(1, 1, C)
直接在HW上pooling,将信息压缩到一个点。
优点:和FC相比无训练参数,所以可以防止过拟合
参考 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 实现:
import torch
AP = torch.nn.AvgPool2d(kernel_size=2, stride=2)
GAP = torch.nn.AdaptiveAvgPool2d((1, 1))
img = torch.rand((1, 1, 4, 4))
print(img)
print(AP(img))
print(GAP(img))
(0 ,0 ,.,.) = 0.6732 0.6106 0.4917 0.0805 0.1563 0.3157 0.0982 0.5887 0.7983 0.1506 0.5492 0.9515 0.3850 0.7505 0.4365 0.7801 [torch.FloatTensor of size 1x1x4x4] Variable containing: (0 ,0 ,.,.) = 0.4389 0.3147 0.5211 0.6793 [torch.FloatTensor of size 1x1x2x2] Variable containing: (0 ,0 ,.,.) = 0.4885 [torch.FloatTensor of size 1x1x1x1]