| 125 | return torch.tanh(alpha * generated + (1 - alpha) * upscaled) |
| 126 | |
| 127 | def forward(self, x, alpha, steps): |
| 128 | out = self.initial(x) |
| 129 | |
| 130 | if steps == 0: |
| 131 | return self.initial_rgb(out) |
| 132 | |
| 133 | upscaled = 0 |
| 134 | |
| 135 | for step in range(steps): |
| 136 | #每一个convblock之后进行上采样 |
| 137 | upscaled = F.interpolate(out, scale_factor=2, mode="nearest") |
| 138 | #进入下一个convblock |
| 139 | out = self.prog_blocks[step](upscaled) |
| 140 | |
| 141 | """ |
| 142 | # The number of channels in upscale will stay the same, while |
| 143 | # out which has moved through prog_blocks might change. To ensure |
| 144 | # we can convert both to rgb we use different rgb_layers |
| 145 | # (steps-1) and steps for upscaled, out respectively |
| 146 | """ |
| 147 | final_upscaled = self.rgb_layers[steps - 1](upscaled) |
| 148 | final_out = self.rgb_layers[steps](out) |
| 149 | return self.fade_in(alpha, final_upscaled, final_out) |
| 150 | |
| 151 | """ |
| 152 | 判别器通道数从:[4 -> 8 ->] 16 -> 32 -> 64 -> 128 -> 256 -> 512 -> 512 -> 512 -> 512 |