Backup

class lib.model.backup_restore.Backup(model_dir: str, model_name: str)

Bases: object

Performs the back up of models at each save iteration, and the restoring of models from their back up location.

Parameters:
  • model_dir (str) – The folder that contains the model to be backed up

  • model_name (str) – The name of the model that is to be backed up

Methods Summary

backup_model(full_path)

Backup a model file.

restore()

Restores a model from backup.

snapshot_models(iterations)

Take a snapshot of the model at the current state and back it up.

Methods Documentation

static backup_model(full_path: str) None

Backup a model file.

The backed up file is saved with the original filename in the original location with .bk appended to the end of the name.

Parameters:

full_path (str) – The full path to a .keras model file or a .json state file

Return type:

None

restore() None

Restores a model from backup.

The original model files are migrated into a folder within the original model folder named <model_name>_archived_<timestamp>. The .bk backup files are then moved to the location of the previously existing model files. Logs that were generated after the the last backup was taken are removed.

Return type:

None

snapshot_models(iterations: int) None

Take a snapshot of the model at the current state and back it up.

The snapshot is a copy of the model folder located in the same root location as the original model file, with the number of iterations appended to the end of the folder name.

Parameters:

iterations (int) – The number of iterations that the model has trained when performing the snapshot.

Return type:

None

static backup_model(full_path: str) None

Backup a model file.

The backed up file is saved with the original filename in the original location with .bk appended to the end of the name.

Parameters:

full_path (str) – The full path to a .keras model file or a .json state file

Return type:

None

restore() None

Restores a model from backup.

The original model files are migrated into a folder within the original model folder named <model_name>_archived_<timestamp>. The .bk backup files are then moved to the location of the previously existing model files. Logs that were generated after the the last backup was taken are removed.

Return type:

None

snapshot_models(iterations: int) None

Take a snapshot of the model at the current state and back it up.

The snapshot is a copy of the model folder located in the same root location as the original model file, with the number of iterations appended to the end of the folder name.

Parameters:

iterations (int) – The number of iterations that the model has trained when performing the snapshot.

Return type:

None