class
InstanceNorm1d
extends
_InstanceNormBaseInstanceNorm1d(num_features: int, eps: float = 1e-05, momentum: float | None = 0.1, affine: bool = False, track_running_stats: bool = False, device: DeviceLike = None, dtype: DTypeLike = None, bias: bool = True)Instance normalization for 3-D input (N, C, L).
Normalises each (n, c) slice over the length dimension
independently:
where and are the mean and variance of the elements in sample , channel .
This is useful for 1-D temporal or sequential data where the statistics should not be mixed across samples or channels.
Parameters
num_ featuresintNumber of channels .
epsfloat= 1e-05Numerical stability constant. Default:
1e-5.momentumfloat or None= 0.1EMA factor for running stats;
None never updates them.affinebool= FalseIf
True, learns per-channel scale and shift. Default: False.track_ running_ statsbool= FalseIf
True, maintains running mean/variance buffers.
Default: False.deviceDeviceLike= NoneDevice for parameters/buffers. Default:
None.dtypeDTypeLike= NoneData type for parameters/buffers. Default:
None.Attributes
weightParameter or NonePer-channel scale , shape
(num_features,).
None when affine=False.biasParameter or NonePer-channel shift , shape
(num_features,).
None when affine=False.running_ meanTensor or NoneRunning mean per channel, shape
(num_features,).
None when track_running_stats=False.running_ varTensor or NoneRunning variance per channel, shape
(num_features,).
None when track_running_stats=False.Notes
- Input:
- Output: — same shape.
- With
affine=True, the learnedweightandbiascan 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)Used by 1
Instance methods
4Return a string representation of the layer's configuration.
Reset the running statistics, then weight to ones and bias to zeros.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> bn = nn.BatchNorm1d(2)
>>> _ = bn(lucid.randn(4, 2))
>>> bn.reset_parameters()
>>> bn.running_mean.tolist(), int(bn.num_batches_tracked.item())
([0.0, 0.0], 0)Put running_mean to zeros, running_var to ones and the count to zero.
In place, so anything holding a buffer sees the reset. Nothing to do
without track_running_stats, or on a lazy layer before its first
input.