python
class CBS(nn.Module):
""" Convolution -> BatchNorm -> SiLU """
def __init__(self, in_channels, out_channels, kernel_size, stride):
super(CBS, self).__init__()
self.layer = nn.Sequential(
nn.Conv2d(in_channels, out_channels, kernel_size, stride, padding=kernel_size // 2),
nn.BatchNorm2d(out_channels),
nn.SiLU()
)
def forward(self, x):
return self.layer(x)
class MP1(nn.Module):
""" MP1 block """
def __init__(self, in_channels):
super(MP1, self).__init__()
# Upper branch
self.maxpool = nn.MaxPool2d(kernel_size=2, stride=2)
self.cbs_upper = CBS(in_channels, in_channels // 2, 1, 1)
# Lower branch
self.cbs_lower1 = CBS(in_channels, in_channels // 2, 1, 1)
self.cbs_lower2 = CBS(in_channels // 2, in_channels // 2, 3, 2)
def forward(self, x):
# Upper branch
x_upper = self.maxpool(x)
x_upper = self.cbs_upper(x_upper)
# Lower branch
x_lower = self.cbs_lower1(x)
x_lower = self.cbs_lower2(x_lower)
# Concatenate
return torch.cat([x_upper, x_lower], dim=1)
class MP2(nn.Module):
""" MP2 block, similar to MP1 but with different output channels """
def __init__(self, in_channels):
super(MP2, self).__init__()
# Upper branch
self.maxpool = nn.MaxPool2d(kernel_size=2, stride=2)
self.cbs_upper = CBS(in_channels, in_channels, 1, 1)
# Lower branch
self.cbs_lower1 = CBS(in_channels, in_channels, 1, 1)
self.cbs_lower2 = CBS(in_channels, in_channels, 3, 2)
def forward(self, x):
# Upper branch
x_upper = self.maxpool(x)
x_upper = self.cbs_upper(x_upper)
# Lower branch
x_lower = self.cbs_lower1(x)
x_lower = self.cbs_lower2(x_lower)
# Concatenate
return torch.cat([x_upper, x_lower], dim=1)
class ChannelAttention(nn.Module):
""" Channel Attention Submodule for GAM """
def __init__(self, in_channels):
super(ChannelAttention, self).__init__()
self.mlp = nn.Sequential(
nn.Linear(in_channels, in_channels // 2),
nn.SiLU(),
nn.Linear(in_channels // 2, in_channels),
nn.Sigmoid()
)
def forward(self, x):
avg_pool = torch.mean(x, dim=[2, 3])
return self.mlp(avg_pool).unsqueeze(2).unsqueeze(3) * x
class SpatialAttention(nn.Module):
""" Spatial Attention Submodule for GAM """
def __init__(self, in_channels, out_channels):
super(SpatialAttention, self).__init__()
self.conv = nn.Sequential(
nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1),
nn.SiLU(),
nn.Conv2d(out_channels, 1, kernel_size=3, stride=1, padding=1),
nn.Sigmoid()
)
def forward(self, x):
return self.conv(x) * x
class GAM(nn.Module):
""" Global Attention Module (GAM) """
def __init__(self, in_channels):
super(GAM, self).__init__()
self.channel_attention = ChannelAttention(in_channels)
self.spatial_attention = SpatialAttention(in_channels, in_channels // 2)
def forward(self, x):
x = self.channel_attention(x)
x = self.spatial_attention(x)
return x
......
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rpm](https://img-home.csdnimg.cn/images/20210720083646.png)
![rpm](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![caj](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 11 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/d5b8e16cddf148da83293d5bb68d9224_admin_maxin.jpg!1)
博士僧小星
- 粉丝: 1946
- 资源: 5903
![benefits](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-1.c8e153b4.png)
下载权益
![privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-2.ec46750a.png)
C知道特权
![article](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-3.fc5e5fb6.png)
VIP文章
![course-privilege](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-4.320a6894.png)
课程特权
![rights](https://csdnimg.cn/release/downloadcmsfe/public/img/vip-rights-icon.fe0226a8.png)
开通VIP
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- 9364b7c93d9cd9d09c3bd5ceeaa0350b.JPG
- 代码审计工具Checkmarx安装环境和安装过程
- MiniBurp.7z
- 最新的Chrome版本
- eclipse哈哈哈哈哈
- vs 2019 c++20规范 S TL库中的 ratio duration<T,U> time-point<T,U>等
- Idea哈哈哈哈哈哈哈哈哈
- vs 2019 c++20 规范的头文件 <future> 源码注释和几个结论
- vs 2019 c++20规范 S TL 库中头文件 <atomic> 源码注释及探讨几个知识点
- c++20 规范, v s 2019 , 头文件 <m u t ex > ,注释以及几个探讨
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)