(content_feat: torch.Tensor, style_feat: torch.Tensor)
| 32 | |
| 33 | |
| 34 | def _adain(content_feat: torch.Tensor, style_feat: torch.Tensor) -> torch.Tensor: |
| 35 | assert content_feat.shape[:2] == style_feat.shape[:2], "ADAIN: N、C 必须匹配" |
| 36 | size = content_feat.size() |
| 37 | style_mean, style_std = _calc_mean_std(style_feat) |
| 38 | content_mean, content_std = _calc_mean_std(content_feat) |
| 39 | normalized = (content_feat - content_mean.expand(size)) / content_std.expand(size) |
| 40 | return normalized * style_std.expand(size) + style_mean.expand(size) |
| 41 | |
| 42 | |
| 43 | # ----------------------------- |
no test coverage detected