ITrainingCallback<T>
Interfaces · AiDotNet.Interfaces
A user-registerable hook that observes supervised training epoch-by-epoch and can request that training stop early.
Known implementations: HealthMonitorCallback<T>
For Beginners
This is your “listen in on training” hook. Implement it (or
use the one-line Func overload of ConfigureTrainingCallback) to:
- print or plot the loss after each epoch,
- stream progress to a UI,
- or pull the plug early — return
falsefromOnEpochEndand the
trainer stops cleanly at that epoch and returns the model trained so far. The framework calls these methods for you; you never call them yourself.
How It Works
Register callbacks on the facade via
AiModelBuilder.ConfigureTrainingCallback(...). The training loop invokes
OnTrainBegin once before the first epoch, OnEpochEnd after
every completed epoch, and OnTrainEnd once after training finishes
(whether it ran to completion or was aborted). Multiple callbacks may be registered;
they are all invoked, and training aborts if any of them returns
false from OnEpochEnd.
Threading: callbacks are invoked synchronously from the training loop on the training thread. Keep the work light; offload anything heavy (network, disk) so you do not stall training.
Methods
| Method | Summary |
|---|---|
bool OnEpochEnd(TrainingProgress<T> progress) |
Called after each epoch completes. |
void OnTrainBegin(TrainingProgress<T> progress) |
Called once, just before the first epoch runs. |
void OnTrainEnd(TrainingProgress<T> progress) |
Called once, after training finishes — whether it completed all epochs or was aborted. |