MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / AdaGN

Class AdaGN

k_diffusion/layers.py:299–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

297
298
299class AdaGN(ConditionedModule):
300 def __init__(self, feats_in, c_out, num_groups, eps=1e-5, cond_key='cond'):
301 super().__init__()
302 self.num_groups = num_groups
303 self.eps = eps
304 self.cond_key = cond_key
305 self.mapper = nn.Linear(feats_in, c_out * 2)
306 nn.init.zeros_(self.mapper.weight)
307 nn.init.zeros_(self.mapper.bias)
308
309 def forward(self, input, cond):
310 weight, bias = self.mapper(cond[self.cond_key]).chunk(2, dim=-1)
311 input = F.group_norm(input, self.num_groups, eps=self.eps)
312 return torch.addcmul(utils.append_dims(bias, input.ndim), input, utils.append_dims(weight, input.ndim) + 1)
313
314
315# Attention

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected