YOLOv5 改进激活函数(小白笔记)

#只需在 models文件夹下的common.py文件中操作

在common.py文件中导入activations.py 内的激活函数

有些激活函数不需要导入(按chrl后能跳转的),有些确需要,不知道为啥,希望来个大佬解惑

from utils.activations import MetaAconC  #导入激活函数

##在class Conv(nn.Module): class BottleneckCSP(nn.Module): 内更改
在这里插入图片描述
##github上的其他激活函数更改方式

 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 = nn.Identity() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = nn.Tanh() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = nn.Sigmoid() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = nn.ReLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = nn.LeakyReLU(0.1) if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = nn.Hardswish() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = nn.SiLU() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = Mish() if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = FReLU(c2) if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = AconC(c2) if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = MetaAconC(c2) if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = SiLU_beta(c2) if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         self.act = FReLU_noBN_biasFalse(c2) if act is True else (act if isinstance(act, nn.Module) else nn.Identity()) 
         # self.act = FReLU_noBN_biasTrue(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))) 
  

激活函数来源:

  • 3
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
yolov5算法中,对激活函数进行了改进和扩展,引入了很多新奇有趣的激活函数。其中一些改进激活函数包括ReLU的变体,如PReLU、RReLU、FReLU等。此外,还引入了Swish和Mish等激活函数。 Swish激活函数是一种将输入元素与sigmoid函数的输出相乘得到的结果,表达式为f(x) = x·sigmoid(βx)或简化为f(x) = x·σ(x),其中β是一个可调节的参数。Swish激活函数具有非线性特性,且在一些深度学习模型中表现出了良好的性能。 Mish激活函数是另一种基于sigmoid函数的变体,它的数学表示为f(x) = x·tanh(softplus(x))。Mish激活函数在一些目标检测任务中表现出了较好的性能,具有更好的平滑性和非线性特性。 此外,yolov5还引入了Acon系列和Dynamic ReLU系列等激活函数。Acon系列是一组基于自适应卷积操作的激活函数,具有局部感知性和自适应性。Dynamic ReLU系列是一组基于ReLU函数的变体,通过引入动态阈值来增加激活函数的非线性性能。 综上所述,yolov5算法通过引入多种改进激活函数,如PReLU、RReLU、FReLU、Swish、Mish、Acon系列和Dynamic ReLU系列等,来提升模型的表达能力和性能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [YOLOv5的Tricks | 【Trick1】关于激活函数Activation的改进汇总](https://blog.csdn.net/weixin_44751294/article/details/125085657)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值