更换YOLOv5激活函数

YOLOv5代码库中激活函数有很多,目前v6.1作者使用的是SiLU ,因为目前本人在水硕,导师要求发一篇核心,就想在YOLOv5上改改,试一试能不能增加性能,但是搜了一下发现好像这类博客比较少,所以打算自己写一下,也为了自己今后查的时候方便一些。

主要更改点在 models/common.py中

更换YOLOv5激活函数_第1张图片

先导入自己想更换的激活函数(我这里以MetaAconC为例,也就是说我想把SiLU更换为MetaAconC激活函数)

第二步:如图所示,更换SiLU即可。

更换YOLOv5激活函数_第2张图片

要是你想更换其他激活函数我这里把实例贴出来,选择你自己的想更换的激活函数,照着下面代码的改就可以了

# 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()) 

更换YOLOv5激活函数_第3张图片

 上面是原作者进行的各种激活函数的实验,供大家参考

欢迎大家交流

参考来自:https://github.com/ultralytics/yolov5/issues/3013

你可能感兴趣的:(深度学习,深度学习,机器学习,人工智能,目标检测)