Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support prepend argument in TBLogger constructor #101

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/TBLogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export tb_append, tb_overwrite, tb_increment
"""
TBLogger(logdir[, tb_increment];
time=time(),
prefix="",
purge_step=nothing,
step_increment=1,
min_level=Logging.Info)
Expand All @@ -29,20 +30,24 @@ argument specifies the behaviour if the `logdir` already exhists: the default
choice `tb_increment` appends an increasing number 1,2... to `logdir`. Other
choices are `tb_overwrite`, which overwrites the previous folder, and `tb_append`.

Optional keyword argument `prefix` can be passed to prepend a path to the file
name (note, not the log directory). See `create_eventfile()`

If a `purge_step::Int` is passed, every step before `purge_step` will be ignored
by tensorboard (usefull in the case of restarting a crashed computation).

`min_level` specifies the minimum level of messages logged to
tensorboard.
"""
function TBLogger(logdir="tensorboard_logs/run", overwrite=tb_increment;
time=time(),
time=time(),
prefix="",
purge_step::Union{Int,Nothing}=nothing,
step_increment = 1,
min_level::LogLevel=Info)

logdir = init_logdir(logdir, overwrite)
fpath, evfile = create_eventfile(logdir, purge_step, time)
fpath, evfile = create_eventfile(logdir, purge_step, time; prepend = prefix)

all_files = Dict(fpath => evfile)
start_step = something(purge_step, 0)
Expand Down
5 changes: 5 additions & 0 deletions test/test_TBLogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ test_log_dir = "test_logs/"
tbl4 = TBLogger(test_log_dir*"run_2", tb_overwrite)
@test !isfile(test_log_dir*"run_2/testfile")

# check custom file prefix
tbl5 = TBLogger(test_log_dir*"run_3"; time = 0, prefix = "test.")
@test isfile(test_log_dir*"run_3/test.events.out.tfevents.0.$(gethostname())")

# close all event files
close.(values(tbl1.all_files))
close.(values(tbl2.all_files))
close.(values(tbl4.all_files))
close.(values(tbl5.all_files))
end

@testset "create log directory" begin
Expand Down