Visualizing the data we're working with is indispensible both to check that data pipelines are set up correctly and to check the predictions of a trained model. For visualization, the Makie.jl plotting package is used which requires you to install a plotting backend . Learning tasks define how the data is visualized, allowing you to use the following functions for visualization:
showsample
(
showsamples
): Visualize an unprocessed sample (usually a pair of inputs and targets) or a vector of samples.
showencodedsample
(
showbatch
): Visualize processed model input and output
x, y
or a batch of
xs
and
ys
.
showprediction
(
showpredictions
): Compare a model output with the ground truth.
To add support for these to a learning task, you have to implement the plotting interface for a block:
showblock!
.
Let's look at an example using the Cat/Dog classifier from the saving and loading tutorial.
import
CairoMakie
;
CairoMakie
.
activate!
(
type
=
"
png
"
)
using
FastAI
task
,
model
=
loadtaskmodel
(
"
catsdogs.jld2
"
)
dir
=
joinpath
(
load
(
datasets
(
)
[
"
dogscats
"
]
)
,
"
train
"
)
data
=
loadfolderdata
(
dir
,
filterfn
=
isimagefile
,
loadfn
=
(
loadfile
,
parentname
)
)
(mapobs(loadfile, ["/home/lorenz/.julia/datadeps/fastai-dogscats/dogscats/train/cats/cat.0.jpg", "…]), mapobs(parentname, ["/home/lorenz/.julia/datadeps/fastai-dogscats/dogscats/train/cats/cat.0.jpg", "…]))
First we load a vector of unprocessed samples, a batch of training data and the corresponding model outputs:
idxs
=
rand
(
1
:
numobs
(
data
)
,
9
)
samples
=
[
getobs
(
data
,
i
)
for
i
in
idxs
]
xs
,
ys
=
makebatch
(
task
,
data
,
idxs
)
ŷs
=
gpu
(
model
)
(
gpu
(
xs
)
)
|>
cpu
2×9 Matrix{Float32}:
2.81113 -2.68682 4.27251 -4.39263 … 2.25726 -2.52003 -4.23501
-1.4409 0.872713 -4.20728 2.1302 -1.23509 1.5162 3.21313
Then we can visualize the data with the functions listed above:
showsamples
(
task
,
samples
)
showbatch
(
task
,
xs
,
ys
)
showpredictions
(
task
,
xs
,
ŷs
,
ys
)