pub struct BatchNorm {
pub num_channels: usize,
pub eps: f64,
pub momentum: f64,
pub gamma: ArrayD<f64>,
pub beta: ArrayD<f64>,
pub affine: bool,
pub running_mean: ArrayD<f64>,
pub running_var: ArrayD<f64>,
pub training: bool,
pub num_batches_tracked: u64,
}Expand description
Batch Normalization: normalizes across the batch dimension.
Tracks running mean/variance for evaluation mode.
Input shape: [batch, channels, ...spatial_dims...]
Fields§
§num_channels: usizeNumber of channels (features).
eps: f64Small constant for numerical stability.
momentum: f64Momentum for running statistics update (EMA coefficient).
gamma: ArrayD<f64>Learnable scale parameter.
beta: ArrayD<f64>Learnable shift parameter.
affine: boolWhether to apply learnable affine transformation.
running_mean: ArrayD<f64>Running mean used during evaluation.
running_var: ArrayD<f64>Running variance used during evaluation.
training: boolWhether the module is in training mode.
num_batches_tracked: u64Number of mini-batches tracked.
Implementations§
Source§impl BatchNorm
impl BatchNorm
Sourcepub fn new(
num_channels: usize,
eps: f64,
momentum: f64,
affine: bool,
) -> Result<Self, NormalizationError>
pub fn new( num_channels: usize, eps: f64, momentum: f64, affine: bool, ) -> Result<Self, NormalizationError>
Create a new BatchNorm layer.
Sourcepub fn forward(
&mut self,
input: &ArrayD<f64>,
) -> Result<ArrayD<f64>, NormalizationError>
pub fn forward( &mut self, input: &ArrayD<f64>, ) -> Result<ArrayD<f64>, NormalizationError>
Forward pass: normalize across batch (and spatial) dimensions per channel.
In training mode: compute batch statistics and update running stats via EMA. In eval mode: use running statistics.
Sourcepub fn train_mode(&mut self)
pub fn train_mode(&mut self)
Switch to training mode (compute batch statistics).
Sourcepub fn is_training(&self) -> bool
pub fn is_training(&self) -> bool
Check whether the module is in training mode.
Sourcepub fn reset_running_stats(&mut self)
pub fn reset_running_stats(&mut self)
Reset running statistics to initial values.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BatchNorm
impl RefUnwindSafe for BatchNorm
impl Send for BatchNorm
impl Sync for BatchNorm
impl Unpin for BatchNorm
impl UnsafeUnpin for BatchNorm
impl UnwindSafe for BatchNorm
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more