local_model_save
- class aitoolbox.experiment.local_save.local_model_save.AbstractLocalModelSaver[source]
Bases:
ABC
- abstract save_model(model, project_name, experiment_name, experiment_timestamp=None, epoch=None, iteration_idx=None, protect_existing_folder=True)[source]
Model saving method which all the model savers have to implement to give an expected API to other components
- Parameters:
model (keras.Model or dict) – model representation. If used with PyTorch it is a simple dict under the hood. In the case of Keras training this would be the keras Model.
project_name (str) – root name of the project
experiment_name (str) – name of the particular experiment
experiment_timestamp (str or None) – time stamp at the start of training
epoch (int or None) – in which epoch the model is being saved
iteration_idx (int or None) – at which training iteration the model is being saved
protect_existing_folder (bool) – can override potentially already existing folder or not
- Returns:
model_name, model_local_path
- Return type:
- class aitoolbox.experiment.local_save.local_model_save.BaseLocalModelSaver(local_model_result_folder_path='~/project/model_result', checkpoint_model=False)[source]
Bases:
object
Base functionality for all the local model savers
- Parameters:
- class aitoolbox.experiment.local_save.local_model_save.PyTorchLocalModelSaver(local_model_result_folder_path='~/project/model_result', checkpoint_model=False)[source]
Bases:
AbstractLocalModelSaver
,BaseLocalModelSaver
PyTorch experiment local model saver
- Parameters:
- save_model(model, project_name, experiment_name, experiment_timestamp=None, epoch=None, iteration_idx=None, protect_existing_folder=True)[source]
Save the PyTorch model representation dict to the local drive
- Parameters:
model (dict) – PyTorch model represented as a dict of weights, optimizer state and other necessary info.
project_name (str) – root name of the project
experiment_name (str) – name of the particular experiment
experiment_timestamp (str or None) – time stamp at the start of training
epoch (int or None) – in which epoch the model is being saved
iteration_idx (int or None) – at which training iteration the model is being saved
protect_existing_folder (bool) – can override potentially already existing folder or not
- Returns:
model_name, model_local_path
- Return type:
- class aitoolbox.experiment.local_save.local_model_save.KerasLocalModelSaver(local_model_result_folder_path='~/project/model_result', checkpoint_model=False)[source]
Bases:
AbstractLocalModelSaver
,BaseLocalModelSaver
Keras experiment local model saver
- Parameters:
- save_model(model, project_name, experiment_name, experiment_timestamp=None, epoch=None, iteration_idx=None, protect_existing_folder=True)[source]
Save the Keras model to the local drive
- Parameters:
model (keras.Model) – Keras model
project_name (str) – root name of the project
experiment_name (str) – name of the particular experiment
experiment_timestamp (str or None) – time stamp at the start of training
epoch (int or None) – in which epoch the model is being saved
iteration_idx (int or None) – at which training iteration the model is being saved
protect_existing_folder (bool) – can override potentially already existing folder or not
- Returns:
model_name, model_local_path
- Return type:
- class aitoolbox.experiment.local_save.local_model_save.LocalSubOptimalModelRemover(metric_name, num_best_kept=2)[source]
Bases:
object
Removes the tracked saved models which become suboptimal when new models are trained in subsequent epochs
Useful when interested in saving the limited local disk space, especially when dealing with large model which take a lot of disk space.
- Parameters:
- decide_if_remove_suboptimal_model(history, new_model_dump_paths)[source]
Make decision if suboptimal model should be removed due to the introduction of the new and better model
- Parameters:
history (aitoolbox.experiment.training_history.TrainingHistory) – training performance history
new_model_dump_paths (list) – new saved models paths which will begin to be tracked
- Returns:
None