将卷积运算放到初始化中,与模型初始化一块加载到cuda
原来代码:
class layer(nn.Module):
'''
x: input features with shape [N,C,H,W]
gamma, b: parameters of mapping function
'''
def __init__(self):
super(layer, self).__init__()
self.avg_pool = nn.AdaptiveAvgPool2d(1)
self.sigmoid = nn.Sigmoid()
def forward(self, x, gamma=2, b=1):
n,channel,h,w = x.size(<