Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add events function to helpers.jl #146

Merged
merged 1 commit into from
May 14, 2024
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
20 changes: 20 additions & 0 deletions src/Deserialization/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,23 @@ function steps(tbl; kwargs...)

return steps
end

"""
events(logger)

Returns a list of all the events serialized by `logger`.

`logger` can be a `TBLogger` or the path of a valid TensorBoard logdir.

You should call this function only if you are interested in the events in an array-like
structure. If you need to iterate over the events, use `map_events` instead.
"""
function events(tbl; kwargs...)
events = []

map_events(tbl; kwargs...) do ev
push!(events, ev)
end

return events
end
10 changes: 9 additions & 1 deletion test/test_TBLogger.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_log_dir = "test_logs/"
close.(values(tbl3.all_files))
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())")
Expand Down Expand Up @@ -124,3 +124,11 @@ end
@test length(tbl.all_files) == 1

end

@testset "events" begin
tbl = TBLogger(test_log_dir*"run", tb_overwrite)
@test length(TensorBoardLogger.events(tbl)) == 1 # creation event

TensorBoardLogger.log_value(tbl, "test", 1.0)
@test length(TensorBoardLogger.events(tbl)) == 2 # creation event + log_value
end
Loading