Last active
July 5, 2019 16:14
-
-
Save PhilipVinc/eb15570eb09cb2916e781a4b814457da to your computer and use it in GitHub Desktop.
Read data from tensor board back into Julia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using TensorBoardLogger, Logging, ValueHistories | |
function read_event(f::IOStream) | |
header = read(f, 8) | |
crc_header = read(f, 4) | |
# check | |
crc_header_ck = reinterpret(UInt8, UInt32[TensorBoardLogger.masked_crc32c(header)]) | |
@assert crc_header == crc_header_ck | |
# DATA | |
data_len = first(reinterpret(Int64, header)) | |
data = read(f, data_len) | |
crc_data = read(f, 4) | |
# check | |
crc_data_ck = reinterpret(UInt8, UInt32[TensorBoardLogger.masked_crc32c(data)]) | |
@assert crc_data == crc_data_ck | |
pb = PipeBuffer(data) | |
ev = TensorBoardLogger.readproto(pb, TensorBoardLogger.Event()) | |
return ev | |
end | |
# Create some mock data | |
tb_logger = TBLogger("testlog") | |
with_logger(tb_logger) do | |
for i=1:5 | |
@info "test" val=i b=i*2 | |
end | |
end | |
# tb_logger.all_files is a dictionary of paths=>iostream of all files open | |
fname=joinpath(tb_logger.logdir, first(keys(tb_logger.all_files))) | |
# Open the event's file | |
f=open(fname, "r") | |
#trash the first event, as it is empty. | |
ev_zero = read_event(f) | |
# save data in here | |
mvhist = MVHistory() | |
# deserialize scalar data. | |
while !eof(f) | |
ev=read_event(f) | |
for sv=ev.summary.value | |
tag = sv.tag | |
val = sv.simple_value | |
push!(mvhist, Symbol(tag), ev.step, val) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment