CSVLogger#

class braintools.trainer.CSVLogger(save_dir, name='logs', version=None, flush_logs_every_n_steps=100)#

CSV file logging backend.

Logs metrics to a CSV file for simple analysis.

Parameters:
  • save_dir (str) – Directory to save CSV logs.

  • name (str) – Experiment name (subdirectory).

  • version (str | None) – Version string.

  • flush_logs_every_n_steps (int) – How often to flush logs to disk.

Examples

>>> logger = CSVLogger('logs/', name='my_experiment')
>>> trainer = Trainer(logger=logger)
finalize(status='success')[source]#

Finalize logging (called at end of training).

Parameters:

status (str) – Final status (‘success’, ‘failed’, ‘interrupted’).

property log_dir: str#

Directory for this specific run’s logs.

log_hyperparams(params)[source]#

Log hyperparameters.

Parameters:

params (Dict[str, Any]) – Dictionary of hyperparameter names to values.

log_metrics(metrics, step=None)[source]#

Log metrics.

Parameters:
  • metrics (Dict[str, float]) – Dictionary of metric names to values.

  • step (int | None) – Global step number.

property root_dir: str#

Root directory for logs.

save()[source]#

Flush buffered metrics to CSV.

If metrics with new column names have appeared since the header was written, the whole file is rewritten with the wider header so that late-appearing metrics are not silently dropped and earlier rows stay column-aligned. (T-14)