.FastAI
AbstractBlockTask
abstract type
defined in module
FastAI
abstract type AbstractBlockTask <: LearningTask
Abstract supertype for learning tasks that derive their functionality from
Block
s and
Encoding
s.
These learning tasks require you only to specify blocks and encodings by defining which blocks of data show up at which stage of the pipeline. Generally, a subtype will have a field
blocks
of type
NamedTuple
that contains this information and a field
encodings
of encodings that are applied to samples. They can be accessed with
getblocks
and
getencodings
respectively. For example,
SupervisedTask
represents a learning task where each sample consists of an input and a target.
using
FastAI
,
FastVision
task
=
SupervisedTask
(
(
Image
{
2
}
(
)
,
Label
(
[
"
cat
"
,
"
dog
"
]
)
)
,
(
ImagePreprocessing
(
)
,
OneHot
(
)
,
)
)
FastAI
.
getblocks
(
task
)
(input = Image{2}(), target = Label{String}(["cat", "dog"]), sample = (Image{2}(), Label{String}(["cat", "dog"])), encodedsample = (FastVision.ImageTensor{2}(3), FastAI.OneHotTensor{0, String}(["cat", "dog"])), x = FastVision.ImageTensor{2}(3), y = FastAI.OneHotTensor{0, String}(["cat", "dog"]), ŷ = FastAI.OneHotTensor{0, String}(["cat", "dog"]), pred = Label{String}(["cat", "dog"]))
To implement a new
AbstractBlockTask
either
use the helper
BlockTask
(simpler)
or subtype
AbstractBlockTask
(allows customization through dispatch)
To support different learning task interfaces, a
AbstractBlockTask
's blocks need to contain different blocks. Below we list first block names with descriptions, and afterwards relevant interface functions and which blocks are required to use them.
Each name corresponds to a key of the named tuple
blocks = getblocks(task)
). A block is referred to with
blocks.$name
and an instance of data from a block is referred to as
$name
.
blocks.sample
: The most important block, representing one full observation of unprocessed data. Data containers used with a learning task should have compatible observations, i.e.
checkblock(blocks.sample, data[i])
.
blocks.x
: Data that will be fed into the model, i.e. (neglecting batching)
model(x)
should work
blocks.ŷ
: Data that is output by the model, i.e. (neglecting batching)
checkblock(blocks.ŷ, model(x))
blocks.y
: Data that is compared to the model output using a loss function, i.e.
lossfn(ŷ, y)
blocks.encodedsample
: An encoded version of
blocks.sample
. Will usually correspond to
encodedblockfilled(getencodings(task), blocks.sample)
.
Core:
encode
(task, ctx, sample)
requires
sample
. Also enables use of
taskdataset
,
taskdataloaders
decode
(task, ctx, encodedsample)
requires
encodedsample
decodeypred
(task, ctx, ŷ)
requires
ŷ
decodey
(task, ctx, y)
requires
y
Training:
taskmodel
(task)
requires
x
,
ŷ
tasklossfn
(task)
requires
y
,
ŷ
Visualization:
showsample
,
showsamples
require
sample
showencodedsample
,
showencodedsamples
,
showbatch
require
encodedsample
showsample
,
showsamples
require
sample
showoutput
,
showoutputs
,
showoutputbatch
require
ŷ
,
encodedsample
Testing:
mockmodel
(task)
requires
x
,
ŷ
mocksample
(task)
requires
sample
The following pages link back here:
datablock/task.jl , interpretation/learner.jl , interpretation/task.jl