Skip to content
class

Segmentation

extendsTransformsPreset
Segmentation(crop_size: int | None = None, resize_size: int = 520, mean: tuple[float, ...] | None = None, std: tuple[float, ...] | None = None, interpolation: str | Interpolation = Interpolation.BILINEAR, stretch: bool = False)

Semantic-segmentation preset — image + mask share geometry.

Pipeline: shorter side to resize_size (the reference's rule: the longer side truncated) → CenterCrop(crop_size) → Normalize applied to the image only, or — with stretch=True — Resize(resize_size, resize_size) → Normalize, which is what an upstream processor configured with an explicit (height, width) pair does. The image is low-pass filtered as it shrinks, either way. Mask travels through the geometric stages with nearest-neighbour interpolation (label preservation guaranteed by every lucid.utils.transforms._base.GeometricTransform's _apply_mask hook) and is not normalised.

Parameters

crop_sizeint= None
Square crop fed to the model.
resize_sizeint= 520
Shorter-side length before cropping; canonical for FCN / DeepLab style recipes.
meantuple of float= None
Per-channel normalization stats; default ImageNet.
stdtuple of float= None
Per-channel normalization stats; default ImageNet.
interpolationstr or Interpolation= "bilinear"
Image resize interpolation. Masks always use nearest.
stretchbool= False
Resize to exactly resize_size x resize_size and skip the crop, distorting the aspect ratio — for checkpoints whose upstream processor names an explicit (height, width). Reproducing those with shortest-edge and centre-crop frames the image differently from how the model was evaluated.

Examples

>>> import lucid, lucid.utils.transforms as T
>>> tf = T.Segmentation()
>>> tuple(tf(T.Image(lucid.rand(3, 32, 32))).data.shape)
(3, 520, 520)
A preset. The mask travels with the image and is resampled with
nearest-neighbour so a label is never interpolated into one that
does not exist.

Used by 1

Constructors

1
dunder

__init__

→None
__init__(crop_size: int | None = None, resize_size: int = 520, mean: tuple[float, ...] | None = None, std: tuple[float, ...] | None = None, interpolation: str | Interpolation = Interpolation.BILINEAR, stretch: bool = False)