speechbrain.utils.epoch_loop moduleο
Implements a checkpointable epoch counter (loop), optionally integrating early stopping.
- Authors
Aku Rouhe 2020
Davide Borra 2021
Summaryο
Classes:
An epoch counter which can save and recall its state. |
|
An epoch counter which can save and recall its state, integrating an early stopper by tracking a target metric. |
Referenceο
- class speechbrain.utils.epoch_loop.EpochCounter(limit)[source]ο
Bases:
object
An epoch counter which can save and recall its state.
Use this as the iterator for epochs. Note that this iterator gives you the numbers from [1 β¦ limit] not [0 β¦ limit-1] as range(limit) would.
- Parameters:
limit (int) β maximum number of epochs
Example
>>> from speechbrain.utils.checkpoints import Checkpointer >>> tmpdir = getfixture('tmpdir') >>> epoch_counter = EpochCounter(10) >>> recoverer = Checkpointer(tmpdir, {"epoch": epoch_counter}) >>> recoverer.recover_if_possible() >>> # Now after recovery, >>> # the epoch starts from where it left off! >>> for epoch in epoch_counter: ... # Run training... ... ckpt = recoverer.save_checkpoint()
- class speechbrain.utils.epoch_loop.EpochCounterWithStopper(limit, limit_to_stop, limit_warmup, direction)[source]ο
Bases:
EpochCounter
An epoch counter which can save and recall its state, integrating an early stopper by tracking a target metric.
- Parameters:
Example
>>> limit = 10 >>> limit_to_stop = 5 >>> limit_warmup = 2 >>> direction = "min" >>> epoch_counter = EpochCounterWithStopper(limit, limit_to_stop, limit_warmup, direction) >>> for epoch in epoch_counter: ... # Run training... ... # Track a validation metric, (insert calculation here) ... current_valid_metric = 0 ... # Update epoch counter so that we stop at the appropriate time ... epoch_counter.update_metric(current_valid_metric) ... print(epoch) 1 2 3 4 5 6 7 8