pytorchcocotools.internal.mask_api.rle_encode
source module pytorchcocotools.internal.mask_api.rle_encode
Functions
-
rleEncode — Encode binary masks using RLE.
source rleEncode(mask: Annotated[tv.Mask, 'N H W'], *, device: TorchDevice | None = None, requires_grad: bool = False) → RLEs
Encode binary masks using RLE.
Uses vectorized transition detection with batch-first layout to avoid expensive argsort. Transitions are computed on [N, H*W] so nonzero() returns pairs already sorted by (mask_id, position).
Parameters
-
mask : Annotated[tv.Mask, 'N H W'] — The binary masks to encode.
-
device : TorchDevice | None — The desired device of the bounding boxes.
-
requires_grad : bool — Whether the bounding boxes require gradients.
Returns
-
RLEs — Run length encoded masks.