Skip to content

Commit 182d691

Browse files
Shashikant KadamPhilipVinc
authored andcommitted
add support for 1-D and 3-D images, Logger interface, TBImage Wrapper, Tests, Examples (#24)
* add matrix and list support to log_text * add support for 1-D images in `log_image` * add ImageFormat explanation * add seperate function for image objects * add more formats change flow of data different `image_summary` for image object and AbstractArrays * add preprocess function for image objects for automatic dispatch * add TBImage, TBImages wrapper * add tests * add support for 3-d images such as mri * add more tests * add examples folder * syntax revision * change if else to function dispatch `image_summary` * major revision `log_image` smart use of ImageFormats * change throw message
1 parent fe1276a commit 182d691

File tree

9 files changed

+368
-195
lines changed

9 files changed

+368
-195
lines changed

examples/Histograms.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using TensorBoardLogger #import the TensorBoardLogger package
2+
using Logging #import Logging package
3+
4+
logger = TBLogger("histogramlogs", tb_append) #create tensorboard logger
5+
6+
################log histogram example:################
7+
#using logger interface
8+
with_logger(logger) do
9+
for i in 1:100
10+
x0 = 0.5+i/30; s0 = 0.5/(i/20);
11+
edges = collect(-5:0.1:5)
12+
centers = collect(edges[1:end-1] .+0.05)
13+
histvals = [exp(-((c-x0)/s0)^2) for c = centers]
14+
data_tuple = (edges, histvals)
15+
@info "histogram/loggerinterface" autobin=rand(10).+0.1*i manualbin=data_tuple
16+
end
17+
end
18+
19+
#using explicit function interface
20+
for i in 1:100
21+
x0 = 0.5+i/30; s0 = 0.5/(i/20);
22+
edges = collect(-5:0.1:5)
23+
centers = collect(edges[1:end-1] .+0.05)
24+
histvals = [exp(-((c-x0)/s0)^2) for c = centers]
25+
data_tuple = (edges, histvals)
26+
log_histogram(logger, "histogram/explicitinterface/autobin", rand(10).+0.1*i, step = i) #automatic bins
27+
log_histogram(logger, "histogram/explicitinterface/manualbin", data_tuple, step = i) #manual bins
28+
end

examples/Images.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using TensorBoardLogger #import the TensorBoardLogger package
2+
using Logging #import Logging package
3+
using TestImages
4+
using Flux: Data
5+
using Random
6+
logger = TBLogger("imagelogs", tb_append) #create tensorboard logger
7+
8+
################log images example: mri################
9+
mri = testimage("mri")
10+
11+
#using logger interface
12+
with_logger(logger) do
13+
@info "image/mri/loggerinterface" mri
14+
end
15+
#using explicit function interface
16+
log_image(logger, "image/mri/explicitinterface", mri, step = 0)
17+
18+
19+
################log images example: MNIST data################
20+
images = shuffle(Data.MNIST.images())[1:5]
21+
22+
#using logger interface
23+
with_logger(logger) do
24+
@info "image/mnist/loggerinterface" images = TBImages(images, HW)
25+
end
26+
#using explicit function interface
27+
log_images(logger, "image/mnist/explicitinterface", images, step = 0)
28+
29+
30+
################log images example: random arrays################
31+
noise = rand(16, 16, 3, 4) #Format is HWCN
32+
33+
#using logger interface
34+
with_logger(logger) do
35+
@info "image/noise/loggerinterface" random = TBImage(noise, HWCN)
36+
end
37+
#using explicit function interface
38+
log_image(logger, "image/noise/explicitinterface", noise, HWCN, step = 0)

examples/Scalars.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using TensorBoardLogger #import the TensorBoardLogger package
2+
using Logging #import Logging package
3+
4+
logger = TBLogger("scalarlogs", tb_append) #create tensorboard logger
5+
6+
################log scalars example: y = x²################
7+
#using logger interface
8+
with_logger(logger) do
9+
for x in 1:20
10+
@info "scalar/loggerinterface" y = x*x
11+
end
12+
end
13+
#using explicit function interface
14+
for x in 1:20
15+
log_value(logger, "scalar/explicitinterface", x*x, step = x)
16+
end
17+
18+
19+
################log scalar example: y = x-xi################
20+
with_logger(logger) do
21+
for x in 1:10
22+
z = x-x*im
23+
@info "scalar/complex" y = z
24+
end
25+
end

0 commit comments

Comments
 (0)