r"""Spatially Adaptive Normalization (SPADE) forward. Args: x (N x C1 x H x W tensor) : Input tensor. cond_inputs (list of tensors) : Conditional maps for SPADE. Returns: output (4D tensor) : Output tensor.
(self, x, *cond_inputs, **_kwargs)
| 236 | self.conditional = True |
| 237 | |
| 238 | def forward(self, x, *cond_inputs, **_kwargs): |
| 239 | r"""Spatially Adaptive Normalization (SPADE) forward. |
| 240 | |
| 241 | Args: |
| 242 | x (N x C1 x H x W tensor) : Input tensor. |
| 243 | cond_inputs (list of tensors) : Conditional maps for SPADE. |
| 244 | Returns: |
| 245 | output (4D tensor) : Output tensor. |
| 246 | """ |
| 247 | output = self.norm(x) if self.norm is not None else x |
| 248 | for i in range(len(cond_inputs)): |
| 249 | if cond_inputs[i] is None: |
| 250 | continue |
| 251 | label_map = F.interpolate(cond_inputs[i], size=x.size()[2:], mode=self.interpolation) |
| 252 | if self.separate_projection: |
| 253 | hidden = self.mlps[i](label_map) |
| 254 | gamma = self.gammas[i](hidden) |
| 255 | beta = self.betas[i](hidden) |
| 256 | else: |
| 257 | affine_params = self.mlps[i](label_map) |
| 258 | gamma, beta = affine_params.chunk(2, dim=1) |
| 259 | if self.bias_only: |
| 260 | output = output + beta |
| 261 | else: |
| 262 | output = output * (1 + gamma) + beta |
| 263 | return output |
| 264 | |
| 265 | |
| 266 | class DualAdaptiveNorm(nn.Module): |