class
BatchNorm3d
extends
_BatchNormBaseBatchNorm3d(num_features: int, eps: float = 1e-05, momentum: float | None = 0.1, affine: bool = True, track_running_stats: bool = True, device: DeviceLike = None, dtype: DTypeLike = None)Batch normalization over a 5-D input (N, C, D, H, W).
Extends batch normalization to volumetric data by normalising each channel across the batch and all three spatial dimensions:
where and are computed over the axes for each channel .
The training/evaluation distinction is identical to
BatchNorm2d — running statistics are updated during training
and used as fixed normalisation constants during evaluation.
Parameters
num_featuresintNumber of channels .
epsfloat= 1e-05Small constant added to the variance for numerical stability.
Default:
1e-5.momentumfloat or None= 0.1EMA factor for the running statistics.
None selects
cumulative averaging. Default: 0.1.affinebool= TrueIf
True, learns per-channel and .
Default: True.track_running_statsbool= TrueIf
True, maintains running_mean, running_var,
and num_batches_tracked. Default: True.deviceDeviceLike= NoneDevice for parameters and buffers. Default:
None.dtypeDTypeLike= NoneData type for parameters and buffers. Default:
None.Attributes
weightParameter or NoneLearnable scale of shape
(num_features,).
None when affine=False.biasParameter or NoneLearnable shift of shape
(num_features,).
None when affine=False.running_meanTensor or NoneRunning per-channel mean, shape
(num_features,).
None when track_running_stats=False.running_varTensor or NoneRunning per-channel variance, shape
(num_features,).
None when track_running_stats=False.num_batches_trackedTensor or NoneScalar
int64 counting training batches seen.
None when track_running_stats=False.Notes
- Input:
- Output: — same shape.
- Typical applications include 3-D convolutional networks for video understanding, medical image segmentation (CT/MRI), and any domain where the data has a depth axis in addition to height and width.
- Because the reduction covers more elements
than in
BatchNorm2d, the variance estimate is generally more stable at the same batch size.
Examples
Normalizing activations from a 3-D convolution:
>>> import lucid
>>> import lucid.nn as nn
>>> bn3d = nn.BatchNorm3d(32)
>>> x = lucid.randn(4, 32, 16, 32, 32) # (N, C, D, H, W)
>>> out = bn3d(x)
>>> out.shape
(4, 32, 16, 32, 32)
Disable affine parameters for a parameter-free normaliser:
>>> bn_no_affine = nn.BatchNorm3d(32, affine=False)
>>> out2 = bn_no_affine(x)
>>> out2.shape
(4, 32, 16, 32, 32)