class

InstanceNorm1d

extends_InstanceNormBase
InstanceNorm1d(num_features: int, eps: float = 1e-05, momentum: float = 0.1, affine: bool = False, track_running_stats: bool = False, device: DeviceLike = None, dtype: DTypeLike = None)
source

Instance normalization for 3-D input (N, C, L).

Normalises each (n, c) slice over the length dimension LL independently:

yn,c=xn,cμn,cσn,c2+εγc+βcy_{n,c} = \frac{x_{n,c} - \mu_{n,c}} {\sqrt{\sigma_{n,c}^2 + \varepsilon}} \cdot \gamma_c + \beta_c

where μn,c\mu_{n,c} and σn,c2\sigma_{n,c}^2 are the mean and variance of the LL elements in sample nn, channel cc.

This is useful for 1-D temporal or sequential data where the statistics should not be mixed across samples or channels.

Parameters

num_featuresint
Number of channels CC.
epsfloat= 1e-05
Numerical stability constant. Default: 1e-5.
momentumfloat= 0.1
EMA factor used when track_running_stats=True. Default: 0.1.
affinebool= False
If True, learns per-channel scale and shift. Default: False.
track_running_statsbool= False
If True, maintains running mean/variance buffers. Default: False.
deviceDeviceLike= None
Device for parameters/buffers. Default: None.
dtypeDTypeLike= None
Data type for parameters/buffers. Default: None.

Attributes

weightParameter or None
Per-channel scale γ\gamma, shape (num_features,). None when affine=False.
biasParameter or None
Per-channel shift β\beta, shape (num_features,). None when affine=False.
running_meanTensor or None
Running mean per channel, shape (num_features,). None when track_running_stats=False.
running_varTensor or None
Running variance per channel, shape (num_features,). None when track_running_stats=False.

Notes

  • Input: (N,C,L)(N, C, L)
  • Output: (N,C,L)(N, C, L) — same shape.
  • With affine=True, the learned weight and bias can be replaced at inference time by externally supplied style tensors, which is the core mechanism behind adaptive instance normalization (AdaIN) used in style transfer.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> norm = nn.InstanceNorm1d(32)
>>> x = lucid.randn(8, 32, 100)   # (N, C, L)
>>> out = norm(x)
>>> out.shape
(8, 32, 100)
With learnable affine parameters:
>>> norm_affine = nn.InstanceNorm1d(32, affine=True)
>>> out2 = norm_affine(x)
>>> out2.shape
(8, 32, 100)