Skip to content

Commit ab514be

Browse files
authored
Merge pull request #124 from nomadbl/master
Update to ProtoBuf 1.0.11
2 parents 875fdb4 + b2a763b commit ab514be

File tree

115 files changed

+10432
-9724
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+10432
-9724
lines changed

.github/workflows/UnitTest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [macos-latest, ubuntu-latest]
16-
julia_version: ["1.3", "1", "nightly"]
16+
julia_version: ["1.6", "1", "nightly"]
1717

1818
runs-on: ${{ matrix.os }}
1919
env:

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TensorBoardLogger"
22
uuid = "899adc3e-224a-11e9-021f-63837185c80f"
33
authors = ["Filippo Vicentini <[email protected]>"]
4-
version = "0.1.20"
4+
version = "0.1.30"
55

66
[deps]
77
CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
@@ -14,10 +14,10 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1414
[compat]
1515
FileIO = "1.2.3"
1616
ImageCore = "0.8.1, 0.9"
17-
ProtoBuf = "0.10, 0.11"
17+
ProtoBuf = "1.0.11"
1818
Requires = "0.5, 1"
19-
StatsBase = "0.27, 0.28, 0.29, 0.30, 0.31, 0.32, 0.33"
20-
julia = "1.3"
19+
StatsBase = "0.27, 0.28, 0.29, 0.30, 0.31, 0.32, 0.33, 0.34"
20+
julia = "1.6"
2121

2222
[extras]
2323
Minio = "4281f0d9-7ae0-406e-9172-b7277c1efa20"

gen/compile_proto.jl

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,63 +21,45 @@ pbpath =dirname(dirname(PosixPath(pathof(ProtoBuf))))/p"gen"
2121
cur_path = cwd()
2222
TBL_root = dirname(cur_path)
2323

24-
src_dir = cur_path/"proto"
25-
out_dir = cur_path/"protojl"
24+
# src_dir = cur_path/"proto"
25+
src_dir = PosixPath(".")/"proto"
26+
out_dir = cur_path/"protojl"
2627

2728
## Clean the output directory
2829
rm(out_dir, force=true, recursive=true)
2930

3031
## First module
3132
function process_module(cur_module::AbstractString; base_module::AbstractString=cur_module, input_path=cur_module)
32-
# Include search paths
33-
includes = [src_dir, src_dir/base_module]
3433

3534
# Output folder
36-
module_out_dir = out_dir/cur_module
35+
module_out_dir = out_dir/cur_module
3736

3837
# Input files
39-
infiles = glob("*.proto", src_dir/input_path)
38+
infiles = split.(string.(glob("*.proto", src_dir/input_path)), '/') .|> (a -> a[3:end]) .|> a -> joinpath(a...)
4039

4140
mkpath(module_out_dir)
42-
includes_str=["--proto_path=$path" for path=includes]
43-
run(ProtoBuf.protoc(`$includes_str --julia_out=$module_out_dir $infiles`))
44-
45-
nothing
41+
relative_paths = string.(infiles)
42+
search_directories = joinpath(@__DIR__, "proto")
43+
output_directory = string(module_out_dir)
44+
# println("relative_paths=$relative_paths")
45+
# println("search_directories=$search_directories")
46+
# println("output_directory=$output_directory")
47+
ProtoBuf.protojl(relative_paths ,search_directories ,output_directory)
48+
files_to_include = [string(module_out_dir/basename(file)) for file in infiles]
49+
return files_to_include
4650
end
4751

4852
#process_module("tensorflow", input_path="tensorflow/core/protobuf")
4953

50-
process_module("tensorboard", input_path="tensorboard/compat/proto")
54+
files_to_include = process_module("tensorboard", input_path="tensorboard/compat/proto")
5155

5256
#plugins = ["audio", "custom_scalar", "hparams", "histogram", "image", "scalar", "text"]
5357
plugins = ["custom_scalar", "hparams", "text"]
54-
for plugin in plugins
55-
process_module("tensorboard/plugins/$plugin", base_module="tensorboard")
56-
end
5758

59+
append!(files_to_include, (process_module("tensorboard/plugins/$plugin", base_module="tensorboard") for plugin in plugins)...)
5860

59-
## this fails but would be better
60-
#cur_module = "tensorboard"
61-
#base_module = cur_module
62-
#
63-
## Include search paths
64-
#includes = [src_dir, src_dir/base_module]
65-
#
66-
## Output folder
67-
#module_out_dir = out_dir/("$cur_module"*"2")
68-
#
69-
## Input files
70-
#infiles = glob("*.proto", src_dir/cur_module/"compat/proto")
71-
#
72-
#for plugin in plugins
73-
# plugin_proto_files = glob("*.proto", src_dir/cur_module/"plugins/$plugin")
74-
# append!(infiles, plugin_proto_files)
75-
#end
76-
#
77-
#mkpath(module_out_dir)
78-
#includes_str=["--proto_path=$path" for path=includes]
79-
#run(ProtoBuf.protoc(`$includes_str --julia_out=$module_out_dir $infiles`))
80-
61+
# files_to_include contains all the proto files, can be used for printing and inspection
62+
println("generated code for \n$files_to_include")
8163

8264
# Finally move the output directory to the src folder
8365
mv(out_dir, TBL_root/"src"/"protojl")

src/Deserialization/deserialization.jl

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function read_event(f::IO)
4949
@assert crc_data == crc_data_ck
5050

5151
pb = PipeBuffer(data)
52-
ev = readproto(pb, Event())
52+
ev = decode(ProtoDecoder(pb), Event)
5353
return ev
5454
end
5555

@@ -137,19 +137,9 @@ end
137137
138138
Returns the type of a summary
139139
"""
140-
function summary_type(summary)
141-
if hasproperty(summary, :histo)
142-
return :histo
143-
elseif hasproperty(summary, :image)
144-
return :image
145-
elseif hasproperty(summary, :audio)
146-
return :audio
147-
elseif hasproperty(summary, :tensor)
148-
return :tensor
149-
#elseif hasproperty(summary, :simple_value)
150-
end
151-
# always defined
152-
return :simple_value
140+
function summary_type(summary::Summary_Value)
141+
summary.value isa Nothing && error("Summary value of Nothing while deserializing")
142+
return summary.value.name
153143
end
154144

155145
"""
@@ -193,12 +183,11 @@ SummaryDeserializingIterator(summ; smart=true) =
193183
function Base.iterate(iter::SummaryDeserializingIterator, state=1)
194184
evs = iter.summary
195185
res = iterate(evs, state)
196-
res == nothing && return nothing
186+
res isa Nothing && return nothing
197187

198188
(tag, summary), i_state = res
199189

200190
typ = summary_type(summary)
201-
202191
if typ === :histo
203192
val = deserialize_histogram_summary(summary)
204193
tag, val, state = lookahead_deserialize(tag, val, evs, state, :histo)
@@ -210,7 +199,7 @@ function Base.iterate(iter::SummaryDeserializingIterator, state=1)
210199
elseif typ === :tensor
211200
val = deserialize_tensor_summary(summary)
212201
elseif typ === :simple_value
213-
val = summary.simple_value
202+
val = summary.value
214203
tag, val, state = lookahead_deserialize(tag, val, evs, state, :simple_value)
215204
else
216205
@error "Event with unknown field" summary=summary
@@ -254,17 +243,15 @@ function map_summaries(fun::Function, logdir; purge=true, tags=nothing, steps=no
254243

255244
for event_file in TBEventFileCollectionIterator(logdir, purge=purge)
256245
for event in event_file
257-
# if event.summary is not defined, don't bother processing this event,
258-
# as it's probably a "start file" event or a graph event.
259-
!hasproperty(event, :summary) && continue
260-
246+
# if event.what contains no summary, don't bother processing this event
247+
event.what isa Nothing && continue
248+
!(event.what.value isa Summary) && continue
261249
step = event.step
262250
steps !== nothing && step steps && continue
263251

264-
iter = SummaryDeserializingIterator(event.summary, smart)
252+
iter = SummaryDeserializingIterator(event.what.value, smart)
265253
for (name, val) in iter
266254
tags !== nothing && name tags && continue
267-
268255
fun(name, step, val)
269256
end
270257
end

src/Deserialization/histograms.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
function deserialize_histogram_summary(summary)
1+
function deserialize_histogram_summary(summary::Summary_Value)
22
# custom deserialization
33
if hasproperty(summary, :metadata)
4+
histo = summary.value.value
45
if summary.metadata.plugin_data.plugin_name == TB_PLUGIN_JLARRAY_NAME
5-
val = reshape(summary.histo.bucket,
6+
val = reshape(histo.bucket,
67
reinterpret(Int,
78
summary.metadata.plugin_data.content)...)
89

@@ -11,7 +12,7 @@ function deserialize_histogram_summary(summary)
1112
end
1213

1314
# deserialize histogramproto
14-
hist_proto = summary.histo
15+
hist_proto = summary.value.value
1516
bin_edges = similar(hist_proto.bucket_limit, length(hist_proto.bucket_limit)+1)
1617
bin_edges[1] = hist_proto.min
1718
bin_edges[2:end] .= hist_proto.bucket_limit
@@ -27,7 +28,7 @@ function lookahead_deserialize_histogram_summary(old_tag, old_val, evs::Summary,
2728
result = old_tag, old_val, state
2829
# iterate to the next element
2930
res = iterate(evs, state + 1)
30-
res == nothing && return result
31+
res isa Nothing && return result
3132

3233
# if the next event is identified, check its type
3334
(new_tag, summary), i_state = res

src/Deserialization/images.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
function deserialize_image_summary(summary)
2-
img = summary.image
1+
function deserialize_image_summary(summary::Summary_Value)
2+
img = summary.value.value
33

44
value = load(_format_stream(format"PNG", IOBuffer(img.encoded_image_string)))
55

src/Deserialization/lookahead.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ end
4949
function lookahead_deserialize_simple_value_summary(old_tag, old_val, evs::Summary,
5050
state)
5151
# prepare the default output (when no action is taken)
52-
result = old_tag, old_val, state
52+
result = old_tag, old_val.value, state
5353
# iterate to the next element
5454
res = iterate(evs, state + 1)
55-
res == nothing && return result
55+
res isa Nothing && return result
5656

5757
# if the next event is identified, check its type
5858
(new_tag, summary), i_state = res
5959
typ = summary_type(summary)
6060

6161
# if types match, check tags. If they match, return modified structure
6262
if typ === :simple_value && tags_match_re_im(old_tag, new_tag)
63-
val_im = summary.simple_value
64-
result = new_tag[1:end-3], old_val + im*val_im, i_state - 1
63+
val_im = summary.value.value
64+
result = new_tag[1:end-3], old_val.value + im*val_im, i_state - 1
6565
else
6666
return result
6767
end

src/Deserialization/tensor.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using .tensorboard: TextPluginData
1+
using .tensorboard_plugin_text: TextPluginData
22

33
function deserialize_tensor_summary(summary)
44
metadata = summary.metadata
@@ -15,8 +15,8 @@ function deserialize_tensor_summary(summary)
1515
end
1616

1717
function deserialize_text_tensor(summary, sizes, names)
18-
version_data = readproto(PipeBuffer(summary.metadata.plugin_data.content),
19-
TextPluginData())
18+
version_data = decode(ProtoDecoder(PipeBuffer(summary.metadata.plugin_data.content)),
19+
TextPluginData)
2020
tensor = summary.tensor
2121
strings = Array{String, length(sizes)}(undef, sizes...)
2222

src/Loggers/LogAudio.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using .tensorboard: Summary_Audio
1+
using .tensorboard: var"Summary.Audio" as Summary_Audio
22

33
"""
44
log_audios(logger::TBLogger, name::AbstractString, samples::AbstractArray, samplerate::Real; step=step(logger))
@@ -32,6 +32,6 @@ function audio_summary(name::AbstractString, samples::AbstractArray, samplerate:
3232
io = IOBuffer()
3333
save(_format_stream(format"WAV",io), samples)
3434
eas = io.data
35-
audio = Summary_Audio(sample_rate = samplerate, num_channels = ndims(samples), length_frames = size(samples, 1), encoded_audio_string = eas, content_type = "audio/wav")
36-
Summary_Value(tag=name, audio=audio)
35+
audio = Summary_Audio(samplerate, ndims(samples), size(samples, 1), eas, "audio/wav")
36+
Summary_Value(name, name, nothing, OneOf(:audio, audio))
3737
end

src/Loggers/LogHistograms.jl

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,36 @@ end
4848
function histogram_summary(name::AbstractString, hist::Histogram{T,1}) where T
4949
edges = first(hist.edges)
5050
hist_vals = hist.weights
51-
52-
hp = HistogramProto(min=first(edges), max=last(edges),
53-
bucket_limit=collect(edges[2:end]),
54-
bucket=hist_vals)
55-
return Summary_Value(tag=name, histo=hp)
51+
num = length(hist_vals)
52+
histsum = sum(hist_vals)
53+
histsumsqr = sum(hist_vals.^2)
54+
hp = HistogramProto(first(edges), last(edges),
55+
num,
56+
histsum,
57+
histsumsqr,
58+
collect(edges[2:end]),
59+
hist_vals)
60+
return Summary_Value(name, name, nothing, OneOf(:histo, hp))
5661
end
5762

5863
# Writes to an Histogram summary the flattened version of the array.
5964
# Also stores the shape of the array as a field in a plugin, which allows to
6065
# reconstruct the original shape when read back into Julia
6166
function histogram_arr_summary(name::AbstractString, tensor::AbstractArray)
6267

63-
smpd = SummaryMetadata_PluginData(plugin_name=TB_PLUGIN_JLARRAY_NAME,
64-
content=reinterpret(UInt8, collect(size(tensor))))
65-
sm = SummaryMetadata(plugin_data=smpd)
66-
68+
smpd = SummaryMetadata_PluginData(TB_PLUGIN_JLARRAY_NAME, reinterpret(UInt8, collect(size(tensor))))
69+
sm = SummaryMetadata(smpd, name, "", DataClass.DATA_CLASS_TENSOR)
6770

68-
edges = collect(0:length(tensor))
69-
hp = HistogramProto(min=minimum(edges), max=maximum(edges),
70-
bucket_limit=edges[2:end],
71-
bucket=vec(tensor))
71+
num = length(tensor)
72+
edges = collect(0:num)
73+
histsum = sum(tensor)
74+
histsumsqr = sum(tensor.^2)
75+
hp = HistogramProto(minimum(edges), maximum(edges),
76+
num,
77+
histsum,
78+
histsumsqr,
79+
edges[2:end],
80+
vec(tensor))
7281

73-
return Summary_Value(tag=name, histo=hp, metadata=sm)
82+
return Summary_Value(name, name, sm, OneOf(:histo, hp))
7483
end

0 commit comments

Comments
 (0)