Skip to content

Commit 08f57d8

Browse files
authored
Support Plots.jl plots (#42)
* Remove lightgraphs dependency and use Requires.jl ( fix #39 ) * Add Plots support * Add PyPlot support * Replace all `log_image(s)` methods with a common one, that internally use all our preprocess machinery (should use it for everything else too) * move LogGraph to Optional folder * BugFix: log_***(step=nothing) gave errors * Update travis to Test on latest julia * Docs
1 parent a8f4a27 commit 08f57d8

25 files changed

+448
-177
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ os:
44
- linux
55
julia:
66
- 1.0
7-
- 1.1
7+
- 1
88
- nightly
99
matrix:
1010
allow_failures:

Project.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ CRC32c = "8bf52ea8-c179-5cab-976a-9e18b702a9bc"
88
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
99
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
1010
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
11-
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1211
ProtoBuf = "3349acd9-ac6a-5e09-bcdb-63829b23a429"
12+
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1313
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1414

1515
[compat]
@@ -20,10 +20,13 @@ julia = "0.7, 1"
2020
[extras]
2121
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
2222
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
23+
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
2324
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
25+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
26+
PyPlot="d330b81b-6aea-500a-939a-2ce795aea3ee"
2427
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2528
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
2629
WAV = "8149f6b0-98f6-5db9-b78f-408fbbb8ef88"
2730

2831
[targets]
29-
test = ["Test", "Flux", "TestImages", "ImageMagick", "Logging", "WAV"]
32+
test = ["Test", "Flux", "TestImages", "ImageMagick", "Logging", "LightGraphs", "Plots", "PyPlot", "WAV"]

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ To install run the following command in the julia REPL:
1616
] add TensorBoardLogger
1717
```
1818

19-
To also enable support for Images, also install `ImageMagick`
19+
If you need to log Images, you must also install `ImageMagick`
20+
(on MacOS, you will also need `QuartzImageIO`).
2021
```
2122
] add ImageMagick
2223
```
@@ -34,6 +35,14 @@ logger in Julia:
3435
- You can set it to be the current logger in a scope with the function [`with_logger`](https://docs.julialang.org/en/v1/stdlib/Logging/index.html#Base.CoreLogging.with_logger)
3536
- You can combine it with other Loggers using [LoggingExtras.jl](https://github.com/oxinabox/LoggingExtras.jl), so that messages are logged to TensorBoard and to other backends at the same time.
3637

38+
You can log to TensorBoard any type. Numeric types will be logged as scalar,
39+
arrays will be binned into histograms, images and audio will be logged as such,
40+
and we even support [Plots](https://github.com/JuliaPlots/Plots.jl) and
41+
[PyPlot](https://github.com/JuliaPlots/Plots.jl) figures!
42+
43+
For details about how types are logged by default, or how to customize this behaviour for your custom types,
44+
refer to the documentation or the examples folder.
45+
3746
```julia
3847
using TensorBoardLogger, Logging, Random
3948

@@ -59,6 +68,10 @@ with_logger(lg) do
5968
end
6069
```
6170

71+
## Integration with third party packages
72+
We also support native logging of the types defined by a few third-party packages, such as `Plots` and `PyPlot` plots.
73+
If there are other libraries that you think we should include in the list, please open an issue.
74+
6275
## Roadmap
6376
Support for Computational Graphs is currently planned and partly implemented.
6477

docs/make.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ makedocs(
88
pages = [
99
"Home" => "index.md",
1010
"Manual" => Any[
11-
"Basics" => "index.md",
12-
"Backends" => "custom_behaviour.md",
13-
"Extending" => "extending_behaviour.md"
11+
"Backends" => "custom_behaviour.md",
12+
"Extending" => "extending_behaviour.md",
13+
"Explicit Interface" => "explicit_interface.md"
1414
],
1515
"Examples" => Any[
1616
"Optim.jl" => "examples/optim.md"

docs/src/custom_behaviour.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ parameters. For example, to log a vector as text you can do the following:
2626
@info "mytag" TBText([1,2,3])
2727
```
2828

29-
3029
```@docs
3130
TBText
3231
TBHistogram

docs/src/explicit_interface.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Explicit interface
2+
3+
in addition to the standard logging interface, it is possible to log
4+
data to TensorBoard using the functions documented below.
5+
All the functions accept take as first argument a `TBLogger` object
6+
and as the second argument a `String` as the tag under which the
7+
data will be logged.
8+
9+
# Scalar backend
10+
```@docs
11+
log_value
12+
```
13+
14+
# Distributions backend
15+
```@docs
16+
log_histogram
17+
log_vector
18+
```
19+
20+
# Text backend
21+
```@docs
22+
log_text
23+
```
24+
25+
# Images backend
26+
```@docs
27+
log_image
28+
log_images
29+
```
30+
31+
# Audio backend
32+
```@docs
33+
log_audio
34+
log_audios
35+
```

docs/src/index.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ To install this Julia package run the following command in the julia REPL:
1515
```
1616

1717
!!! note
18-
To log images to the *Image* backend of TensorBoard you must also install
19-
`ImageMagick`. You won't need to import it.
18+
If you need to log Images, you must also install `ImageMagick`
19+
(on MacOS, you will also need `QuartzImageIO`).
20+
You only need to install those dependencies, and you will never need to load them.
2021
```
2122
] add ImageMagick
2223
```
@@ -41,10 +42,17 @@ there already exhist a document at the given path.
4142

4243
Once you have created a `TBLogger`, you can use it as you would use any other
4344
logger in Julia:
44-
- You can set it to be your global logger with the function [`global_logger`](https://docs.julialang.org/en/v1/stdlib/Logging/index.html#Base.CoreLogging.global_logger)
45-
- You can set it to be the current logger in a scope with the function [`with_logger`](https://docs.julialang.org/en/v1/stdlib/Logging/index.html#Base.CoreLogging.with_logger)
46-
- You can combine it with other Loggers using [LoggingExtras.jl](https://github.com/oxinabox/LoggingExtras.jl), so that messages are logged to TensorBoard and to other backends at the same time.
45+
- You can set it to be your global logger with the function [`global_logger`](https://docs.julialang.org/en/v1/stdlib/Logging/index.html#Base.CoreLogging.global_logger)
46+
- You can set it to be the current logger in a scope with the function [`with_logger`](https://docs.julialang.org/en/v1/stdlib/Logging/index.html#Base.CoreLogging.with_logger)
47+
- You can combine it with other Loggers using [LoggingExtras.jl](https://github.com/oxinabox/LoggingExtras.jl), so that messages are logged to TensorBoard and to other backends at the same time.
4748

49+
Every `TBLogger` has an internal counter to store the current `step`, which is initially set to `1`. All the data logged with the same `@log` call will be logged with the same step, and then
50+
it will increment the internal counter by 1.
51+
52+
If you want to increase the counter by a different amount, or prevent it from increasing, you can log the additional message
53+
`log_step_increment=N`. The default behaviour corresponds to `N=1`. If you set `N=0` the internal counter will not be modified.
54+
55+
See the example below:
4856
```julia
4957
using TensorBoardLogger, Logging, Random
5058

@@ -92,8 +100,13 @@ how to specify a desired backend refer to [Specifying a backend](@ref).
92100
If you want to define a new default behaviour for a custom type refer to section
93101
[Extending TensorBoardLogger](@ref).
94102

103+
## Third-party packages
104+
We also support logging custom types from a the following third-party libraries:
105+
- [Plots.jl](https://github.com/JuliaPlots/Plots.jl): the `Plots.Plot` type will be rendered to PNG at the resolution specified by the object and logged as an image
106+
- [PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl): the `PyPlot.Figure` type will be rendered to PNG at the resolution specified by the object and logged as an image
107+
95108
## Explicit logging
96109

97110
In alternative, you can also log data to TensorBoard through it's functional interface,
98111
by calling the relevant method with a tag string and the data. For information
99-
on this interface refer to @ref()...
112+
on this interface refer to [Explicit interface]@ref()...

src/ImageFormat.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Note: we use the 100s place of the enum to represent the number of dimensions
2+
# And the 10s place to represent which dimension is the observation (N), 0 for no observation dimension
3+
@enum ImageFormat begin
4+
L=100;
5+
CL=200; LC; HW; WH; NL=210; LN=220;
6+
HWC=300; WHC; CHW; CWH; NCL=310; NHW; NWH; NLC; CLN=330; LCN; HWN; WHN;
7+
NHWC=410; NWHC; NCHW; NCWH; HWCN=440; WHCN; CHWN; CWHN;
8+
end
9+
10+
expected_ndims(x::ImageFormat) = Int(x) ÷ 100 # get the 100's digit
11+
obs_dim(x::ImageFormat) = (Int(x) % 100) ÷ 10 # get the 10's digit
12+
const strip_obs = Dict(
13+
NL=>L, LN=>L, NCL=>CL, CLN=>CL, NLC=>LC, LCN=>LC,
14+
NHW=>HW, HWN=>HW, NWH=>WH, WHN=>WH,
15+
NHWC=>HWC, NWHC=>WHC, NCHW=>CHW, NCWH=>CWH, HWCN=>HWC, WHCN=>WHC, CHWN=>CHW, CWHN=>CWH
16+
)

src/Loggers/LogAudio.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
log_audios(logger::TBLogger, name::AbstractString, samples::AbstractArray, samplerate::Real, step)
2+
log_audios(logger::TBLogger, name::AbstractString, samples::AbstractArray, samplerate::Real; step=step(logger))
33
44
Logs multiple audio clips at step `step`
55
- samples:
@@ -12,7 +12,7 @@ function log_audios(logger::TBLogger, name::AbstractString, samplesArray::Abstra
1212
end
1313
end
1414
"""
15-
log_audio(logger::TBLogger, name::AbstractString, samples::AbstractArray, samplerate::Real, step)
15+
log_audio(logger::TBLogger, name::AbstractString, samples::AbstractArray, samplerate::Real; step=step(logger))
1616
1717
Logs an audio clip with name `name` at step `step`
1818
- samples: Array of samples N*C where N = number of samples and C = number of channels

src/Loggers/LogHistograms.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
log_histogram(logger, name, (bins,weights); step)
2+
log_histogram(logger, name, (bins,weights); step=step(logger))
33
44
Logs a histogram under the tag `name` on given `step`. The histogram must be
55
passed as a tuple holding the `N+1` bin edges and the height of the `N` bins.
@@ -15,7 +15,7 @@ function log_histogram(logger::TBLogger, name::AbstractString, (bins,weights)::T
1515
end
1616

1717
"""
18-
log_histogram(logger, name, data::Vector; step)
18+
log_histogram(logger, name, data::Vector; step=step(logger))
1919
2020
Bins the values found in `data` and logs them as an histogram under the tag
2121
`name`.
@@ -29,7 +29,7 @@ function log_histogram(logger::TBLogger, name::AbstractString, data::AbstractArr
2929
end
3030

3131
"""
32-
log_vector(logger, name, data::Vector; step)
32+
log_vector(logger, name, data::Vector; step=step(logger))
3333
3434
Logs the vector found in `data` as an histogram under the name `name`.
3535
"""

0 commit comments

Comments
 (0)