fn
instance_norm
→Tensorinstance_norm(x: Tensor, running_mean: Tensor | None = None, running_var: Tensor | None = None, weight: Tensor | None = None, bias: Tensor | None = None, use_input_stats: bool = True, momentum: float = 0.1, eps: float = 1e-05)Instance normalization (Ulyanov, Vedaldi & Lempitsky, 2016).
Normalises each (sample, channel) slice against its own
spatial mean and variance — i.e. statistics are reduced only over
the spatial axes. Originally introduced for fast neural style
transfer; widely used wherever per-image contrast should be made
invariant (image generation, image-to-image translation).
Parameters
xTensorInput of shape
(N, C, *spatial) with ndim >= 3.running_meanTensor or None= NoneRunning per-channel mean of shape
(C,). Only consulted
when use_input_stats=False.running_varTensor or None= NoneRunning per-channel variance of shape
(C,).weightTensor= NonePer-channel scale of shape
(C,).biasTensor= NonePer-channel shift of shape
(C,).use_input_statsbool= TrueWhen
True (default) statistics come from the current
instance. When False and running buffers are supplied,
those are used instead.momentumfloat= 0.1EMA coefficient for the running buffers (when externally
updated).
epsfloat= 1e-05Numerical safety added inside the square root.
Returns
TensorSame shape as x.
Notes
Math (reduction taken only over spatial axes ):
InstanceNorm equals group_norm with num_groups == C.
The lack of batch coupling also makes it the natural normaliser
when adapting per-sample statistics matters more than population
coherence — exactly the case in style transfer.
Examples
>>> import lucid
>>> from lucid.nn.functional import instance_norm
>>> x = lucid.randn(4, 3, 64, 64)
>>> y = instance_norm(x)
>>> y.shape
(4, 3, 64, 64)