当前位置:   article > 正文

YOLOv9独家原创改进|加入幽灵卷积Ghost Convolution模块,轻量化!_ghostconv

ghostconv


专栏介绍:YOLOv9改进系列 | 包含深度学习最新创新,主力高效涨点!!!


一、论文摘要

        由于内存和计算资源有限,在嵌入式设备上部署卷积神经网络是困难的。特征图中的冗余是那些成功的细胞神经网络的一个重要特征,但在神经结构设计中很少进行研究。本文提出了一种新的Ghost模块,通过少量的计算生成更多的特征图。基于一组内在特征图,我们以低廉的成本应用一系列线性变换来生成许多重影特征图,这些重影特征图可充分揭示内在特征背后的信息。所提出的Ghost模块可以作为即插即用组件来升级现有的卷积神经网络。Ghost瓶颈被设计为堆叠Ghost模块,然后可以轻松地建立轻量级GhostNet。

适用检测目标:   轻量化或移动端部署


二、Ghost Conv模块详解

《GhostNet: More Features from Cheap Operations》

        论文地址:  https://arxiv.org/abs/1911.11907

 2.1 模块简介

        Ghost Conv的主要思想:  通过一系列线性变换,以很小的计算量从原始特征发掘所需信息的“Ghost”特征图(Ghost feature maps)

 总结: 一种类似残差的模块

Ghost Conv模块的原理图


三、Ghost Conv模块使用教程

3.1 Ghost Conv模块的代码

  1. class GhostConv(nn.Module):
  2. """Ghost Convolution https://github.com/huawei-noah/ghostnet."""
  3. def __init__(self, c1, c2, k=1, s=1, g=1, act=True):
  4. """Initializes the GhostConv object with input channels, output channels, kernel size, stride, groups and
  5. activation.
  6. """
  7. super().__init__()
  8. c_ = c2 // 2 # hidden channels
  9. self.cv1 = Conv(c1, c_, k, s, None, g, act=act)
  10. self.cv2 = Conv(c_, c_, 5, 1, None, c_, act=act)
  11. def forward(self, x):
  12. """Forward propagation through a Ghost Bottleneck layer with skip connection."""
  13. y = self.cv1(x)
  14. return torch.cat((y, self.cv2(y)), 1)

3.2 在YOlO v9中的添加教程

阅读YOLOv9添加模块教程或使用下文操作

        1. 将YOLOv9工程中models下common.py文件中增加模块的代码。

         2. 将YOLOv9工程中models下yolo.py文件中的第718行(可能因版本变化而变化)增加以下代码。

            RepNCSPELAN4, SPPELAN, GhostConv}:

3.3 运行配置文件

  1. # YOLOv9
  2. # Powered bu https://blog.csdn.net/StopAndGoyyy
  3. # parameters
  4. nc: 80 # number of classes
  5. depth_multiple: 1 # model depth multiple
  6. width_multiple: 1 # layer channel multiple
  7. #activation: nn.LeakyReLU(0.1)
  8. #activation: nn.ReLU()
  9. # anchors
  10. anchors: 3
  11. # YOLOv9 backbone
  12. backbone:
  13. [
  14. [-1, 1, Silence, []],
  15. # conv down
  16. [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
  17. # conv down
  18. [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
  19. # elan-1 block
  20. [-1, 1, RepNCSPELAN4, [256, 128, 64, 1]], # 3
  21. # avg-conv down
  22. [-1, 1, ADown, [256]], # 4-P3/8
  23. # elan-2 block
  24. [-1, 1, RepNCSPELAN4, [512, 256, 128, 1]], # 5
  25. # avg-conv down
  26. [-1, 1, ADown, [512]], # 6-P4/16
  27. # elan-2 block
  28. [-1, 1, RepNCSPELAN4, [512, 512, 256, 1]], # 7
  29. # avg-conv down
  30. [-1, 1, ADown, [512]], # 8-P5/32
  31. # elan-2 block
  32. [-1, 1, RepNCSPELAN4, [512, 512, 256, 1]], # 9
  33. ]
  34. # YOLOv9 head
  35. head:
  36. [
  37. # elan-spp block
  38. [-1, 1, SPPELAN, [512, 256]], # 10
  39. # up-concat merge
  40. [-1, 1, nn.Upsample, [None, 2, 'nearest']],
  41. [[-1, 7], 1, Concat, [1]], # cat backbone P4
  42. # elan-2 block
  43. [-1, 1, RepNCSPELAN4, [512, 512, 256, 1]], # 13
  44. # up-concat merge
  45. [-1, 1, nn.Upsample, [None, 2, 'nearest']],
  46. [[-1, 5], 1, Concat, [1]], # cat backbone P3
  47. # elan-2 block
  48. [-1, 1, RepNCSPELAN4, [256, 256, 128, 1]], # 16 (P3/8-small)
  49. # avg-conv-down merge
  50. [-1, 1, ADown, [256]],
  51. [[-1, 13], 1, Concat, [1]], # cat head P4
  52. # elan-2 block
  53. [-1, 1, RepNCSPELAN4, [512, 512, 256, 1]], # 19 (P4/16-medium)
  54. # avg-conv-down merge
  55. [-1, 1, ADown, [512]],
  56. [[-1, 10], 1, Concat, [1]], # cat head P5
  57. # elan-2 block
  58. [-1, 1, RepNCSPELAN4, [512, 512, 256, 1]], # 22 (P5/32-large)
  59. # multi-level reversible auxiliary branch
  60. # routing
  61. [5, 1, CBLinear, [[256]]], # 23
  62. [7, 1, CBLinear, [[256, 512]]], # 24
  63. [9, 1, CBLinear, [[256, 512, 512]]], # 25
  64. # conv down
  65. [0, 1, Conv, [64, 3, 2]], # 26-P1/2
  66. # conv down
  67. [-1, 1, Conv, [128, 3, 2]], # 27-P2/4
  68. # elan-1 block
  69. [-1, 1, RepNCSPELAN4, [256, 128, 64, 1]], # 28
  70. # avg-conv down fuse
  71. [-1, 1, ADown, [256]], # 29-P3/8
  72. [[23, 24, 25, -1], 1, CBFuse, [[0, 0, 0]]], # 30
  73. # elan-2 block
  74. [-1, 1, RepNCSPELAN4, [512, 256, 128, 1]], # 31
  75. # avg-conv down fuse
  76. [-1, 1, ADown, [512]], # 32-P4/16
  77. [[24, 25, -1], 1, CBFuse, [[1, 1]]], # 33
  78. # elan-2 block
  79. [-1, 1, RepNCSPELAN4, [512, 512, 256, 1]], # 34
  80. # avg-conv down fuse
  81. [-1, 1, ADown, [512]], # 35-P5/32
  82. [[25, -1], 1, CBFuse, [[2]]], # 36
  83. # elan-2 block
  84. [-1, 1, RepNCSPELAN4, [512, 512, 256, 1]], # 37
  85. [-1, 1, GhostConv, [512, 3]], # 38
  86. # detection head
  87. # detect
  88. [[31, 34, 38, 16, 19, 22], 1, DualDDetect, [nc]], # DualDDetect(A3, A4, A5, P3, P4, P5)
  89. ]

3.4 训练过程


欢迎关注!


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/806767
推荐阅读
相关标签
  

闽ICP备14008679号