Skip to content

Commit fe1276a

Browse files
oxinaboxPhilipVinc
authored andcommitted
Add SummaryCollection constructors that take the summaries (#26)
* Add SummaryCollection constructors that take the summaries * use new SummaryCollecton constructor
1 parent 2d1ed9e commit fe1276a

File tree

5 files changed

+9
-13
lines changed

5 files changed

+9
-13
lines changed

src/Loggers/LogHistograms.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ be used to bin the data.
1010
function log_histogram(logger::TBLogger, name::AbstractString, (bins,weights)::Tuple{AbstractVector, AbstractArray};
1111
step=nothing)
1212
weights = collect(vec(weights))
13-
summ = SummaryCollection()
14-
push!(summ.value, histogram_summary(name, collect(bins), weights))
13+
summ = SummaryCollection(histogram_summary(name, collect(bins), weights))
1514
write_event(logger.file, make_event(logger, summ, step=step))
1615
end
1716

@@ -24,9 +23,8 @@ Bins the values found in `data` and logs them as an histogram under the tag
2423
function log_histogram(logger::TBLogger, name::AbstractString, data::AbstractArray;
2524
step=nothing)
2625
data = vec(data)
27-
summ = SummaryCollection()
2826
hvals = fit(Histogram, data)
29-
push!(summ.value, histogram_summary(name, collect(hvals.edges[1]), hvals.weights))
27+
summ = SummaryCollection(histogram_summary(name, collect(hvals.edges[1]), hvals.weights))
3028
write_event(logger.file, make_event(logger, summ, step=step))
3129
end
3230

@@ -36,8 +34,7 @@ end
3634
Logs the vector found in `data` as an histogram under the name `name`.
3735
"""
3836
function log_vector(logger::TBLogger, name::AbstractString, data::AbstractVector; step=nothing)
39-
summ = SummaryCollection()
40-
push!(summ.value, histogram_summary(name, collect(0:length(data)),data))
37+
summ = SummaryCollection(histogram_summary(name, collect(0:length(data)),data))
4138
write_event(logger.file, make_event(logger, summ, step=step))
4239
end
4340

src/Loggers/LogImage.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ function log_image(logger::TBLogger, name::AbstractString, imgArray::AbstractArr
170170
end
171171
)
172172
imgArray = formatdict[format](imgArray)
173-
summ = SummaryCollection()
174-
push!(summ.value, image_summary(name, imgArray))
173+
summ = SummaryCollection(image_summary(name, imgArray))
175174
write_event(logger.file, make_event(logger, summ, step=step))
176175
end
177176

src/Loggers/LogText.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Logs text with name `name` at step `step`
55
- 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
66
"""
77
function log_text(logger::TBLogger, name::String, text::Any; step = nothing)
8-
summ = SummaryCollection()
9-
push!(summ.value, text_summary(name, text))
8+
summ = SummaryCollection(text_summary(name, text))
109
write_event(logger.file, make_event(logger, summ, step=step))
1110
end
1211

src/Loggers/LogValue.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
Logs a Floating-point variable with name `name` at step `step`
55
"""
66
function log_value(logger::TBLogger, name::AbstractString, value::Real; step=nothing)
7-
summ = SummaryCollection()
8-
push!(summ.value, scalar_summary(name, value))
7+
summ = SummaryCollection(scalar_summary(name, value))
98
write_event(logger.file, make_event(logger, summ, step=step))
109
end
1110

src/event.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Create summary for Summary_value (default constructor by
22
# protobuf is broken).
3-
const SummaryCollection(;kwargs...) = Summary(value=Base.Vector{Summary_Value}(); kwargs...)
3+
SummaryCollection(;kwargs...) = Summary(value=Vector{Summary_Value}(); kwargs...)
4+
SummaryCollection(summaries::Vector{Summary_Value}; kwargs...) = Summary(value=summaries; kwargs...)
5+
SummaryCollection(summary::Summary_Value; kwargs...) = Summary(value=[summary]; kwargs...)
46

57
function make_event(logger::TBLogger, summary::Summary;
68
step::Int=TensorBoardLogger.step(logger))

0 commit comments

Comments
 (0)