pub struct BatchNorm { /* private fields */ }Expand description
Batch Normalization layer
Normalizes the input across the channel dimension for NHWC tensors.
Implementations§
Source§impl BatchNorm
impl BatchNorm
Sourcepub fn new(num_features: usize) -> Self
pub fn new(num_features: usize) -> Self
Create a new BatchNorm layer with default initialization
- gamma initialized to 1.0
- beta initialized to 0.0
- running_mean initialized to 0.0
- running_var initialized to 1.0
Sourcepub fn with_epsilon(num_features: usize, epsilon: f32) -> Self
pub fn with_epsilon(num_features: usize, epsilon: f32) -> Self
Create BatchNorm with custom epsilon
Sourcepub fn set_params(&mut self, gamma: Vec<f32>, beta: Vec<f32>) -> CnnResult<()>
pub fn set_params(&mut self, gamma: Vec<f32>, beta: Vec<f32>) -> CnnResult<()>
Set the learned parameters (gamma, beta)
Sourcepub fn set_running_stats(
&mut self,
mean: Vec<f32>,
var: Vec<f32>,
) -> CnnResult<()>
pub fn set_running_stats( &mut self, mean: Vec<f32>, var: Vec<f32>, ) -> CnnResult<()>
Set the running statistics (mean, var)
Sourcepub fn num_features(&self) -> usize
pub fn num_features(&self) -> usize
Get the number of features (channels)
Sourcepub fn running_mean(&self) -> &[f32]
pub fn running_mean(&self) -> &[f32]
Get a reference to running mean
Sourcepub fn running_var(&self) -> &[f32]
pub fn running_var(&self) -> &[f32]
Get a reference to running variance
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
Mutably borrows from an owned value. Read more