yolov7 添加FReLU激活函数

1.找到yolov7的utils中的activation.py,在最后面输入以下代码

# 原理:对局部卷积后的输出与原始数据进行一个max的比对
class FReLU(nn.Module):
    def __init__(self, c1, k=3):  # ch_in, kernel
        super().__init__()
        # 可分离卷积,不改变hw与channels
        self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1, bias=False)  
        self.bn = nn.BatchNorm2d(c1)

    def forward(self, x):
        # 卷积处理后的特征图与原来的x是相同的shape的
        return torch.max(x, self.bn(self.conv(x)))   

2.在modules中的common.py中将Conv模块改为以下代码

class Conv(nn.Module):
    # Standard convolution
    def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):  # ch_in, ch_out, kernel, stride, padding, groups
        super(Conv, self).__init__()
        self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g, bias=False)
        self.bn = nn.BatchNorm2d(c2)
        self.act = FReLU(c2) if act is True else (act if isinstance(act, nn.Module) else nn.Identity())

    def forward(self, x):
        return self.act(self.bn(self.conv(x)))

    def fuseforward(self, x):
        return self.act(self.conv(x))

3.把原来的Conv模块注释掉

 4.再train就可以了

  • 2
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值