pub struct Trainer { /* private fields */ }Expand description
Main trainer for model training.
Implementations§
Source§impl Trainer
impl Trainer
Sourcepub fn new(
config: TrainerConfig,
loss_fn: Box<dyn Loss>,
optimizer: Box<dyn Optimizer>,
) -> Self
pub fn new( config: TrainerConfig, loss_fn: Box<dyn Loss>, optimizer: Box<dyn Optimizer>, ) -> Self
Create a new trainer.
Sourcepub fn with_scheduler(self, scheduler: Box<dyn LrScheduler>) -> Self
pub fn with_scheduler(self, scheduler: Box<dyn LrScheduler>) -> Self
Set learning rate scheduler.
Sourcepub fn with_callbacks(self, callbacks: CallbackList) -> Self
pub fn with_callbacks(self, callbacks: CallbackList) -> Self
Set callbacks.
Sourcepub fn with_metrics(self, metrics: MetricTracker) -> Self
pub fn with_metrics(self, metrics: MetricTracker) -> Self
Set metrics.
Sourcepub fn train(
&mut self,
train_data: &ArrayView<'_, f64, Ix2>,
train_targets: &ArrayView<'_, f64, Ix2>,
val_data: Option<&ArrayView<'_, f64, Ix2>>,
val_targets: Option<&ArrayView<'_, f64, Ix2>>,
parameters: &mut HashMap<String, Array<f64, Ix2>>,
) -> TrainResult<TrainingHistory>
pub fn train( &mut self, train_data: &ArrayView<'_, f64, Ix2>, train_targets: &ArrayView<'_, f64, Ix2>, val_data: Option<&ArrayView<'_, f64, Ix2>>, val_targets: Option<&ArrayView<'_, f64, Ix2>>, parameters: &mut HashMap<String, Array<f64, Ix2>>, ) -> TrainResult<TrainingHistory>
Train the model.
Sourcepub fn get_state(&self) -> &TrainingState
pub fn get_state(&self) -> &TrainingState
Get current training state.
Sourcepub fn save_checkpoint(
&self,
path: &PathBuf,
parameters: &HashMap<String, Array<f64, Ix2>>,
history: &TrainingHistory,
best_val_loss: Option<f64>,
) -> TrainResult<()>
pub fn save_checkpoint( &self, path: &PathBuf, parameters: &HashMap<String, Array<f64, Ix2>>, history: &TrainingHistory, best_val_loss: Option<f64>, ) -> TrainResult<()>
Save a complete training checkpoint.
This saves all state needed to resume training, including:
- Model parameters
- Optimizer state
- Scheduler state (if present)
- Training history
- Current epoch and losses
Sourcepub fn load_checkpoint(
&mut self,
path: &PathBuf,
) -> TrainResult<(HashMap<String, Array<f64, Ix2>>, TrainingHistory, usize)>
pub fn load_checkpoint( &mut self, path: &PathBuf, ) -> TrainResult<(HashMap<String, Array<f64, Ix2>>, TrainingHistory, usize)>
Resume training from a checkpoint.
This restores all training state including parameters, optimizer state, and history. Training will resume from the saved epoch.
Returns the restored parameters, history, and starting epoch.
Sourcepub fn train_from_checkpoint(
&mut self,
checkpoint_path: &PathBuf,
train_data: &ArrayView<'_, f64, Ix2>,
train_targets: &ArrayView<'_, f64, Ix2>,
val_data: Option<&ArrayView<'_, f64, Ix2>>,
val_targets: Option<&ArrayView<'_, f64, Ix2>>,
) -> TrainResult<(HashMap<String, Array<f64, Ix2>>, TrainingHistory)>
pub fn train_from_checkpoint( &mut self, checkpoint_path: &PathBuf, train_data: &ArrayView<'_, f64, Ix2>, train_targets: &ArrayView<'_, f64, Ix2>, val_data: Option<&ArrayView<'_, f64, Ix2>>, val_targets: Option<&ArrayView<'_, f64, Ix2>>, ) -> TrainResult<(HashMap<String, Array<f64, Ix2>>, TrainingHistory)>
Train the model starting from a checkpoint.
This is a convenience method that loads a checkpoint and continues training.
Auto Trait Implementations§
impl Freeze for Trainer
impl !RefUnwindSafe for Trainer
impl !Send for Trainer
impl !Sync for Trainer
impl Unpin for Trainer
impl !UnwindSafe for Trainer
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