defforward(self,x): # [N, C, 1, 1] out = self.gap(x) # [N, 1, C] out = out.squeeze(-1).permute(0,2,1) out = self.conv(out) out = out.transpose(1,2).unsqueeze(-1) # [N, C, 1, 1] out = self.act(out) return out * x
if __name__ == '__main__': x = torch.randn(2,64,32,32) N,C,H,W = x.shape model = ECANet(in_ch=C) print((model(x)).shape)
FAQ
卷积计算出现问题
RuntimeError: Given groups=1, weight of size [1, 1, 3, 3], expected input[1, 2, 1, 64] to have 1 channels, but got 2 channels instead