From f9992b61eb015335622dc891ffb8245c863c492f Mon Sep 17 00:00:00 2001 From: shashikdm Date: Tue, 14 May 2019 18:50:16 +0530 Subject: [PATCH 1/2] add matrix and list support to log_text --- src/Loggers/LogText.jl | 36 +++++++++++++++++++++++++++++------- test/runtests.jl | 2 ++ test/test_TBLogger.jl | 14 ++++++++------ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/Loggers/LogText.jl b/src/Loggers/LogText.jl index b23b5cd5..8b76cb94 100644 --- a/src/Loggers/LogText.jl +++ b/src/Loggers/LogText.jl @@ -1,23 +1,46 @@ """ - log_text(logger, name, text, step) + log_text(logger::TBLogger, name::String, text::Any, step = nothing) Logs text with name `name` at step `step` +- text: If text is a 2-D or 3-D `Array`, it will be rendered as a table or a list. Any other data will be represented as string """ -function log_text(logger::TBLogger, name::String, text::Any; step=nothing) +function log_text(logger::TBLogger, name::String, text::Any; step = nothing) summ = SummaryCollection() push!(summ.value, text_summary(name, text)) write_event(logger.file, make_event(logger, summ, step=step)) end function text_summary(name::String, text::Any) - text = markdown_repr(text) - textstringval = [Vector{UInt8}(text)] - texttensorshape = TensorShapeProto(dim = Vector([TensorShapeProto_Dim(size = 1)])) + #Create a string tensor + #shape of the tensor + dims = Array{TensorShapeProto_Dim, 1}() + if isa(text, AbstractArray) + for dim in size(text) + push!(dims, TensorShapeProto_Dim(size = dim)) + end + else + push!(dims, TensorShapeProto_Dim(size = 1)) + end + texttensorshape = TensorShapeProto(dim = Vector(dims)) + + #content of the tensor + textstringval = Vector{Array{UInt8, 1}}() + if isa(text, AbstractArray) + for string in text + string = markdown_repr(string) + push!(textstringval, Array{UInt8, 1}(string)) + end + else + text = markdown_repr(text) + push!(textstringval, Array{UInt8, 1}(text)) + end + #metadata for the text textcontent = serialize_proto(TextPluginData(version = 0)) plugindata = SummaryMetadata_PluginData(plugin_name = "text", content = textcontent) smd = SummaryMetadata(plugin_data = plugindata) + #create tensor texttensor = TensorProto(dtype = _DataType.DT_STRING, string_val = textstringval, tensor_shape = texttensorshape) - return Summary_Value(tag = name, metadata = smd, tensor = texttensor) + Summary_Value(tag = name, metadata = smd, tensor = texttensor) end """ @@ -39,4 +62,3 @@ function markdown_repr(x) end return repr(x) end - diff --git a/test/runtests.jl b/test/runtests.jl index bf5b3305..9b8cd626 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -93,6 +93,8 @@ end log_text(logger, "markdown", "**This** is the *power* of >>>markdown", step = step) log_text(logger, "html", "

HTML is a programming language

", step = step) log_text(logger, "docstring", """This should work too""", step = step) + log_text(logger, "Array", collect(1:10), step = step) + log_text(logger, "Matrix", rand(4, 4), step = step) end @testset "Text processing interface" begin diff --git a/test/test_TBLogger.jl b/test/test_TBLogger.jl index 83f24689..5f795f7f 100644 --- a/test/test_TBLogger.jl +++ b/test/test_TBLogger.jl @@ -50,19 +50,21 @@ end end @testset "stepping" begin - import TensorBoardLogger.step - + # workaround step being already exported in julia 1.0 + #import TensorBoardLogger.step + tb_step = TensorBoardLogger.step + tbl = TBLogger("test_logs/run", tb_overwrite) - @test step(tbl) == 0 + @test tb_step(tbl) == 0 tbl = TBLogger("test_logs/run", purge_step=12) - @test step(tbl) == 12 + @test tb_step(tbl) == 12 @test increment_step!(tbl, 1) == 13 - @test step(tbl) == 13 + @test tb_step(tbl) == 13 @test set_step!(tbl, 1) == 1 - @test step(tbl) == 1 + @test tb_step(tbl) == 1 end @testset "resetting" begin From cf7c9116023123a334ff3d8e0de8f84dd39a5d7f Mon Sep 17 00:00:00 2001 From: shashikdm Date: Tue, 14 May 2019 18:54:41 +0530 Subject: [PATCH 2/2] reverting test_TBLogger.jl --- test/test_TBLogger.jl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/test/test_TBLogger.jl b/test/test_TBLogger.jl index 5f795f7f..83f24689 100644 --- a/test/test_TBLogger.jl +++ b/test/test_TBLogger.jl @@ -50,21 +50,19 @@ end end @testset "stepping" begin - # workaround step being already exported in julia 1.0 - #import TensorBoardLogger.step - tb_step = TensorBoardLogger.step - + import TensorBoardLogger.step + tbl = TBLogger("test_logs/run", tb_overwrite) - @test tb_step(tbl) == 0 + @test step(tbl) == 0 tbl = TBLogger("test_logs/run", purge_step=12) - @test tb_step(tbl) == 12 + @test step(tbl) == 12 @test increment_step!(tbl, 1) == 13 - @test tb_step(tbl) == 13 + @test step(tbl) == 13 @test set_step!(tbl, 1) == 1 - @test tb_step(tbl) == 1 + @test step(tbl) == 1 end @testset "resetting" begin