Wraps a segmentation / label mask, resampled with nearest mode.
Companion target for semantic / instance segmentation pipelines. Geometric transforms (flip / crop / resize / rotate) move the mask in lock-step with its image but always resample with nearest interpolation so class indices survive unblended; photometric transforms (colour-jitter, blur, ...) leave the mask untouched.
Parameters
dataTensorLabel / probability map with shape
(H, W), (C, H, W),
or (B, C, H, W). Integer dtypes are recommended for class
indices to preserve nearest-neighbour resampling exactly.Examples
Says a tensor is labels rather than a picture, which changes how it
is resampled — nearest-neighbour, so a class index is never
interpolated into one that does not exist:
>>> import lucid, lucid.utils.transforms as T
>>> holder = T.Mask(lucid.zeros(1, 32, 32))
>>> tuple(T.Resize(16, 16)(holder).data.shape)
(1, 16, 16)
A mask is (C, H, W) like an image — a bare (H, W) is refused
by name rather than guessed at, since a two-dimensional tensor could
as easily be a single channel or a batch of rows.