training_progress_callback
最后更新
luxonis_train.callbacks.training_progress_callback记录每个批次和每个 epoch 的进度和时间。类
TrainingProgressCallback
trainer.logger,并使用 log_metrics,其中 <mode> 是 train、val 或 test:<mode>/epoch_progress_percent:已完成的 epoch 批次百分比。<mode>/epoch_duration_sec:从 epoch 开始到日志条目的秒数。<mode>/batch_total_sec:从日志批次的开始钩子到结束钩子的秒数。<mode>/epoch_completion_sec:从 epoch 开始到结束的秒数。
val/epoch_completion_sec 和 test/epoch_completion_sec 是例外。它们的步长是 trainer.current_epoch。批次结束钩子仅在 epoch 中完成的批次数量是 log_every_n_batches 的倍数时才记录。回调函数忽略验证健全性检查。批次结束和 epoch 结束钩子仅在 rank zero 上运行。如果没有 trainer.logger,回调函数不发送任何键。每个训练 epoch 的开始会记录一个警告。LuxonisLightningModule.get_mlflow_logging_keys 列出了当配置中包含此回调函数时的十二个键。将回调函数添加到配置的 trainer.callbacks 中:Yaml
1trainer:
2 callbacks:
3 - name: TrainingProgressCallback
4 params:
5 log_every_n_batches: 10方法
init
Python
1def __init__(log_every_n_batches: int = 1):log_every_n_batches(int):每隔多少个 epoch 批次记录一次批次结束。1记录每个批次。较高的值会减少日志记录开销。小于1的值等同于1。
on_test_batch_end
Python
1def on_test_batch_end(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule, outputs: STEP_OUTPUT, batch: Any, batch_idx: int, dataloader_idx: int = 0):log_every_n_batches 的倍数时,它会在测试批次计数器的步长处记录这些键:test/batch_total_sec:自 on_test_batch_start 以来的秒数。test/epoch_progress_percent:100c ⁄ n,其中 c 是批次计数,n 是trainer.num_test_batches的有限条目之和。当 n 为0时,值为0.0。test/epoch_duration_sec:自 on_test_epoch_start 以来的秒数。
trainer.logger,钩子不记录任何内容。参数trainer(pl.Trainer):训练器。钩子读取num_test_batches并记录到logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。outputs(STEP_OUTPUT):测试步骤的输出。未使用。batch(Any):批次。未使用。batch_idx(int):批次的索引。未使用。dataloader_idx(int):数据加载器的索引。未使用。
on_test_batch_start
Python
1def on_test_batch_start(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule, batch: Any, batch_idx: int, dataloader_idx: int = 0):test/batch_total_sec 的开始时间。参数trainer(pl.Trainer):训练器。未使用。pl_module(lxt.LuxonisLightningModule):模型。未使用。batch(Any):批次。未使用。batch_idx(int):批次的索引。未使用。dataloader_idx(int):数据加载器的索引。未使用。
on_test_epoch_end
Python
1def on_test_epoch_end(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule):trainer.logger,它不执行任何操作。当 epoch 的批次计数大于 0 且不是 log_every_n_batches 的倍数时,最后一个批次没有日志条目。钩子然后将 test/epoch_progress_percent 记录为 100.0,并将 test/epoch_duration_sec 记录在测试批次计数器的步长处。在任何情况下,它都会在 trainer.current_epoch 步长处记录 test/epoch_completion_sec,即自 on_test_epoch_start 以来的秒数。参数trainer(pl.Trainer):训练器。钩子读取current_epoch并记录到logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。
on_test_epoch_start
Python
1def on_test_epoch_start(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule):test/epoch_progress_percent 记录为 0.0。如果没有 trainer.logger,它不记录任何内容。参数trainer(pl.Trainer):训练器。钩子记录到其logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。
on_train_batch_end
Python
1def on_train_batch_end(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule, outputs: STEP_OUTPUT, batch: Any, batch_idx: int):batch_idx + 1 是 log_every_n_batches 的倍数时,它会在该计数器的步长处记录这些键:train/epoch_progress_percent:100(i + 1) ⁄ n,其中 i 是batch_idx,n 是trainer.num_training_batches。当 n 为0或无限时,值为0.0。train/epoch_duration_sec:自 on_train_epoch_start 以来的秒数。train/batch_total_sec:自 on_train_batch_start 以来的秒数。
trainer.logger,钩子不记录任何内容。参数trainer(pl.Trainer):训练器。钩子读取num_training_batches并记录到logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。outputs(STEP_OUTPUT):训练步骤的输出。未使用。batch(Any):批次。未使用。batch_idx(int):epoch 中批次的索引。
on_train_batch_start
Python
1def on_train_batch_start(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule, batch: Any, batch_idx: int):train/batch_total_sec 的开始时间。参数trainer(pl.Trainer):训练器。未使用。pl_module(lxt.LuxonisLightningModule):模型。未使用。batch(Any):批次。未使用。batch_idx(int):epoch 中批次的索引。未使用。
on_train_epoch_end
Python
1def on_train_epoch_end(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule):train/epoch_completion_sec(自 on_train_epoch_start 以来的秒数)和 train/epoch_progress_percent 记录为 100.0。这两个键都使用训练批次计数器的步长。如果没有 trainer.logger,钩子不记录任何内容。参数trainer(pl.Trainer):训练器。钩子记录到其logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。
on_train_epoch_start
Python
1def on_train_epoch_start(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule):train/epoch_progress_percent 记录为 0.0。如果没有 trainer.logger,它会记录一个警告。参数trainer(pl.Trainer):训练器。钩子记录到其logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。
on_validation_batch_end
Python
1def on_validation_batch_end(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule, outputs: STEP_OUTPUT, batch: Any, batch_idx: int, dataloader_idx: int = 0):log_every_n_batches 的倍数时,它会在验证批次计数器的步长处记录这些键:val/batch_total_sec:自 on_validation_batch_start 以来的秒数。val/epoch_progress_percent:100c ⁄ n,其中 c 是批次计数,n 是trainer.num_val_batches的有限条目之和。当 n 为0时,值为0.0。val/epoch_duration_sec:自 on_validation_epoch_start 以来的秒数。
trainer.logger,钩子不记录任何内容。参数trainer(pl.Trainer):训练器。钩子读取sanity_checking和num_val_batches,并记录到logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。outputs(STEP_OUTPUT):验证步骤的输出。未使用。batch(Any):批次。未使用。batch_idx(int):批次的索引。未使用。dataloader_idx(int):数据加载器的索引。未使用。
on_validation_batch_start
Python
1def on_validation_batch_start(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule, batch: Any, batch_idx: int, dataloader_idx: int = 0):val/batch_total_sec 的开始时间。参数trainer(pl.Trainer):训练器。钩子读取sanity_checking。pl_module(lxt.LuxonisLightningModule):模型。未使用。batch(Any):批次。未使用。batch_idx(int):批次的索引。未使用。dataloader_idx(int):数据加载器的索引。未使用。
on_validation_epoch_end
Python
1def on_validation_epoch_end(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule):trainer.logger 的情况下,它不执行任何操作。当 epoch 的批次计数大于 0 且不是 log_every_n_batches 的倍数时,最后一个批次没有日志条目。钩子然后将 val/epoch_progress_percent 记录为 100.0,并将 val/epoch_duration_sec 记录在验证批次计数器的步长处。在任何情况下,它都会在 trainer.current_epoch 步长处记录 val/epoch_completion_sec,即自 on_validation_epoch_start 以来的秒数。参数trainer(pl.Trainer):训练器。钩子读取sanity_checking和current_epoch,并记录到logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。
on_validation_epoch_start
Python
1def on_validation_epoch_start(trainer: pl.Trainer, pl_module: lxt.LuxonisLightningModule):val/epoch_progress_percent 记录为 0.0。如果没有 trainer.logger,它不记录任何内容。参数trainer(pl.Trainer):训练器。钩子读取sanity_checking并记录到logger。pl_module(lxt.LuxonisLightningModule):模型。未使用。