首页 > 其他分享 >添加FReLU激活函数 在YOLOv7中修改

添加FReLU激活函数 在YOLOv7中修改

时间:2023-09-07 10:37:18浏览次数:40  
标签:YOLOv7 __ conv nn self 添加 act FReLU c1

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就可以了

标签:YOLOv7,__,conv,nn,self,添加,act,FReLU,c1
From: https://blog.51cto.com/u_16055951/7394642

相关文章

  • 在Windows中给鼠标右键添加菜单
    我们可以通过修改注册表来给鼠标右键添加菜单,添加的位置与修改注册表的位置有关系:空白处右键(或者桌面空白处):HKEY_CLASSES_ROOT/Directory/background/shell文件夹右键:HKEY_CLASSES_ROOT/Directory/shell文件上右键:HKEY_CLASSES_ROOT/*/shell1.win+r打开窗口,输入regedit......
  • Jquery向json对象添加键值对,读取键值对,删除键值对
    添加键值对varlabelName={};labelName["Name"]="James"labelName["Sex"]="1"结果:labelName={"Name":"James","Sex":1};读取键值对vargetData={"Label":"Dong","Sex"......
  • git 用一个project添加两个远程仓库
    以android的recovery项目为例,目前gitbranch-r中只有A仓库的分支 gitbranch-r m/dev->A/branch_nameA A/master这是因为manifest中的recovery项目配置为:<remotename="A"fetch="ssh://git@git.****.cn/A/"review="gerrit.pt.A.com"/><pro......
  • ota升级包编译过程中firmware如何添加进来
    整个分析过程中,机型名以xxxx为例主要可分为一firmware如何添加进target-files.zip二编译ota升级包时如何从target-files.zip取出firmware并添加到ota升级包三如何向升级脚本updater-script中加入控制firmware升级的语句四增量升级包相比全量包不同的步骤五结论及修复方......
  • 在gradle中添加,但是编译不通过
    compile'com.android.support:design:24.1.1'在gradle中添加,但是编译不通过,需要把compile改成buildgradlemoduledependencies{implementation'androidx.appcompat:appcompat:1.2.0'implementation'com.google.android.material:material:1.3.0&......
  • linux添加route
    临时添加:方法一:route命令添加:routeadd-net 192.168.168.0 netmask 255.255.255.0 gw 192.168.168.1deveth0route删除:routedel-host xxx gwxxx deveth0方法二:iproute添加:iproute add192.168.0.0/24 via下一跳 deveth0iproute删除:ip......
  • Vue3 setup 如何添加name
    Vue3setup如何添加name小满zs2022-11-2915:5810778 开启掘金成长之旅!这是我参与「掘金日新计划·12月更文挑战」的第2天,点击查看活动详情Vue3中name有什么用呢?1.在递归组件的时候需要定义name2.配合keep-aliveincludeexclude可以缓存组件3.在Vue有报错或......
  • 如何在海洋CMS系统中添加广告
    1:下载广告代码,注意广告中的图片要放在自己的server上,图片地址要改为自己的实际图片地址,图片存放位置,存在模板的image里面2在海洋cms后台添加广告管理只需要广告index.html代码,转换成js代码.广告名称和标识按照自己的实际需求写即可 后台->扩展->添加广告复制广告代码中的ht......
  • 如何在Nuxt 3中为<html>和<body>标签添加Tailwind CSS类?
    在Nuxt3中为<html>和<body>标签添加TailwindCSS类,可以参考以下步骤:安装TailwindCSS:在项目根目录下运行以下命令安装TailwindCSS和其依赖:npminstalltailwindcss@latest@tailwindcss/typography@latestpostcss@latestautoprefixer@latest创建TailwindCSS配置......
  • Django admin 添加操作记录
    1:引入日志模块fromsimple_history.adminimportSimpleHistoryAdmin2:admin类继承 SimpleHistoryAdmin 3:对应model添加字段历史记录字段history=HistoricalRecords(excluded_fields=['user','create_time','update_time'])......