YOLOv9中模块总结补充|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是一个具有残差结构的基础模块,如下图。

class RepConvN(nn.Module):
    """RepConv is a basic rep-style block, including training and deploy status
    This code is based on https://github.com/DingXiaoH/RepVGG/blob/main/repvgg.py
    """
    default_act = nn.SiLU()  # default activation

    def __init__(self, c1, c2, k=3, s=1, p=1, g=1, d=1, act=True, bn=False, deploy=False):
        super().__init__()
        assert k == 3 and p == 1
        self.g = g
        self.c1 = c1
        self.c2 = c2
        self.act = self.default_act if act is True else act if isinstance(act, nn.Module) else nn.Identity()

        self.bn = None
        self.conv1 = Conv(c1, c2, k, s, p=p, g=g, act=False)
        self.conv2 = Conv(c1, c2, 1, s, p=(p - k // 2), g=g, act=False)

    def forward(self, x):
        """Forward process"""
        id_out = 0 if self.bn is None else self.bn(x)
        return self.act(self.conv1(x) + self.conv2(x) + id_out)


class RepNBottleneck(nn.Module):
    # Standard bottleneck
    def __init__(self, c1, c2, shortcut=True, g=1, k=(3, 3), e=0.5):  # ch_in, ch_out, shortcut, kernels, groups, expand
        super().__init__()
        c_ = int(c2 * e)  # hidden channels
        self.cv1 = RepConvN(c1, c_, k[0], 1)
        self.cv2 = Conv(c_, c2, k[1], 1, g=g)
        self.add = shortcut and c1 == c2

    def forward(self, x):
        return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))



class RepNCSP(nn.Module):
    # CSP Bottleneck with 3 convolutions
    def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5):  # ch_in, ch_out, number, shortcut, groups, expansion
        super().__init__()
        c_ = int(c2 * e)  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c1, c_, 1, 1)
        self.cv3 = Conv(2 * c_, c2, 1)  # optional act=FReLU(c2)
        self.m = nn.Sequential(*(RepNBottleneck(c_, c_, shortcut, g, e=1.0) for _ in range(n)))

    def forward(self, x):
        return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), 1))



class RepNCSPELAN4(nn.Module):
    # csp-elan
    def __init__(self, c1, c2, c3, c4, c5=1):  # ch_in, ch_out, number, shortcut, groups, expansion
        super().__init__()
        self.c = c3//2
        self.cv1 = Conv(c1, c3, 1, 1)
        self.cv2 = nn.Sequential(RepNCSP(c3//2, c4, c5), Conv(c4, c4, 3, 1))
        self.cv3 = nn.Sequential(RepNCSP(c4, c4, c5), Conv(c4, c4, 3, 1))
        self.cv4 = Conv(c3+(2*c4), c2, 1, 1)

    def forward(self, x):
        y = list(self.cv1(x).chunk(2, 1))
        y.extend((m(y[-1])) for m in [self.cv2, self.cv3])
        return self.cv4(torch.cat(y, 1))

    def forward_split(self, x):
        y = list(self.cv1(x).split((self.c, self.c), 1))
        y.extend(m(y[-1]) for m in [self.cv2, self.cv3])
        return self.cv4(torch.cat(y, 1))

最近更新

  1. TCP协议是安全的吗?

    2024-05-10 00:12:07       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-10 00:12:07       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-10 00:12:07       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-10 00:12:07       20 阅读

热门阅读

  1. Scala基础学习-循环

    2024-05-10 00:12:07       9 阅读
  2. redis之集群

    2024-05-10 00:12:07       10 阅读
  3. 【QEMU系统分析之实例篇(十八)】

    2024-05-10 00:12:07       13 阅读
  4. vue 钩子函数updated什么时候触发

    2024-05-10 00:12:07       12 阅读
  5. 获取xml内容,使用dom4J

    2024-05-10 00:12:07       11 阅读
  6. 秋招后端开发面试题 - JVM类加载机制

    2024-05-10 00:12:07       9 阅读