class

LazyBatchNorm3d

extends_LazyBatchNormMixin
LazyBatchNorm3d(eps: float = 1e-05, momentum: float | None = 0.1, affine: bool = True, track_running_stats: bool = True, device: DeviceLike = None, dtype: DTypeLike = None)
source

BatchNorm3d with lazy num_features inference.

Identical to BatchNorm3d 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 or None= 0.1
EMA factor for running statistics. None uses cumulative averaging. Default: 0.1.
affinebool= True
If True, lazily allocates learnable scale and shift. Default: True.
track_running_statsbool= True
If True, lazily allocates running statistics buffers. Default: True.
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 BatchNorm3d. C is inferred on the first forward pass.
  • Output: same shape as the input.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> bn = nn.LazyBatchNorm3d()
>>> x = lucid.randn(2, 32, 8, 16, 16)   # (N, C, D, H, W)
>>> out = bn(x)    # num_features=32 inferred on first call
>>> out.shape
(2, 32, 8, 16, 16)
Useful for 3-D architectures (video, volumetric) where the feature
count is determined by a preceding layer of variable depth:
>>> bn_no_track = nn.LazyBatchNorm3d(track_running_stats=False)
>>> out2 = bn_no_track(x)
>>> out2.shape
(2, 32, 8, 16, 16)