pub struct ModelEMACallback { /* private fields */ }Expand description
Model EMA (Exponential Moving Average) callback.
Maintains an exponential moving average of model parameters during training. This often leads to better generalization and more stable predictions.
The shadow parameters are updated as: shadow_param = decay * shadow_param + (1 - decay) * param
Reference: Common practice in modern deep learning, popularized by Mean Teacher and other semi-supervised learning methods.
Implementations§
Source§impl ModelEMACallback
impl ModelEMACallback
Sourcepub fn new(decay: f64, use_warmup: bool) -> Self
pub fn new(decay: f64, use_warmup: bool) -> Self
Create a new Model EMA callback.
§Arguments
decay- EMA decay rate (e.g., 0.999, 0.9999)use_warmup- Whether to use decay warmup (recommended)
Sourcepub fn initialize(&mut self, parameters: &HashMap<String, Array<f64, Ix2>>)
pub fn initialize(&mut self, parameters: &HashMap<String, Array<f64, Ix2>>)
Initialize shadow parameters from current model parameters.
Trait Implementations§
Source§impl Callback for ModelEMACallback
impl Callback for ModelEMACallback
Source§fn on_train_begin(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_train_begin(&mut self, _state: &TrainingState) -> TrainResult<()>
Called at the beginning of training.
Source§fn on_batch_end(
&mut self,
_batch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_batch_end( &mut self, _batch: usize, _state: &TrainingState, ) -> TrainResult<()>
Called at the end of a batch.
Source§fn on_train_end(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_train_end(&mut self, _state: &TrainingState) -> TrainResult<()>
Called at the end of training.
Source§fn on_epoch_begin(
&mut self,
_epoch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_epoch_begin( &mut self, _epoch: usize, _state: &TrainingState, ) -> TrainResult<()>
Called at the beginning of an epoch.
Source§fn on_epoch_end(
&mut self,
_epoch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_epoch_end( &mut self, _epoch: usize, _state: &TrainingState, ) -> TrainResult<()>
Called at the end of an epoch.
Source§fn on_batch_begin(
&mut self,
_batch: usize,
_state: &TrainingState,
) -> TrainResult<()>
fn on_batch_begin( &mut self, _batch: usize, _state: &TrainingState, ) -> TrainResult<()>
Called at the beginning of a batch.
Source§fn on_validation_end(&mut self, _state: &TrainingState) -> TrainResult<()>
fn on_validation_end(&mut self, _state: &TrainingState) -> TrainResult<()>
Called after validation.
Source§fn should_stop(&self) -> bool
fn should_stop(&self) -> bool
Check if training should stop early.
Auto Trait Implementations§
impl Freeze for ModelEMACallback
impl RefUnwindSafe for ModelEMACallback
impl Send for ModelEMACallback
impl Sync for ModelEMACallback
impl Unpin for ModelEMACallback
impl UnwindSafe for ModelEMACallback
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
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>
Converts
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>
Converts
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