Better visualization/interpretation API #154
Labels
api-proposal
Implementation or suggestion for new APIs and improvements to existing APIs
enhancement
New feature or request
The block plotting API can be improved. Right now, it is
Based on blocks we should be able to create an interface that is backend-agnostic (i.e. plot with Makie.jl, show as text, or as image) and usable for different tasks.
Backend-agnostic interface
The backend-agnostic functions are prefixed with
show
- andshowsample(method, sample)
: Show an unencoded sample.showprediction(method, input, targetpred)
: Show ashowxy(method, x, y)
: Show an encoded sample, decoded until interpretableshowoutput(method, x, y, output)
: Show an encoded sample and a model output, decoded until interpretableFor every function, there is a version that shows multiples, i.e. a vector of unencoded data or a collated batch of encoded data:
showsamples
,showpredictions
,showxys
/showbatch
,showoutputs
The corresponding blocks (e.g. what makes up a
sampleblock
) can be derived from the learning method. The high-level function are all lowered to the genericshowblock(display, block, data)
. For example,showsample(method, sample)
will lower to `showblock(display, method, sampleblock, sample).Here,
display
is a backend for showing. Possible backends are:Block types implement a method that indicates that they support a backend. A backend is then automatically chosen given all block types and considering
Concrete examples
To give some context, let's take an image classification learning method as an example. Here we have
sample = (image, label)
andsampleblock = (Image{2}(), Label(classes))
.showsample(method, sample)
hence callsshowblock(display, (Image{2}(), Label(classes)), (image, label))
display
here will be the Makie backend, as it bothImage
andLabel
should be showable through Makie.showblock(::MakieBackend, ::Tuple{<:Image, <:Label}, _)
we could implement a method where the label is put as a title instead of having its own axis. Same logic applies for a segmentation task where the mask could be drawn over an image.showxy
callsshowblockinterpretable(encodings, (ImageTensor{2}(3), OneHotTensor{0}(classes)), (x, y))
ImageTensor
is not interpretable by itself and is decoded back into anImage
OneHotTensor
could be decoded back into aLabel
and rendered as text, or ashowblock
could be defined forOneHotTensor{0}
that visualizes it as a barplot of probabilities/logits.showblockinterpretable
then defers toshowblock(display, (Image{2}(), OneHotTensor{0}(classes)), (imagedecoded, y))
Backends
A Makie backend that plots data and creates static figures akin to the current
plot*
functionsA text backend that draws to a terminal, using fancy printing packages like PrettyTables.jl, ImageInTerminal.jl and UnicodePlots.jl
A interactive Makie backend that augments the figure with interactive sliders, e.g. to show slices of a heatmap or such. Probably out of scope for FastAI.jl itself but could be an extension package.
The text was updated successfully, but these errors were encountered: