class

LazyInstanceNorm3d

extends_LazyInstanceNormMixin
LazyInstanceNorm3d(eps: float = 1e-05, momentum: float = 0.1, affine: bool = False, track_running_stats: bool = False, device: DeviceLike = None, dtype: DTypeLike = None)
source

InstanceNorm3d with lazy num_features inference.

Identical to InstanceNorm3d except that num_features is inferred from x.shape[1] on the first forward pass.

Parameters

epsfloat= 1e-05
Numerical stability constant. Default: 1e-5.
momentumfloat= 0.1
EMA factor for optional running statistics. Default: 0.1.
affinebool= False
If True, lazily allocates per-channel scale and shift. Default: False.
track_running_statsbool= False
If True, lazily allocates running mean/variance buffers. Default: False.
deviceDeviceLike= None
Device for lazily allocated tensors. Default: None.
dtypeDTypeLike= None
Data type for lazily allocated tensors. Default: None.

Notes

  • Input: (N,C,D,H,W)(N, C, D, H, W) — same as InstanceNorm3d. C is inferred on the first forward pass.
  • Output: same shape as the input.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> norm = nn.LazyInstanceNorm3d()
>>> x = lucid.randn(1, 16, 8, 32, 32)   # (N, C, D, H, W)
>>> out = norm(x)   # num_features=16 inferred here
>>> out.shape
(1, 16, 8, 32, 32)
Useful for 3-D segmentation networks built with unknown channel
counts at construction time:
>>> norm_affine = nn.LazyInstanceNorm3d(affine=True)
>>> out2 = norm_affine(x)
>>> out2.shape
(1, 16, 8, 32, 32)