pub struct SWACallback { /* private fields */ }Expand description
SWA (Stochastic Weight Averaging) callback.
Averages model parameters over the course of training, typically starting from a later epoch. This often leads to better generalization and wider optima.
Reference: Izmailov et al. “Averaging Weights Leads to Wider Optima and Better Generalization” (UAI 2018)
Implementations§
Source§impl SWACallback
impl SWACallback
Sourcepub fn new(start_epoch: usize, update_frequency: usize, verbose: bool) -> Self
pub fn new(start_epoch: usize, update_frequency: usize, verbose: bool) -> Self
Create a new SWA callback.
§Arguments
start_epoch- Epoch to start averaging (e.g., 0.75 * total_epochs)update_frequency- Average parameters every N epochs (typically 1)verbose- Whether to print progress
Sourcepub fn update_average(
&mut self,
parameters: &HashMap<String, Array<f64, Ix2>>,
) -> TrainResult<()>
pub fn update_average( &mut self, parameters: &HashMap<String, Array<f64, Ix2>>, ) -> TrainResult<()>
Update SWA parameters with current model parameters.
Trait Implementations§
Source§impl Callback for SWACallback
impl Callback for SWACallback
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_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_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_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_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_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_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 SWACallback
impl RefUnwindSafe for SWACallback
impl Send for SWACallback
impl Sync for SWACallback
impl Unpin for SWACallback
impl UnwindSafe for SWACallback
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