speechbrain.utils.epoch_loop 模块
实现一个可检查点的epoch计数器(循环),可选择集成早停功能。
- Authors
阿库·柔赫 2020
达维德·博拉 2021
摘要
类:
一个可以保存和恢复其状态的时期计数器。 |
|
一个可以保存和恢复其状态的epoch计数器,通过跟踪目标指标集成早期停止器。 |
参考
- class speechbrain.utils.epoch_loop.EpochCounter(limit)[source]
基础类:
object一个可以保存和恢复其状态的时期计数器。
将此用作迭代器进行epochs。 请注意,此迭代器为您提供从[1 … limit]的数字,而不是 [0 … limit-1] 如 range(limit) 会提供的。
- Parameters:
limit (int) – 最大轮次数
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]
基础类:
EpochCounter一个可以保存和恢复其状态的时期计数器,通过跟踪目标指标集成早期停止器。
- 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