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

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

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

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

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

##在class Conv(nn.Module): class BottleneckCSP(nn.Module): 内更改
YOLOv5 改进激活函数(小白笔记)_第1张图片
##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))) 
  

激活函数来源:

你可能感兴趣的:(python,人工智能,深度学习)