MCPcopy
hub / github.com/NVlabs/imaginaire / forward

Method forward

imaginaire/layers/activation_norm.py:238–263  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
266class DualAdaptiveNorm(nn.Module):

Callers

nothing calls this directly

Calls 1

normMethod · 0.80

Tested by

no test coverage detected