广州企业建站素材,门户网站系统程序,少儿编程机构,有没有专门做二手的网站目录 1.背景介绍 论文题目#xff1a;《Coordinate Attention for Efficient Mobile NetWork Design》论文地址#xff1a; https://arxiv.org/pdf/2103.02907.pdf
2.原理介绍
3.YOLOv5改进#xff1a;
3.1common中加入下面代码
3.2在yolo.py中注册
3.3添加配置文件
…目录 1.背景介绍 论文题目《Coordinate Attention for Efficient Mobile NetWork Design》论文地址 https://arxiv.org/pdf/2103.02907.pdf
2.原理介绍
3.YOLOv5改进
3.1common中加入下面代码
3.2在yolo.py中注册
3.3添加配置文件
4.yolov7改进
4.1 在common中加入以下代码
4.2在yolo.py中注册
4.3添加配置文件 1.背景介绍 论文题目《Coordinate Attention for Efficient Mobile NetWork Design》论文地址 https://arxiv.org/pdf/2103.02907.pdf 2.原理介绍
本文中作者通过将位置信息嵌入到通道注意力中提出了一种新颖的移动网络注意力机制将其称为“Coordinate Attention”。与通过2维全局池化将特征张量转换为单个特征向量的通道注意力不同Coordinate注意力将通道注意力分解为两个1维特征编码过程分别沿2个空间方向聚合特征。这样可以沿一个空间方向捕获远程依赖关系同时可以沿另一空间方向保留精确的位置信息。然后将生成的特征图分别编码为一对方向感知和位置敏感的attention map可以将其互补地应用于输入特征图以增强关注对象的表示。 step1: 为了避免空间信息全部压缩到通道中这里没有使用全局平均池化。为了能够捕获具有精准位置信息的远程空间交互对全局平均池化进行的分解具体如下 对尺寸为C ∗ H ∗ W C*H*WC∗H∗W输入特征图I n p u t InputInput分别按照X XX方向和Y YY方向进行池化分别生成尺寸为C ∗ H ∗ 1 C*H*1C∗H∗1和C ∗ 1 ∗ W C*1*WC∗1∗W的特征图。如下图所示图片粘贴自B站大佬渣渣的熊猫潘。 step2:将生成的C ∗ 1 ∗ W C*1*WC∗1∗W的特征图进行变换然后进行concat操作。公式如下 ..................
最后Coordinate Attention 的输出公式可以写成 不同于通道注意力将输入通过2D全局池化转化为单个特征向量CoordAttention将通道注意力分解为两个沿着不同方向聚合特征的1D特征编码过程。这样的好处是可以沿着一个空间方向捕获长程依赖沿着另一个空间方向保留精确的位置信息。然后将生成的特征图分别编码形成一对方向感知和位置敏感的特征图它们可以互补地应用到输入特征图来增强感兴趣的目标的表示 3.YOLOv5改进
3.1 common中加入下面代码 class h_sigmoid(nn.Module):def __init__(self, inplaceTrue):super(h_sigmoid, self).__init__()self.relu nn.ReLU6(inplaceinplace)def forward(self, x):return self.relu(x 3) / 6class h_swish(nn.Module):def __init__(self, inplaceTrue):super(h_swish, self).__init__()self.sigmoid h_sigmoid(inplaceinplace)def forward(self, x):return x * self.sigmoid(x)
class CA(nn.Module):# Coordinate Attention for Efficient Mobile Network DesignRecent studies on mobile network design have demonstrated the remarkable effectiveness of channel attention (e.g., the Squeeze-and-Excitation attention) for liftingmodel performance, but they generally neglect the positional information, which is important for generating spatially selective attention maps. In this paper, we propose anovel attention mechanism for mobile iscyy networks by embedding positional information into channel attention, whichwe call “coordinate attention”. Unlike channel attentionthat transforms a feature tensor to a single feature vector iscyy via 2D global pooling, the coordinate attention factorizes channel attention into two 1D feature encoding processes that aggregate features along the two spatial directions, respectivelydef __init__(self, inp, oup, reduction32):super(CA, self).__init__()mip max(8, inp // reduction)self.conv1 nn.Conv2d(inp, mip, kernel_size1, stride1, padding0)self.bn1 nn.BatchNorm2d(mip)self.act h_swish()self.conv_h nn.Conv2d(mip, oup, kernel_size1, stride1, padding0)self.conv_w nn.Conv2d(mip, oup, kernel_size1, stride1, padding0)def forward(self, x):identity xn,c,h,w x.size()pool_h nn.AdaptiveAvgPool2d((h, 1))pool_w nn.AdaptiveAvgPool2d((1, w))x_h pool_h(x)x_w pool_w(x).permute(0, 1, 3, 2)y torch.cat([x_h, x_w], dim2)y self.conv1(y)y self.bn1(y)y self.act(y) x_h, x_w torch.split(y, [h, w], dim2)x_w x_w.permute(0, 1, 3, 2)a_h self.conv_h(x_h).sigmoid()a_w self.conv_w(x_w).sigmoid()out identity * a_w * a_hreturn out 3.2在yolo.py中注册
找到parse.model模块 加入下列代码 elif m in [CA]:c1, c2 ch[f], args[0]if c2 ! no: # if not outputssc2 make_divisible(c2 * gw, 8)args [c1, c2, *args[1:]]3.3添加配置文件 # YOLOv5 , GPL-3.0 license# Parameters
nc: 80 # number of classes
depth_multiple: 0.33 # model depth iscyy multiple
width_multiple: 0.50 # layer channel iscyy multiple
anchors:- [10,13, 16,30, 33,23] # P3/8- [30,61, 62,45, 59,119] # P4/16- [116,90, 156,198, 373,326] # P5/32# YOLOv5 v6.0 backbone
backbone:# [from, number, module, args][[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2[-1, 1, Conv, [128, 3, 2]], # 1-P2/4[-1, 3, C3, [128]],[-1, 1, Conv, [256, 3, 2]], # 3-P3/8[-1, 6, C3, [256]],[-1, 1, Conv, [512, 3, 2]], # 5-P4/16[-1, 9, C3, [512]],[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32[-1, 3, C3, [1024]],[-1, 1, SPPF, [1024, 5]], # 9]# YOLOv5 v6.0 head
head:[[-1, 1, Conv, [512, 1, 1]],[-1, 1, nn.Upsample, [None, 2, nearest]],[[-1, 6], 1, Concat, [1]], # cat backbone P4[-1, 3, C3, [512, False]], # 13[-1, 1, Conv, [256, 1, 1]],[-1, 1, nn.Upsample, [None, 2, nearest]],[[-1, 4], 1, Concat, [1]], # cat backbone P3[-1, 3, C3, [256, False]], # 17 (P3/8-small)[-1, 1, Conv, [256, 3, 2]],[[-1, 14], 1, Concat, [1]], # cat head P4[-1, 3, C3, [512, False]], # 20 (P4/16-medium)[-1, 1, Conv, [512, 3, 2]],[[-1, 10], 1, Concat, [1]], # cat head P5[-1, 3, C3, [1024, False]], # 23 (P5/32-large)[-1, 1, CA, [1024]],[[17, 20, 24], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)]到此YOLOv5就改好了 4.yolov7改进
4.1 在common中加入以下代码 class h_sigmoid(nn.Module):def __init__(self, inplaceTrue):super(h_sigmoid, self).__init__()self.relu nn.ReLU6(inplaceinplace)def forward(self, x):return self.relu(x 3) / 6class h_swish(nn.Module):def __init__(self, inplaceTrue):super(h_swish, self).__init__()self.sigmoid h_sigmoid(inplaceinplace)def forward(self, x):return x * self.sigmoid(x)
class CA(nn.Module):# Coordinate Attention for Efficient Mobile Network DesignRecent studies on mobile network design have demonstrated the remarkable effectiveness of channel attention (e.g., the Squeeze-and-Excitation attention) for liftingmodel performance, but they generally neglect the positional information, which is important for generating spatially selective attention maps. In this paper, we propose anovel attention mechanism for mobile iscyy networks by embedding positional information into channel attention, whichwe call “coordinate attention”. Unlike channel attentionthat transforms a feature tensor to a single feature vector iscyy via 2D global pooling, the coordinate attention factorizes channel attention into two 1D feature encoding processes that aggregate features along the two spatial directions, respectivelydef __init__(self, inp, oup, reduction32):super(CA, self).__init__()mip max(8, inp // reduction)self.conv1 nn.Conv2d(inp, mip, kernel_size1, stride1, padding0)self.bn1 nn.BatchNorm2d(mip)self.act h_swish()self.conv_h nn.Conv2d(mip, oup, kernel_size1, stride1, padding0)self.conv_w nn.Conv2d(mip, oup, kernel_size1, stride1, padding0)def forward(self, x):identity xn,c,h,w x.size()pool_h nn.AdaptiveAvgPool2d((h, 1))pool_w nn.AdaptiveAvgPool2d((1, w))x_h pool_h(x)x_w pool_w(x).permute(0, 1, 3, 2)y torch.cat([x_h, x_w], dim2)y self.conv1(y)y self.bn1(y)y self.act(y) x_h, x_w torch.split(y, [h, w], dim2)x_w x_w.permute(0, 1, 3, 2)a_h self.conv_h(x_h).sigmoid()a_w self.conv_w(x_w).sigmoid()out identity * a_w * a_hreturn out 4.2在yolo.py中注册
找到parse.model模块 加入下列代码 elif m in [CA]:c1, c2 ch[f], args[0]if c2 ! no: # if not outputssc2 make_divisible(c2 * gw, 8)args [c1, c2, *args[1:]]4.3添加配置文件
# YOLOv7 , GPL-3.0 license
# parameters
nc: 80 # number of classes
depth_multiple: 1.0 # model depth multiple
width_multiple: 1.0 # layer channel iscyy multiple# anchors
anchors:- [12,16, 19,36, 40,28] # P3/8- [36,75, 76,55, 72,146] # P4/16- [142,110, 192,243, 459,401] # P5/32# yolov7 backbone
backbone:# [from, number, module, args][[-1, 1, Conv, [32, 3, 1]], # 0[-1, 1, Conv, [64, 3, 2]], # 1-P1/2[-1, 1, Conv, [64, 3, 1]],[-1, 1, Conv, [128, 3, 2]], # 3-P2/4 [-1, 1, C3, [128]], [-1, 1, Conv, [256, 3, 2]], [-1, 1, MP, []],[-1, 1, Conv, [128, 1, 1]],[-3, 1, Conv, [128, 1, 1]],[-1, 1, Conv, [128, 3, 2]],[[-1, -3], 1, Concat, [1]], # 16-P3/8[-1, 1, Conv, [128, 1, 1]],[-2, 1, Conv, [128, 1, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[-1, 1, Conv, [128, 3, 1]],[[-1, -3, -5, -6], 1, Concat, [1]],[-1, 1, Conv, [512, 1, 1]],[-1, 1, MP, []],[-1, 1, Conv, [256, 1, 1]],[-3, 1, Conv, [256, 1, 1]],[-1, 1, Conv, [256, 3, 2]],[[-1, -3], 1, Concat, [1]],[-1, 1, Conv, [256, 1, 1]],[-2, 1, Conv, [256, 1, 1]],[-1, 1, Conv, [256, 3, 1]],[-1, 1, Conv, [256, 3, 1]],[-1, 1, Conv, [256, 3, 1]],[-1, 1, Conv, [256, 3, 1]],[[-1, -3, -5, -6], 1, Concat, [1]],[-1, 1, Conv, [1024, 1, 1]], [-1, 1, MP, []],[-1, 1, Conv, [512, 1, 1]],[-3, 1, Conv, [512, 1, 1]],[-1, 1, Conv, [512, 3, 2]],[[-1, -3], 1, Concat, [1]],[-1, 1, C3, [1024]],[-1, 1, Conv, [256, 3, 1]],]# yolov7 head by iscyy
head:[[-1, 1, SPPCSPC, [512]],[-1, 1, Conv, [256, 1, 1]],[-1, 1, nn.Upsample, [None, 2, nearest]],[31, 1, Conv, [256, 1, 1]],[[-1, -2], 1, Concat, [1]],[-1, 1, C3, [128]],[-1, 1, Conv, [128, 1, 1]],[-1, 1, nn.Upsample, [None, 2, nearest]],[18, 1, Conv, [128, 1, 1]],[[-1, -2], 1, Concat, [1]],[-1, 1, C3, [128]],[-1, 1, MP, []],[-1, 1, Conv, [128, 1, 1]],[-3, 1, CA, [128]],[-1, 1, Conv, [128, 3, 2]],[[-1, -3, 44], 1, Concat, [1]],[-1, 1, C3, [256]], [-1, 1, MP, []],[-1, 1, Conv, [256, 1, 1]],[-3, 1, Conv, [256, 1, 1]],[-1, 1, Conv, [256, 3, 2]], [[-1, -3, 39], 1, Concat, [1]],[-1, 3, C3, [512]],# 检测头 -----------------------------[49, 1, RepConv, [256, 3, 1]],[55, 1, RepConv, [512, 3, 1]],[61, 1, RepConv, [1024, 3, 1]],[[62,63,64], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)]至此v7就配置完成了 v8的配置同v5是一样的。 CA不仅考虑到空间和通道之间的关系还考虑到长程依赖问题。通过实验发现CA不仅可以实现精度提升且参数量、计算量较少。
如果修改的过程中有遇到其他问题欢迎评论区留言大家一起学习进步。 文章转载自: http://www.morning.nlryq.cn.gov.cn.nlryq.cn http://www.morning.easiuse.com.gov.cn.easiuse.com http://www.morning.qtzwh.cn.gov.cn.qtzwh.cn http://www.morning.wxqmc.cn.gov.cn.wxqmc.cn http://www.morning.mrcpy.cn.gov.cn.mrcpy.cn http://www.morning.fqmbt.cn.gov.cn.fqmbt.cn http://www.morning.gywxq.cn.gov.cn.gywxq.cn http://www.morning.lltdf.cn.gov.cn.lltdf.cn http://www.morning.rnmc.cn.gov.cn.rnmc.cn http://www.morning.gbgdm.cn.gov.cn.gbgdm.cn http://www.morning.gassnw.com.gov.cn.gassnw.com http://www.morning.wlqbr.cn.gov.cn.wlqbr.cn http://www.morning.qcfgd.cn.gov.cn.qcfgd.cn http://www.morning.shprz.cn.gov.cn.shprz.cn http://www.morning.qxdrw.cn.gov.cn.qxdrw.cn http://www.morning.qtzk.cn.gov.cn.qtzk.cn http://www.morning.ctsjq.cn.gov.cn.ctsjq.cn http://www.morning.mcndn.cn.gov.cn.mcndn.cn http://www.morning.kfysh.com.gov.cn.kfysh.com http://www.morning.dwhnb.cn.gov.cn.dwhnb.cn http://www.morning.brsgw.cn.gov.cn.brsgw.cn http://www.morning.rkrcd.cn.gov.cn.rkrcd.cn http://www.morning.cmcjp.cn.gov.cn.cmcjp.cn http://www.morning.rydhq.cn.gov.cn.rydhq.cn http://www.morning.fgxr.cn.gov.cn.fgxr.cn http://www.morning.hrpbq.cn.gov.cn.hrpbq.cn http://www.morning.mygbt.cn.gov.cn.mygbt.cn http://www.morning.qqbw.cn.gov.cn.qqbw.cn http://www.morning.sgmgz.cn.gov.cn.sgmgz.cn http://www.morning.paxkhqq.cn.gov.cn.paxkhqq.cn http://www.morning.mpgfk.cn.gov.cn.mpgfk.cn http://www.morning.wdykx.cn.gov.cn.wdykx.cn http://www.morning.yppln.cn.gov.cn.yppln.cn http://www.morning.ylkkh.cn.gov.cn.ylkkh.cn http://www.morning.iknty.cn.gov.cn.iknty.cn http://www.morning.ahlart.com.gov.cn.ahlart.com http://www.morning.qqbw.cn.gov.cn.qqbw.cn http://www.morning.qpfmh.cn.gov.cn.qpfmh.cn http://www.morning.pwdgy.cn.gov.cn.pwdgy.cn http://www.morning.bzlfw.cn.gov.cn.bzlfw.cn http://www.morning.easiuse.com.gov.cn.easiuse.com http://www.morning.fktlr.cn.gov.cn.fktlr.cn http://www.morning.cpmfp.cn.gov.cn.cpmfp.cn http://www.morning.hflrz.cn.gov.cn.hflrz.cn http://www.morning.qyhcm.cn.gov.cn.qyhcm.cn http://www.morning.rrrrsr.com.gov.cn.rrrrsr.com http://www.morning.nzzws.cn.gov.cn.nzzws.cn http://www.morning.tbjb.cn.gov.cn.tbjb.cn http://www.morning.ypbdr.cn.gov.cn.ypbdr.cn http://www.morning.tllws.cn.gov.cn.tllws.cn http://www.morning.bmyrl.cn.gov.cn.bmyrl.cn http://www.morning.rjmg.cn.gov.cn.rjmg.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.cznsq.cn.gov.cn.cznsq.cn http://www.morning.cctgww.cn.gov.cn.cctgww.cn http://www.morning.rxnl.cn.gov.cn.rxnl.cn http://www.morning.gcspr.cn.gov.cn.gcspr.cn http://www.morning.gczzm.cn.gov.cn.gczzm.cn http://www.morning.xfjwm.cn.gov.cn.xfjwm.cn http://www.morning.jkcpl.cn.gov.cn.jkcpl.cn http://www.morning.mcjrf.cn.gov.cn.mcjrf.cn http://www.morning.sltfk.cn.gov.cn.sltfk.cn http://www.morning.mrxgm.cn.gov.cn.mrxgm.cn http://www.morning.jfxth.cn.gov.cn.jfxth.cn http://www.morning.kgkph.cn.gov.cn.kgkph.cn http://www.morning.lrskd.cn.gov.cn.lrskd.cn http://www.morning.lmhcy.cn.gov.cn.lmhcy.cn http://www.morning.qyllw.cn.gov.cn.qyllw.cn http://www.morning.zrks.cn.gov.cn.zrks.cn http://www.morning.lqrpk.cn.gov.cn.lqrpk.cn http://www.morning.ggtkk.cn.gov.cn.ggtkk.cn http://www.morning.gbljq.cn.gov.cn.gbljq.cn http://www.morning.rbzd.cn.gov.cn.rbzd.cn http://www.morning.yzxlkj.com.gov.cn.yzxlkj.com http://www.morning.rmdsd.cn.gov.cn.rmdsd.cn http://www.morning.zlnmm.cn.gov.cn.zlnmm.cn http://www.morning.fthcq.cn.gov.cn.fthcq.cn http://www.morning.ljsxg.cn.gov.cn.ljsxg.cn http://www.morning.glbnc.cn.gov.cn.glbnc.cn http://www.morning.bfmq.cn.gov.cn.bfmq.cn