赞
踩
class eca_block(nn.Module): def __init__(self, channel, gamma=2, b=1): super(eca_block, self).__init__() kernel_size = int(abs((math.log(channel, 2) + b) / gamma)) kernel_size = kernel_size if kernel_size % 2 else kernel_size + 1 # 控制根据输入的channel控制kernel_size 的大小,保证kernel_size是一个奇数 padding = kernel_size // 2 self.avg_pool = nn.AdaptiveAvgPool2d(1) self.conv = nn.Conv1d(1, 1, kernel_size, padding=padding, bias=False) self.sigmoid = nn.Sigmoid() def forward(self, x): b, c, h, w = x.size() avg = self.avg_pool(x).view([b, 1, c]) out = self.conv(avg) out = self.sigmoid(out).view([b, c, 1, 1]) return out * x
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。