发布时间:2024-09-28 11:01
实现代码如下
import torch
import torch.nn as nn
class SELayer(nn.Module):
def __init__(self, channel, reduction=16):
super(SELayer, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.fc = nn.Sequential(
nn.Linear(channel, channel // reduction, bias=False),
nn.ReLU(inplace=True),
nn.Linear(channel // reduction, channel, bias=False),
nn.Sigmoid()
)
def forward(self, x):
b, c, _, _ = x.size()
y = self.avg_pool(x).view(b, c)
y = self.fc(y).view(b, c, 1, 1)
return x * y.expand_as(x)
if __name__ == "__main__":
t = torch.ones((32, 128, 26, 26))
se = SELayer(channel=128, reduction=16)
out = se(t)
print(out.shape)
Element UI - v-infinite-scroll无限滚动组件
27.JavaScript的基础类型和对象一样有属性和方法,你知道这是如何实现的吗?
检测分割算法改进(篇三) ASPP(Atrous spatial pyramid pooling)模块
SpringBoot整合redis使用@Cacheable注解发生��乱码情况
什么是微软 Edge Tracking Prevention 的 Org Relationship Mitigation 策略
SpringCloud Alibaba微服务第10章之Gateway
木子-人生-写一写我自己吧!给所有正在努力准备成为的程序员和马上要成为程序员的我们