| 16 | #Pixel norm沿着channel维度做归一化(axis=1),这样归一化的一个好处在于, |
| 17 | # feature map的每个位置都具有单位长度。 |
| 18 | class PixelNorm(torch.nn.Module): |
| 19 | def __init__(self): |
| 20 | super(PixelNorm, self).__init__() |
| 21 | self.epsilon = 1e-8 |
| 22 | def forward(self,x): |
| 23 | #keepdim:输出张量是否保留了dim |
| 24 | out = x / torch.sqrt(torch.mean(x**2,dim = 1,keepdim=True) + self.epsilon) |
| 25 | return out |
| 26 | |
| 27 | #紧跟PixelNorm之后的3 x 3卷积 |
| 28 | class WSConv2d(torch.nn.Module): |