Skip to content

Commit a2b97d4

Browse files
authored
Merge pull request #146 from VaiTon/events
Add events function to helpers.jl
2 parents e0dcbb3 + 18ca3aa commit a2b97d4

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/Deserialization/helpers.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,23 @@ function steps(tbl; kwargs...)
3333

3434
return steps
3535
end
36+
37+
"""
38+
events(logger)
39+
40+
Returns a list of all the events serialized by `logger`.
41+
42+
`logger` can be a `TBLogger` or the path of a valid TensorBoard logdir.
43+
44+
You should call this function only if you are interested in the events in an array-like
45+
structure. If you need to iterate over the events, use `map_events` instead.
46+
"""
47+
function events(tbl; kwargs...)
48+
events = []
49+
50+
map_events(tbl; kwargs...) do ev
51+
push!(events, ev)
52+
end
53+
54+
return events
55+
end

test/test_TBLogger.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test_log_dir = "test_logs/"
1919
close.(values(tbl3.all_files))
2020
tbl4 = TBLogger(test_log_dir*"run_2", tb_overwrite)
2121
@test !isfile(test_log_dir*"run_2/testfile")
22-
22+
2323
# check custom file prefix
2424
tbl5 = TBLogger(test_log_dir*"run_3"; time = 0, prefix = "test.")
2525
@test isfile(test_log_dir*"run_3/test.events.out.tfevents.0.$(gethostname())")
@@ -124,3 +124,11 @@ end
124124
@test length(tbl.all_files) == 1
125125

126126
end
127+
128+
@testset "events" begin
129+
tbl = TBLogger(test_log_dir*"run", tb_overwrite)
130+
@test length(TensorBoardLogger.events(tbl)) == 1 # creation event
131+
132+
TensorBoardLogger.log_value(tbl, "test", 1.0)
133+
@test length(TensorBoardLogger.events(tbl)) == 2 # creation event + log_value
134+
end

0 commit comments

Comments
 (0)