| 106 | |
| 107 | #是一个Batch Normazliation |
| 108 | class AdaIN(torch.nn.Module): |
| 109 | def __init__(self,channel,w_dim): |
| 110 | super(AdaIN, self).__init__() |
| 111 | #https://blog.csdn.net/OneFlow_Official/article/details/123288435 |
| 112 | self.instance_norm = torch.nn.InstanceNorm2d(channel) |
| 113 | self.style_scale = WSLinear(w_dim,channel) |
| 114 | self.style_bias = WSLinear(w_dim,channel) |
| 115 | |
| 116 | def forward(self,x,w): |
| 117 | x = self.instance_norm(x) |
| 118 | #对dim = 2和dim = 3其进行升维 |
| 119 | style_scale = self.style_scale(w).unsqueeze(2).unsqueeze(3) |
| 120 | style_bias = self.style_bias(w).unsqueeze(2).unsqueeze(3) |
| 121 | return style_scale * x + style_bias |
| 122 | |
| 123 | |
| 124 | #对应着Synthesis network的每一个block |