Logging
Tsunami.log — FunctionTsunami.log(trainer::Trainer, name::AbstractString, value;
[on_step, on_epoch, prog_bar, batchsize])Log a value with name name. Can be called from any function in the training loop or from a callback. Logs to the loggers specified in trainer.loggers.
See the Logging docs for more details.
If on_step is true, the value will be logged on each step. If on_epoch is true, the value will be accumulated and logged on each epoch. In this case, the default reduction is the mean over the batches, which will also take into account the batch size. If both on_step and on_epoch are true, the values will be logged as "<name>_step" and "<name>_epoch"
Arguments
trainer::Trainer: The trainer object.name::AbstractString: The name of the value.value: The value to log.batchsize: The size of the current batch. Used only whenon_epoch == Trueto compute the aggregate the batches. Defaults totrainer.fit_state.batchsize.on_epoch::Bool: Whether to log the value on each epoch. Defaults totrueifstageis:train_epoch_endor:val_epoch_end,falseotherwise.on_step::Bool: Whether to log the value on each step. Defaults totrueifstageis:training,falsefor:validationand:testing.prog_bar::Bool: Whether to log the value to the progress bar. Defaults totrue.
Examples
function val_step(model::Model, trainer, batch, batch_idx)
# log the validation loss
...
Tsunami.log(trainer, "val/loss", val_loss)
endLoggers
Tensorboard
Tsunami.TensorBoardLogger — TypeTensorBoardLogger(run_dir)A logger that writes to writes tensorboard events to the run_dir directory. Relies on the TensorBoardLogger.jl package.
See also read_tensorboard_logs.
Tsunami.read_tensorboard_logs — Functionread_tensorboard_logs(logdir)Reads all tensorboard events from the logdir path and returns them as a list of (name, step, value) tuples.
Example
julia> Tsunami.fit!(model, trainer, train_dataloader);
julia> events = Tsunami.read_tensorboard_logs(trainer.fit_state.run_dir)
24-element Vector{Tuple{String, Int64, Any}}:
("train/loss", 1, 2.509954f0)
("epoch", 1, 1.0f0)
("train/acc", 1, 0.0f0)
("train/loss", 2, 2.2748244f0)
("epoch", 2, 1.0f0)
("train/acc", 2, 0.5f0)
...
# Convert to a DataFrame
julia> df = DataFrame([(; name, step, value) for (name, step, value) in events]);
julia> unstack(df, :step, :name, :value)
8×4 DataFrame
Row │ step train/loss epoch train/acc
│ Int64 Float32? Float32? Float32?
─────┼────────────────────────────────────────
1 │ 1 2.50995 1.0 0.0
2 │ 2 2.27482 1.0 0.5
3 │ 3 2.06172 2.0 0.333333
4 │ 4 1.72649 2.0 1.0
5 │ 5 1.57971 3.0 1.0
6 │ 6 1.39933 3.0 1.0
7 │ 7 1.17671 4.0 1.0
8 │ 8 1.17483 4.0 1.0