| 297 | |
| 298 | |
| 299 | class 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 |
nothing calls this directly
no outgoing calls
no test coverage detected