(feat, eps=1e-5, chunk=1)
| 151 | |
| 152 | |
| 153 | def calc_mean_std(feat, eps=1e-5, chunk=1): |
| 154 | size = feat.size() |
| 155 | assert len(size) == 4 |
| 156 | if chunk == 2: |
| 157 | feat = torch.cat(feat.chunk(2), dim=3) |
| 158 | N, C = size[:2] |
| 159 | feat_var = feat.view(N // chunk, C, -1).var(dim=2) + eps |
| 160 | feat_std = feat_var.sqrt().view(N, C, 1, 1) |
| 161 | feat_mean = feat.view(N // chunk, C, -1).mean(dim=2).view(N // chunk, C, 1, 1) |
| 162 | return feat_mean.repeat(chunk, 1, 1, 1), feat_std.repeat(chunk, 1, 1, 1) |
| 163 | |
| 164 | |
| 165 | def adaptive_instance_normalization(content_feat, style_feat, chunk=1): |
no outgoing calls
no test coverage detected