当前位置:   article > 正文

YOLOv9中模块总结补充|RepNCSPELAN4详图

repncspelan4


 专栏地址:目前售价售价69.9,改进点70+

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


1. RepNCSPELAN4详图

        RepNCSPELAN4是YOLOv9中的特征提取-融合模块,类似前几代YOLO中的C3、C2f等模块。作者通过结合两种神经网络架构,即带有梯度路径规划的 CSPNet 和 ELAN,考虑轻量化、推理速度和准确性设计出的一种广义高效层聚合网络(GELAN),作者使用带有 CSPNet 块的 GELAN 替换了 ELAN,并 RepConv作为计算块。RepNCSPELAN4可拆分为RepN-CSP-ELAN4 ,代码及模块图如下:

        RepNCSPELAN4主要由Conv与ReoNCSP组成,其中的ReoNCSP结构上形似C3与C2f模块,ReoNCSP由Conv与数量不等的RepNBottleneck模块组成,RepNBottleneck的个数由模型的宽度因子决定,RepNBottleneck是一个具有残差结构的基础模块,如下图。

  1. class RepConvN(nn.Module):
  2. """RepConv is a basic rep-style block, including training and deploy status
  3. This code is based on https://github.com/DingXiaoH/RepVGG/blob/main/repvgg.py
  4. """
  5. default_act = nn.SiLU() # default activation
  6. def __init__(self, c1, c2, k=3, s=1, p=1, g=1, d=1, act=True, bn=False, deploy=False):
  7. super().__init__()
  8. assert k == 3 and p == 1
  9. self.g = g
  10. self.c1 = c1
  11. self.c2 = c2
  12. self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()
  13. self.bn = None
  14. self.conv1 = Conv(c1, c2, k, s, p=p, g=g, act=False)
  15. self.conv2 = Conv(c1, c2, 1, s, p=(p - k // 2), g=g, act=False)
  16. def forward(self, x):
  17. """Forward process"""
  18. id_out = 0 if self.bn is None else self.bn(x)
  19. return self.act(self.conv1(x) + self.conv2(x) + id_out)
  20. class RepNBottleneck(nn.Module):
  21. # Standard bottleneck
  22. def __init__(self, c1, c2, shortcut=True, g=1, k=(3, 3), e=0.5): # ch_in, ch_out, shortcut, kernels, groups, expand
  23. super().__init__()
  24. c_ = int(c2 * e) # hidden channels
  25. self.cv1 = RepConvN(c1, c_, k[0], 1)
  26. self.cv2 = Conv(c_, c2, k[1], 1, g=g)
  27. self.add = shortcut and c1 == c2
  28. def forward(self, x):
  29. return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))
  30. class RepNCSP(nn.Module):
  31. # CSP Bottleneck with 3 convolutions
  32. def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5): # ch_in, ch_out, number, shortcut, groups, expansion
  33. super().__init__()
  34. c_ = int(c2 * e) # hidden channels
  35. self.cv1 = Conv(c1, c_, 1, 1)
  36. self.cv2 = Conv(c1, c_, 1, 1)
  37. self.cv3 = Conv(2 * c_, c2, 1) # optional act=FReLU(c2)
  38. self.m = nn.Sequential(*(RepNBottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)))
  39. def forward(self, x):
  40. return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), 1))
  41. class RepNCSPELAN4(nn.Module):
  42. # csp-elan
  43. def __init__(self, c1, c2, c3, c4, c5=1): # ch_in, ch_out, number, shortcut, groups, expansion
  44. super().__init__()
  45. self.c = c3//2
  46. self.cv1 = Conv(c1, c3, 1, 1)
  47. self.cv2 = nn.Sequential(RepNCSP(c3//2, c4, c5), Conv(c4, c4, 3, 1))
  48. self.cv3 = nn.Sequential(RepNCSP(c4, c4, c5), Conv(c4, c4, 3, 1))
  49. self.cv4 = Conv(c3+(2*c4), c2, 1, 1)
  50. def forward(self, x):
  51. y = list(self.cv1(x).chunk(2, 1))
  52. y.extend((m(y[-1])) for m in [self.cv2, self.cv3])
  53. return self.cv4(torch.cat(y, 1))
  54. def forward_split(self, x):
  55. y = list(self.cv1(x).split((self.c, self.c), 1))
  56. y.extend(m(y[-1]) for m in [self.cv2, self.cv3])
  57. return self.cv4(torch.cat(y, 1))

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

闽ICP备14008679号