Skip to content

COCO Types

SUMMARY

Shared segmentation and return types used by the COCO datatypes. Reference this page from datatypes that accept or return these types.

Segmentation Types

COCORLESegmentation

TypedDict. Canonical COCO RLE segmentation: an encoded Run-Length Encoding using the COCO representation, with size as [height, width] and counts as a UTF-8 string. This compressed form is always used for output and internal storage.

FieldTypeDescription
sizelist[int]Segmentation mask size as [height, width].
countsstrCompressed COCO RLE counts encoded as a UTF-8 string.

COCOUncompressedRLESegmentation

TypedDict. Uncompressed COCO RLE segmentation: the same representation with counts as raw run lengths instead of a compressed string. Accepted as input and automatically compressed to COCORLESegmentation.

FieldTypeDescription
sizelist[int]Segmentation mask size as [height, width].
countslist[int]Uncompressed COCO RLE counts as non-negative integers.

COCORLESegmentationLike

Type alias: COCORLESegmentation | COCOUncompressedRLESegmentation. Accepted input form for a segmentation/segmentations constructor parameter — either RLE variant is normalized to the canonical compressed COCORLESegmentation form on construction.

COCOPolygonSegmentation

Type alias: list[list[float]]. One or more polygons, each a flattened [x1, y1, x2, y2, ...] list of at least 3 points. This is the canonical, normalized polygon form returned by as_polygon()/as_polygons() and stored internally.

COCOPolygonSegmentationLike

Type alias: Sequence[Sequence[float] | np.ndarray]. Accepted input form for a segmentation/segmentations constructor parameter — a looser container (list, tuple, or np.ndarray) of polygons, each itself a list, tuple, or np.ndarray of coordinates, normalized to COCOPolygonSegmentation on construction.

Result Representations

COCOObjectDetectionResultAsMask

TypedDict. Return type of COCOObjectDetectionResult.as_mask().

FieldTypeDescription
image_idintSource image id.
category_idintCategory id.
image_heightintSource image height.
image_widthintSource image width.
scorefloatDetection confidence score.
bboxnp.ndarray | None(4,) float32 box in [x, y, w, h] format, or None.
segmentationnp.ndarray | NoneSegmentation rasterized to an (image_height, image_width) uint8 binary mask, or None if absent.

COCOObjectDetectionResultAsPolygon

TypedDict. Return type of COCOObjectDetectionResult.as_polygon().

FieldTypeDescription
image_idintSource image id.
category_idintCategory id.
image_heightintSource image height.
image_widthintSource image width.
scorefloatDetection confidence score.
bboxnp.ndarray | None(4,) float32 box in [x, y, w, h] format, or None.
segmentationCOCOPolygonSegmentation | NoneSegmentation extracted as polygon contours, or None if absent.

COCOObjectDetectionResultsAsMasks

TypedDict. Return type of COCOObjectDetectionResults.as_masks().

FieldTypeDescription
image_idsnp.ndarray(N,) source image ids.
category_idsnp.ndarray(N,) category ids.
image_heightsnp.ndarray(N,) source image heights.
image_widthsnp.ndarray(N,) source image widths.
scoresnp.ndarray(N,) detection confidence scores.
bboxesnp.ndarray | None(N, 4) float32 boxes in [x, y, w, h] format, or None.
segmentationslist[np.ndarray | None]Length-N list of uint8 binary masks, or None per entry without a segmentation.

COCOObjectDetectionResultsAsPolygons

TypedDict. Return type of COCOObjectDetectionResults.as_polygons().

FieldTypeDescription
image_idsnp.ndarray(N,) source image ids.
category_idsnp.ndarray(N,) category ids.
image_heightsnp.ndarray(N,) source image heights.
image_widthsnp.ndarray(N,) source image widths.
scoresnp.ndarray(N,) detection confidence scores.
bboxesnp.ndarray | None(N, 4) float32 boxes in [x, y, w, h] format, or None.
segmentationslist[COCOPolygonSegmentation | None]Length-N list of polygon contours, or None per entry without a segmentation.

Annotation Representations

COCOObjectDetectionAnnotationAsMask

TypedDict. Return type of COCOObjectDetectionAnnotation.as_mask().

FieldTypeDescription
idintAnnotation id.
image_idintSource image id.
category_idintCategory id.
bboxnp.ndarray(4,) float32 box in [x, y, w, h] format.
areafloatAnnotation area, >= 0.
iscrowdboolCrowd flag; selected the rasterization path.
segmentationnp.ndarray | NoneSegmentation rasterized to a binary mask, or None if absent.

COCOObjectDetectionAnnotationsAsMasks

TypedDict. Return type of COCOObjectDetectionAnnotations.as_masks().

FieldTypeDescription
idsnp.ndarray(N,) annotation ids.
image_idsnp.ndarray(N,) source image ids.
category_idsnp.ndarray(N,) category ids.
bboxesnp.ndarray(N, 4) float32 boxes in [x, y, w, h] format.
areasnp.ndarray(N,) annotation areas, each >= 0.
iscrowdsnp.ndarray(N,) crowd flags; selected each entry's rasterization path.
segmentationslist[np.ndarray | None]Length-N list of binary masks, or None per entry without a segmentation.