paddlets.models.common.callbacks.callbacks
- class Callback[source]
Bases:
objectAbstract base class used to build new callbacks.
- _trainer
A model instance.
- Type
- set_trainer(model: PaddleBaseModel)[source]
Set model instance.
- Parameters
model (PaddleBaseModel) – A model instance.
- on_epoch_begin(epoch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the beginning of each epoch.
- Parameters
epoch (int) – The index of epoch.
logs (Dict[str, Any]|None) – The logs is a dict or None.
- on_epoch_end(epoch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the end of each epoch.
- Parameters
epoch (int) – The index of epoch.
logs (Dict[str, Any]|None) – The logs is a dict or None. contains loss and metrics.
- on_batch_begin(batch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the beginning of each batch in training.
- Parameters
batch (int) – The index of batch.
logs (Dict[str, Any]|None) – The logs is a dict or None.
- on_batch_end(batch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the end of each batch in training.
- Parameters
batch (int) – The index of batch.
logs (Dict[str, Any]|None) – The logs is a dict or None. contains loss and batch_size.
- class CallbackContainer(callbacks: List[Callback])[source]
Bases:
objectContainer holding a list of callbacks.
- Parameters
callbacks (List[Callback]) – List of callbacks.
- append(callback: Callback)[source]
Append callback to the container.
- Parameters
callback (Callback) – Callback instance.
- set_trainer(model: PaddleBaseModel)[source]
Set model instance.
- Parameters
model (PaddleBaseModel) – A model instance.
- on_epoch_begin(epoch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the beginning of each epoch.
- Parameters
epoch (int) – The index of epoch.
logs (Dict[str, Any]|None) – The logs is a dict or None.
- on_epoch_end(epoch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the end of each epoch.
- Parameters
epoch (int) – The index of epoch.
logs (Dict[str, Any]|None) – The logs is a dict or None. contains loss and metrics.
- on_batch_begin(batch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the beginning of each batch in training.
- Parameters
batch (int) – The index of batch.
logs (Dict[str, Any]|None) – The logs is a dict or None.
- on_batch_end(batch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the end of each batch in training.
- Parameters
batch (int) – The index of batch.
logs (Dict[str, Any]|None) – The logs is a dict or None. contains loss and batch_size.
- class EarlyStopping(early_stopping_metric: str, is_maximize: bool, tol: float = 0.0, patience: int = 1)[source]
Bases:
CallbackEarlyStopping callback, allow the trainer to exit the training loop if the given metric stopped improving during evaluation.
- Parameters
early_stopping_metric (str) – Early stopping metric name.
is_maximize (bool) – Whether to maximize or not early_stopping_metric.
tol (float) – Minimum change in monitored value to qualify as improvement. This number should be positive.
patience (int) – Number of epochs to wait for improvement before terminating. the counter be reset after each improvement
- _early_stopping_metric
Early stopping metric name.
- Type
str
- _is_maximize
Whether to maximize or not early_stopping_metric.
- Type
bool
- _tol
Minimum change in monitored value to qualify as improvement.
- Type
float
- _patience
Number of epochs to wait for improvement before terminating.
- Type
int
- _best_epoch
Best epoch.
- Type
int
- _stopped_epoch
Stopped epoch.
- Type
int
- _best_loss
Best loss.
- Type
float
- _wait
Number of times that the early_stopping_metric failed to improve.
- Type
int
- class History(verbose: int = 1)[source]
Bases:
CallbackCallback that records events into a History object.
- Parameters
verbose (int) – Print results every verbose iteration.
- _verbose
Print results every verbose iteration.
- Type
int
- _history
Record all information of metrics of each epoch.
- Type
Dict[str, Any]
- _start_time
Start time of training.
- Type
float
- _epoch_loss
Average loss per epoch.
- Type
float
- _epoch_metrics
Record all information of metrics of each epoch.
- Type
Dict[str, Any]
- _samples_seen
Traversed samples.
- Type
int
- on_train_begin(logs: Optional[Dict[str, Any]] = None)[source]
Called at the start of training.
- Parameters
logs (Dict[str, Any]|None) – The logs is a dict or None.
- on_epoch_begin(epoch: int, logs: Optional[Dict[str, Any]] = None)[source]
Called at the beginning of each epoch.
- Parameters
epoch (int) – The index of epoch.
logs (Dict[str, Any]|None) – The logs is a dict or None.