本文主要是介绍YOLOV5中加入CA注意力机制,助力涨点!,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先找到models文件夹中的common.py文件,加入如下模块
#########CA###############
class h_sigmoid(nn.Module):def __init__(self, inplace=True):super(h_sigmoid, self).__init__()self.relu = nn.ReLU6(inplace=inplace)def forward(self, x):return self.relu(x + 3) / 6class h_swish(nn.Module):def __init__(self, inplace=True):super(h_swish, self).__init__()self.sigmoid = h_sigmoid(inplace=inplace)def forward(self, x):return x * self.sigmoid(x)class CoordAtt(nn.Module):def __init__(self, inp, reduction=32):super(CoordAtt, self).__init__()self.pool_h = nn.AdaptiveAvgPool2d((None, 1))self.pool_w = nn.AdaptiveAvgPool2d((1, None))mip = max(8, inp // reduction)self.conv1 = nn.Conv2d(inp, mip, kernel_size=1, stride=1, padding=0)self.bn1 = nn.BatchNorm2d(mip)
这篇关于YOLOV5中加入CA注意力机制,助力涨点!的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!