MCPcopy Create free account
hub / github.com/IceClear/StableSR / adaptive_instance_normalization

Function adaptive_instance_normalization

ldm/modules/diffusionmodules/model.py:36–48  ·  view source on GitHub ↗

Adaptive instance normalization. Adjust the reference features to have the similar color and illuminations as those in the degradate features. Args: content_feat (Tensor): The reference feature. style_feat (Tensor): The degradate features.

(content_feat, style_feat)

Source from the content-addressed store, hash-verified

34 return feat_mean, feat_std
35
36def adaptive_instance_normalization(content_feat, style_feat):
37 """Adaptive instance normalization.
38 Adjust the reference features to have the similar color and illuminations
39 as those in the degradate features.
40 Args:
41 content_feat (Tensor): The reference feature.
42 style_feat (Tensor): The degradate features.
43 """
44 size = content_feat.size()
45 style_mean, style_std = calc_mean_std(style_feat)
46 content_mean, content_std = calc_mean_std(content_feat)
47 normalized_feat = (content_feat - content_mean.expand(size)) / content_std.expand(size)
48 return normalized_feat * style_std.expand(size) + style_mean.expand(size)
49
50def get_timestep_embedding(timesteps, embedding_dim):
51 """

Callers

nothing calls this directly

Calls 1

calc_mean_stdFunction · 0.70

Tested by

no test coverage detected