pytorch forward两个参数实例
作者:weixin_41950276 时间:2022-09-05 09:54:34
以channel Attention Block为例子
class CAB(nn.Module):
def __init__(self, in_channels, out_channels):
super(CAB, self).__init__()
self.global_pooling = nn.AdaptiveAvgPool2d(output_size=1)
self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=1, stride=1, padding=0)
self.relu = nn.ReLU()
self.conv2 = nn.Conv2d(out_channels, out_channels, kernel_size=1, stride=1, padding=0)
self.sigmod = nn.Sigmoid()
def forward(self, x):
x1, x2 = x # high, low
x = torch.cat([x1,x2],dim=1)
x = self.global_pooling(x)
x = self.conv1(x)
x = self.relu(x)
x = self.conv2(x)
x = self.sigmod(x)
x2 = x * x2
res = x2 + x1
return res
来源:https://blog.csdn.net/weixin_41950276/article/details/89069659
标签:pytorch,forward,参数
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
django filters实现数据过滤的示例代码
2023-11-20 03:59:22
python实现按关键字筛选日志文件
2022-12-28 21:45:49
设计之外随谈
2009-06-16 14:38:00
![](https://img.aspxhome.com/file/UploadPic/20096/16/anddy_xiantan-64s.jpg)
PHP中phar包的使用教程
2023-11-09 19:55:52
ServerXMLHTTP的超时设置(setTimeouts)参数含义
2009-02-12 12:51:00
Python爬虫信息输入及页面的切换方法
2023-08-02 17:33:33
基于Python实现自制拼图小游戏
2021-12-01 03:25:01
![](https://img.aspxhome.com/file/2023/9/92099_0s.gif)
python右对齐的实例方法
2022-01-15 20:59:52
Python常见异常的处理方式浅析
2022-05-14 17:32:37
基于Django框架的权限组件rbac实例讲解
2022-09-27 17:11:51
![](https://img.aspxhome.com/file/2023/2/72032_0s.jpg)
MySQL Create Database 创建数据库
2011-09-10 16:04:51
修改Linux下MySQL 5.0的默认连接数
2009-09-01 10:16:00
Python 文件处理之open()函数
2021-03-04 02:26:49
python儿童学游戏编程知识点总结
2022-10-23 04:32:42
django-rest-framework 自定义swagger过程详解
2023-01-01 22:05:34
![](https://img.aspxhome.com/file/2023/4/72214_0s.png)
Python BeautifulSoup中文乱码问题的2种解决方法
2023-05-09 13:42:17
asp如何实现网络打印?
2010-05-24 18:31:00
利用sql函数生成不重复的订单号的代码
2012-01-05 19:02:55
用python实现k近邻算法的示例代码
2022-08-28 16:08:58
python+opencv实现动态物体识别
2023-10-31 01:15:00
![](https://img.aspxhome.com/file/2023/1/97071_0s.jpg)