当前位置:   article > 正文

YOLOv9独家改进|使用HWD(小波下采样)模块改进ADown_haar 小波的下采样hwd

haar 小波的下采样hwd


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


一、改进点介绍

        HWD是一种下采样模型,应用了小波变换的方法。

        ADown是YOLOv9中的下采样模块,对不同的数据场景具有一定的可学习能力。


二、HWD-ADown模块详解

 2.1 模块简介

       HWD-ADown的主要思想:  使用HWD替换ADown中的Conv模块。


三、 HWD-ADown模块使用教程

3.1 HWD-ADown模块的代码

  1. try:
  2. from mmcv.cnn import build_activation_layer, build_norm_layer
  3. from mmcv.ops.modulated_deform_conv import ModulatedDeformConv2d
  4. from mmengine.model import constant_init, normal_init
  5. except ImportError as e:
  6. pass
  7. """
  8. 论文地址:https://arxiv.org/pdf/2208.03641v1.pdf
  9. """
  10. class HWD_ADown(nn.Module):
  11. def __init__(self, c1, c2): # ch_in, ch_out, shortcut, kernels, groups, expand
  12. super().__init__()
  13. self.c = c2 // 2
  14. # self.cv1 = Conv(c1 // 2, self.c, 3, 2, 1)
  15. self.cv1 = HWD(c1 // 2, self.c, 3, 1, 1)
  16. self.cv2 = Conv(c1 // 2, self.c, 1, 1, 0)
  17. def forward(self, x):
  18. x = nn.functional.avg_pool2d(x, 2, 1, 0, False, True)
  19. x1, x2 = x.chunk(2, 1)
  20. x1 = self.cv1(x1)
  21. x2 = torch.nn.functional.max_pool2d(x2, 3, 2, 1)
  22. x2 = self.cv2(x2)
  23. return torch.cat((x1, x2), 1)
  24. class HWD(nn.Module):
  25. def __init__(self, in_ch, out_ch, k, s, p):
  26. super(HWD, self).__init__()
  27. from pytorch_wavelets import DWTForward
  28. self.wt = DWTForward(J=1, mode='zero', wave='haar')
  29. self.conv = Conv(in_ch * 4, out_ch, k, s, p)
  30. def forward(self, x):
  31. yL, yH = self.wt(x)
  32. y_HL = yH[0][:, :, 0, ::]
  33. y_LH = yH[0][:, :, 1, ::]
  34. y_HH = yH[0][:, :, 2, ::]
  35. x = torch.cat([yL, y_HL, y_LH, y_HH], dim=1)
  36. x = self.conv(x)
  37. return x

3.2 在YOlO v9中的添加教程

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

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

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

            RepNCSPELAN4, SPPELAN, HWD_ADown}:

3.3 运行配置文件

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

3.4 训练过程


欢迎关注!


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

闽ICP备14008679号