小言_互联网的博客

YoloV5+DAMOYOLO:将DAMOYOLO中的GFPN结构与Yolov5结合

383人阅读  评论(0)

        前段时间写了一篇damoYolo的训练教程,同时也对自己的数据集进行了训练,虽然效果确实不是很好,但是damoyolo的一些思想和网络结构啥的还是可以借鉴使用的,此次将damoyolo的RepGFPN结构掏出来放到v5的NECK中,测试一下对本人的数据集(小目标)效果比v5要好,大概提升2个点左右。

        放一下damoyolo的github网址:

https://github.com/tinyvision/DAMO-YOLO

damoyolo的整体结构我们是无法看到的因为他的主干网络是nas_backbones 里面是txt文件,RepGFPN是可以看到的。


  
  1. import torch
  2. import torch.nn as nn
  3. from ..core.ops import ConvBNAct, CSPStage
  4. class GiraffeNeckV2(nn.Module):
  5. def __init__(
  6. self,
  7. depth=1.0,
  8. hidden_ratio=1.0,
  9. in_features=[2, 3, 4],
  10. in_channels=[256, 512, 1024],
  11. out_channels=[256, 512, 1024],
  12. act='silu',
  13. spp=False,
  14. block_name='BasicBlock',
  15. ):
  16. super().__init__()
  17. self.in_features = in_features
  18. self.in_channels = in_channels
  19. self.out_channels = out_channels
  20. Conv = ConvBNAct
  21. self.upsample = nn.Upsample(scale_factor= 2, mode= 'nearest')
  22. # node x3: input x0, x1
  23. self.bu_conv13 = Conv(in_channels[ 1], in_channels[ 1], 3, 2, act=act)
  24. self.merge_3 = CSPStage(block_name,
  25. in_channels[ 1] + in_channels[ 2],
  26. hidden_ratio,
  27. in_channels[ 2],
  28. round( 3 * depth),
  29. act=act,
  30. spp=spp)
  31. # node x4: input x1, x2, x3
  32. self.bu_conv24 = Conv(in_channels[ 0], in_channels[ 0], 3, 2, act=act)
  33. self.merge_4 = CSPStage(block_name,
  34. in_channels[ 0] + in_channels[ 1] +
  35. in_channels[ 2],
  36. hidden_ratio,
  37. in_channels[ 1],
  38. round( 3 * depth),
  39. act=act,
  40. spp=spp)
  41. # node x5: input x2, x4
  42. self.merge_5 = CSPStage(block_name,
  43. in_channels[ 1] + in_channels[ 0],
  44. hidden_ratio,
  45. out_channels[ 0],
  46. round( 3 * depth),
  47. act=act,
  48. spp=spp)
  49. # node x7: input x4, x5
  50. self.bu_conv57 = Conv(out_channels[ 0], out_channels[ 0], 3, 2, act=act)
  51. self.merge_7 = CSPStage(block_name,
  52. out_channels[ 0] + in_channels[ 1],
  53. hidden_ratio,
  54. out_channels[ 1],
  55. round( 3 * depth),
  56. act=act,
  57. spp=spp)
  58. # node x6: input x3, x4, x7
  59. self.bu_conv46 = Conv(in_channels[ 1], in_channels[ 1], 3, 2, act=act)
  60. self.bu_conv76 = Conv(out_channels[ 1], out_channels[ 1], 3, 2, act=act)
  61. self.merge_6 = CSPStage(block_name,
  62. in_channels[ 1] + out_channels[ 1] +
  63. in_channels[ 2],
  64. hidden_ratio,
  65. out_channels[ 2],
  66. round( 3 * depth),
  67. act=act,
  68. spp=spp)
  69. def init_weights( self):
  70. pass
  71. def forward( self, out_features):
  72. """
  73. Args:
  74. inputs: input images.
  75. Returns:
  76. Tuple[Tensor]: FPN feature.
  77. """
  78. # backbone
  79. [x2, x1, x0] = out_features
  80. # node x3
  81. x13 = self.bu_conv13(x1)
  82. x3 = torch.cat([x0, x13], 1)
  83. x3 = self.merge_3(x3)
  84. # node x4
  85. x34 = self.upsample(x3)
  86. x24 = self.bu_conv24(x2)
  87. x4 = torch.cat([x1, x24, x34], 1)
  88. x4 = self.merge_4(x4)
  89. # node x5
  90. x45 = self.upsample(x4)
  91. x5 = torch.cat([x2, x45], 1)
  92. x5 = self.merge_5(x5)
  93. # node x8
  94. # x8 = x5
  95. # node x7
  96. x57 = self.bu_conv57(x5)
  97. x7 = torch.cat([x4, x57], 1)
  98. x7 = self.merge_7(x7)
  99. # node x6
  100. x46 = self.bu_conv46(x4)
  101. x76 = self.bu_conv76(x7)
  102. x6 = torch.cat([x3, x46, x76], 1)
  103. x6 = self.merge_6(x6)
  104. outputs = (x5, x7, x6)
  105. return outputs

我根据ONNX结构图和上述代码画了简易的展示图:画的相对简单了,可能有些错误,后续我都没在看了,大家还是主要看代码吧

训练自己的数据集:

YoloV5+GFPN(我没用Rep)

yolov5:

map@0.5 相比之下提升了1.7个百分点。。。。还是阔以的

再看下参数量对比:(imgsize,map@50,mAP50-95,参数量(M),FLOPs)

 

 对比之下参数量和FLOPs确实有增加,这种的增加不大,还是可以接受的,但同时map也相应地增加了。具体的话看大家自己抉择了。


转载:https://blog.csdn.net/zhangdaoliang1/article/details/128558733
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场