1.网络结构图
2.FPN 特征金字塔
https://mp.weixin.qq.com/s?__biz=MzA4MjY4NTk0NQ==&mid=2247485130&idx=2&sn=c69c07b5f8c268be52145b030a96b605&scene=21#wechat_redirect
多层次特征融合
3.PAN
PAN 是FPN 升级版 ,红色的线表示通过FPN获取的特征 ,绿色的线只通过几层就可以获取浅层信息,确保浅层信息的完整
https://mp.weixin.qq.com/s?__biz=MzA4MjY4NTk0NQ==&mid=2247485145&idx=2&sn=dbd970411f3ec2da25bf432af8400a74&chksm=9f80bc4fa8f7355924af4aec888671a31a499684aa5e4e86b4c502b7f28f2521040d7507b980&scene=21#wechat_redirect
4.SPP
SPP(空间金字塔池化)的思想来扩大感受野
class SPP(nn.Module):
# Spatial pyramid pooling layer used in YOLOv3-SPP
def __init__(self, c1, c2, k=(5, 9, 13)):
super(SPP, self).__init__()
c_ = c1 // 2 # hidden channels
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = Conv(c_ * (len(k) + 1), c2, 1, 1)
self.m = nn.ModuleList([nn.MaxPool2d(kernel_size=x, stride=1, padding=x // 2) for x in k])
def forward(self, x):
x = self.cv1(x)
return self.cv2(torch.cat([x] + [m(x) for m in self.m], 1))
代码就是数据通道扩展4倍,把原始的x 、x 使用kernel_size=5下采样、x 使用kernel_size=9下采样、x 使用kernel_size=14下采样.把这些数据结合一起。
5.SAM
Attention机制中的CBAM, CBAM含有空间注意力机制和通道注意力机制,
SAM就是其中的空间注意力机制.
class ChannelAttention(nn.Module):
def __init__(self, in_planes, ratio=16):
super(ChannelAttention, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.max_pool = nn.AdaptiveMaxPool2d(1)
self.fc1 = nn.Conv2d(in_planes, in_planes//16, 1, bias=False)
self.relu1 = nn.ReLU()
self.fc2 = nn.Conv2d(in_planes//16, in_planes, 1, bias=False)
self.sigmoid = nn.Sigmoid()
def forward(self,x):
avg_out = self.fc2(self.relu1(self.fc1(self.avg_pool(x))))
max_out = self.fc2(self.relu1(self.fc1(self.max_pool(x))))
out = avg_out + max_out
return self.sigmoid(out)
求特征图whc中每个 wh的均值和最大值,相当于获取每个wh的权重,这样计算每个通道的权重,然后再和原始数据相乘,就是增加了注意力
class SpatialAttention(nn.Module):
def __init__(self, kernel_size=7):
super(SpatialAttention,self).__init__()
self.conv1 = nn.Conv2d(2,1,kernel_size,padding=padding,bias=False)#concat完channel维度为2
self.sigmoid = nn.Sigmoid()
def forward(self,x):
avg_out = torch.mean(x, dim=1, keepdim=True)# 沿着channel 维度计算均值和最大值
max_out, _ = torch.max(x, dim=1, keepdim=True)
x = torch.cat([avg_out, max_out], dim=1)#沿着channel维度concat一块
x = self.conv1(x)
return self.sigmoid(x)
求特征图whc中每个1*c个点的均值和最大值,相当于获取每个点的权重,这样计算每个点的权重,然后再和原始数据相乘,就是增加了注意力
6.CmBN
https://zhuanlan.zhihu.com/p/115949091