fl4health.utils.early_stopper module¶
- class EarlyStopper(client, patience=1, interval_steps=5, snapshot_dir=None)[source]¶
Bases:
object
- __init__(client, patience=1, interval_steps=5, snapshot_dir=None)[source]¶
Early stopping class is a plugin for the client that allows to stop local training based on the validation loss. At each training step this class saves the best state of the client and restores it if the client is stopped. If the client starts to overfit, the early stopper will stop the training process and restore the best state of the client before sending the model to the server.
- Parameters:
client (BasicClient) – The client to be monitored.
patience (int, optional) – Number of validation cycles to wait before stopping the training. If it is equal to None client never stops, but still loads the best state before sending the model to the server. Defaults to 1.
interval_steps (int) – Specifies the frequency, in terms of training intervals, at which the early stopping mechanism should evaluate the validation loss. Defaults to 5.
snapshot_dir (Path | None, optional) – Rather than keeping best state in the memory we can checkpoint it to the given directory. If it is not given, the best state is kept in the memory. Defaults to None.
- load_snapshot(attributes=None)[source]¶
Load checkpointed snapshot dict consisting to the respective model attributes.