public
encode
— function
encode(method, context, sample) -> (x, y)
encode(method, context, (input, target)) -> (x, y)
Encode a sample
containing both input and target.
If sample
is a Tuple
of (input, target), the default behavior is to
pass them to encodeinput
and encodetarget
.
Remarks
-
When should I implement
encode
vs.encodeinput
andencodetarget
?In simple cases like image classification we can encode the inputs and targets separately and you should prefer
encodeinput
andencodetarget
. The default implementation forencode
when given an(input, target)
-tuple is to delegate toencodeinput
andencodetarget
.In other cases like semantic segmentation, however, we want to apply stochastic augmentations to both image and segmentation mask. In that case you need to encode both at the same time using
encode
.Another situation where
encode
is needed is whensample
is not a tuple of(input, target)
, for example aDict
that includes additional information.encode
still needs to return an(x, y)
-tuple, though.