@@ -3,8 +3,7 @@ mutable struct TBLogger <: AbstractLogger
33 file:: IOStream
44 all_files:: Dict{String, IOStream}
55 global_step:: Int
6-
7- min_level:: LogLevel
6+ min_level:: LogLevel
87end
98
109
@@ -32,16 +31,16 @@ by tensorboard (usefull in the case of restarting a crashed computation).
3231tensorboard
3332"""
3433function TBLogger (logdir= " tensorboard_logs/run" , overwrite= tb_increment;
35- time= time (), purge_step:: Union{Int,Nothing} = nothing ,
36- min_level:: LogLevel = Info)
34+ time= time (), purge_step:: Union{Int,Nothing} = nothing ,
35+ min_level:: LogLevel = Info)
3736
38- logdir = init_logdir (logdir, overwrite)
39- fpath, evfile = create_eventfile (logdir, purge_step, time)
37+ logdir = init_logdir (logdir, overwrite)
38+ fpath, evfile = create_eventfile (logdir, purge_step, time)
4039
4140 all_files = Dict (fpath => evfile)
42- start_step = something (purge_step, 0 )
41+ start_step = something (purge_step, 0 )
4342
44- TBLogger (logdir, evfile, all_files, start_step, min_level)
43+ TBLogger (logdir, evfile, all_files, start_step, min_level)
4544end
4645
4746"""
@@ -55,7 +54,7 @@ is determined by `overwrite`.
5554 - `overwrite=tb_append` appends to it's previous content.
5655"""
5756function init_logdir (logdir, overwrite= tb_increment)
58- if overwrite == tb_overwrite
57+ if overwrite == tb_overwrite
5958 rm (logdir; force= true , recursive= true )
6059 elseif overwrite == tb_append
6160 # do nothing
@@ -74,7 +73,7 @@ function init_logdir(logdir, overwrite=tb_increment)
7473 end
7574 mkpath (logdir)
7675
77- return realpath (logdir)
76+ return realpath (logdir)
7877end
7978
8079"""
@@ -89,11 +88,11 @@ Optional keyword argument `prepend` can be passed to prepend a path to the file
8988name.
9089"""
9190function create_eventfile (logdir, purge_step= nothing , time= time (); prepend= " " )
92- hostname = gethostname ()
91+ hostname = gethostname ()
9392 fname = prepend* " events.out.tfevents.$time .$hostname "
9493 fpath = joinpath (logdir, fname)
9594
96- mkpath (dirname (fpath))
95+ mkpath (dirname (fpath))
9796 file = open (fpath, " w" )
9897
9998 # Create the initial log
@@ -117,8 +116,8 @@ Adds an event file to `lg` with `path` prepended to it's name. It can be used
117116to create sub-event collection in a single event collection.
118117"""
119118function add_eventfile (lg:: TBLogger , path= " " )
120- fname, file = create_eventfile (logdir (lg), prepend= path)
121- lg. all_files[fname] = file
119+ fname, file = create_eventfile (logdir (lg), prepend= path)
120+ lg. all_files[fname] = file
122121 return fname
123122end
124123
@@ -180,19 +179,19 @@ step(lg::TBLogger) = lg.global_step
180179Reset the TBLogger `lg`, deleting everything in it's log directory.
181180"""
182181function reset! (lg:: TBLogger )
183- # close open streams
184- for k= keys (lg. all_files)
185- close (lg. all_files[k])
186- delete! (lg. all_files, k)
187- end
188-
189- # Overwrite the logdirectoy and create a new base event file
190- init_logdir (logdir (lg), tb_overwrite)
191- fname = add_eventfile (lg, " " )
192- lg. file = get_file (lg, fname)
193- set_step! (lg, 0 )
194-
195- return lg
182+ # close open streams
183+ for k= keys (lg. all_files)
184+ close (lg. all_files[k])
185+ delete! (lg. all_files, k)
186+ end
187+
188+ # Overwrite the logdirectoy and create a new base event file
189+ init_logdir (logdir (lg), tb_overwrite)
190+ fname = add_eventfile (lg, " " )
191+ lg. file = get_file (lg, fname)
192+ set_step! (lg, 0 )
193+
194+ return lg
196195end
197196
198197
0 commit comments