网络编程
位置:首页>> 网络编程>> Python编程>> pytorch forward两个参数实例

pytorch forward两个参数实例

作者:weixin_41950276  发布时间:2022-09-05 09:54:34 

标签:pytorch,forward,参数

以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

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com