towhee.trainer.callback.CallbackList¶
- class towhee.trainer.callback.CallbackList(callbacks: Optional[List[Callback]] = None)[source]¶
Bases:
object
CallbackList aggregate multiple Callback in the same object. Invoke the callbacks of CallbackList will invoke corresponding callback in each “Callback” in the FIFO sequential order.
- Parameters:
callbacks (List[towhee.trainer.callback.Callback]) – A list of callbacks which methods will be called simultaneously.
Example:
Methods
- param callback:
The callback need to be added.
Hook function invoked before every batch calculation.
Hook function invoked after every batch calculation.
Hook function invoked before each epoch.
Hook function invoked after each epoch.
Hook function invoked before every batch calculation in evaluate stage.
Hook function invoked after every batch calculation in evaluate stage.
Hook function invoked before evaluate stage.
Hook function invoked after evaluate stage.
Hook function invoked before train stage.
Hook function invoked before every batch calculation in train stage.
Hook function invoked before train stage.
Hook function invoked after train stage.
- param callback:
The callback need to be removed from callback list.
Set the model to callback.
Set the optimizer to callback.
Set the trainercontrol to callback.
- add_callback(callback: Callback, singleton: bool = True)[source]¶
- Parameters:
callback (towhee.trainer.callback.Callback) – The callback need to be added.
singleton (bool) – If set true, only one instance of same Callback will remain in callbacklist.
- on_batch_begin(batch: Tuple, logs: Dict) None [source]¶
Hook function invoked before every batch calculation.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_batch_end(batch: Tuple, logs: Dict) None [source]¶
Hook function invoked after every batch calculation.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_epoch_begin(epochs: int, logs: Dict) None [source]¶
Hook function invoked before each epoch.
- Parameters:
epochs (int) – Epoch index.
logs (Dict) – Kv store to save and load info.
- on_epoch_end(epochs: int, logs: Dict) None [source]¶
Hook function invoked after each epoch.
- Parameters:
epochs (int) – Epoch index.
logs (Dict) – Kv store to save and load info.
- on_eval_batch_begin(batch: Tuple, logs: Dict) None [source]¶
Hook function invoked before every batch calculation in evaluate stage.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_eval_batch_end(batch: Tuple, logs: Dict) None [source]¶
Hook function invoked after every batch calculation in evaluate stage.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_eval_begin(logs: Dict) None [source]¶
Hook function invoked before evaluate stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- on_eval_end(logs: Dict) None [source]¶
Hook function invoked after evaluate stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- on_train_batch_begin(batch: Tuple, logs: Dict) None [source]¶
Hook function invoked before train stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- on_train_batch_end(batch: Tuple, logs: Dict) None [source]¶
Hook function invoked before every batch calculation in train stage.
- Parameters:
batch (Tuple) – The data batch to calculate.
logs (Dict) – Kv store to save and load info.
- on_train_begin(logs: Dict) None [source]¶
Hook function invoked before train stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- on_train_end(logs: Dict) None [source]¶
Hook function invoked after train stage.
- Parameters:
logs (Dict) – Kv store to save and load info.
- pop_callback(callback: Callback)[source]¶
- Parameters:
callback (towhee.trainer.callback.Callback) – The callback need to be removed from callback list.
- set_model(model: Module)[source]¶
Set the model to callback.
- Parameters:
model (torch.nn.Module) – The model which callback can operate.
- set_optimizer(optimizer: Optimizer)[source]¶
Set the optimizer to callback.
- Parameters:
optimizer (torch.optim.Optimizer) – The optimizer which callback can operate.
- set_trainercontrol(trainercontrol: TrainerControl)[source]¶
Set the trainercontrol to callback.
- Parameters:
trainercontrol (towhee.trainer.callback.TrainerControl) – The trainercontrol which callback can operate.