小言_互联网的博客

目标检测算法——YOLOv5/YOLOv7改进之结合ASPP(空洞空间卷积池化金字塔)

364人阅读  评论(0)

>>>深度学习Tricks,第一时间送达<<<


目录

一、前沿介绍

1.空洞卷积(Atrous Convolution)

2.空洞空间卷积池化金字塔(Atrous Spatial Pyramid Pooling)

二、YOLOv5/YOLOv7改进之结合​​ASPP

1.配置common.py文件

2.配置yolo.py文件

3.配置yolov5/yolov7_​​ASPP.yaml文件

>>>一起交流!互相学习!共同进步!<<<


一、前沿介绍

首先要介绍Atrous Convolution(空洞卷积),它是一种增加感受野的方法。

1.空洞卷积(Atrous Convolution)

空洞卷积和普通的卷积操作不同的地方在于卷积核中按照一定的规律插入了一些(rate-1)为零的值,使得感受野增加,而无需通过减小图像大小来增加感受野。

2.空洞空间卷积池化金字塔(Atrous Spatial Pyramid Pooling)

空洞空间卷积池化金字塔(Atrous Spatial Pyramid Pooling,ASPP)对所给定的输入以不同采样率的空洞卷积并行采样,相当于以多个比例捕捉图像的上下文。

二、YOLOv5/YOLOv7改进之结合​​ASPP

共分三步走:

1.配置common.py文件


  
  1. #ASPP——————————————————————————————————————————————————————————————
  2. class ASPP(nn.Module):
  3. def __init__(self, in_channel=512, depth=256):
  4. super(ASPP,self).__init__()
  5. self.mean = nn.AdaptiveAvgPool2d((1, 1)) #(1,1)means ouput_dim
  6. self.conv = nn.Conv2d(in_channel, depth, 1, 1)
  7. self.atrous_block1 = nn.Conv2d(in_channel, depth, 1, 1)
  8. self.atrous_block6 = nn.Conv2d(in_channel, depth, 3, 1, padding=6, dilation=6)
  9. self.atrous_block12 = nn.Conv2d(in_channel, depth, 3, 1, padding=12, dilation=12)
  10. self.atrous_block18 = nn.Conv2d(in_channel, depth, 3, 1, padding=18, dilation=18)
  11. self.conv_1x1_output = nn.Conv2d(depth * 5, depth, 1, 1)
  12. def forward(self, x):
  13. size = x.shape[2:]
  14. image_features = self.mean(x)
  15. image_features = self.conv(image_features)
  16. image_features = F.upsample(image_features, size=size, mode='bilinear')
  17. atrous_block1 = self.atrous_block1(x)
  18. atrous_block6 = self.atrous_block6(x)
  19. atrous_block12 = self.atrous_block12(x)
  20. atrous_block18 = self.atrous_block18(x)
  21. net = self.conv_1x1_output(torch.cat([image_features, atrous_block1, atrous_block6,
  22. atrous_block12, atrous_block18], dim=1))
  23. return net

2.配置yolo.py文件

加入ASPP模块。

3.配置yolov5/yolov7_​​ASPP.yaml文件


  
  1. # anchors
  2. anchors:
  3. - [ 10, 13, 16, 30, 33, 23] # P3/ 8
  4. - [ 30, 61, 62, 45, 59, 119] # P4/ 16
  5. - [ 116, 90, 156, 198, 373, 326] # P5/ 32
  6. # YOLOv5 backbone
  7. backbone:
  8. # [from, number, module, args]
  9. [[-1, 1, Focus, [64, 3]], # 0-P1/ 2
  10. [ -1, 1, Conv, [ 128, 3, 2]], # 1-P2/ 4
  11. [ -1, 3, C3, [ 128]],
  12. [ -1, 1, Conv, [ 256, 3, 2]], # 3-P3/ 8
  13. [ -1, 9, C3, [ 256]],
  14. [ -1, 1, Conv, [ 512, 3, 2]], # 5-P4/ 16
  15. [ -1, 9, C3, [ 512]],
  16. [ -1, 1, Conv, [ 1024, 3, 2]], # 7-P5/ 32
  17. [ -1, 1, ASPP, [ 1024]],
  18. [ -1, 3, C3, [ 1024, False]], # 9
  19. ]
  20. # YOLOv5 head
  21. head:
  22. [[-1, 1, Conv, [512, 1, 1]],
  23. [ -1, 1, nn.Upsample, [None, 2, 'nearest']],
  24. [[-1, 6], 1, Concat, [1]], # cat backbone P4
  25. [ -1, 3, C3, [ 512, False]], # 13
  26. [ -1, 1, Conv, [ 256, 1, 1]],
  27. [ -1, 1, nn.Upsample, [None, 2, 'nearest']],
  28. [[-1, 4], 1, Concat, [1]], # cat backbone P3
  29. [ -1, 3, C3, [ 256, False]], # 17 (P3/ 8-small)
  30. [ -1, 1, Conv, [ 256, 3, 2]],
  31. [[-1, 14], 1, Concat, [1]], # cat head P4
  32. [ -1, 3, C3, [ 512, False]], # 20 (P4/ 16-medium)
  33. [ -1, 1, Conv, [ 512, 3, 2]],
  34. [[-1, 10], 1, Concat, [1]], # cat head P5
  35. [ -1, 3, C3, [ 1024, False]], # 23 (P5/ 32-large)
  36. [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
  37. ]

关于算法改进及论文投稿可关注并留言博主的CSDN/QQ

>>>一起交流!互相学习!共同进步!<<<


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