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.
| Field | Type | Description |
|---|---|---|
size | list[int] | Segmentation mask size as [height, width]. |
counts | str | Compressed 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.
| Field | Type | Description |
|---|---|---|
size | list[int] | Segmentation mask size as [height, width]. |
counts | list[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().
| Field | Type | Description |
|---|---|---|
image_id | int | Source image id. |
category_id | int | Category id. |
image_height | int | Source image height. |
image_width | int | Source image width. |
score | float | Detection confidence score. |
bbox | np.ndarray | None | (4,) float32 box in [x, y, w, h] format, or None. |
segmentation | np.ndarray | None | Segmentation rasterized to an (image_height, image_width) uint8 binary mask, or None if absent. |
COCOObjectDetectionResultAsPolygon
TypedDict. Return type of COCOObjectDetectionResult.as_polygon().
| Field | Type | Description |
|---|---|---|
image_id | int | Source image id. |
category_id | int | Category id. |
image_height | int | Source image height. |
image_width | int | Source image width. |
score | float | Detection confidence score. |
bbox | np.ndarray | None | (4,) float32 box in [x, y, w, h] format, or None. |
segmentation | COCOPolygonSegmentation | None | Segmentation extracted as polygon contours, or None if absent. |
COCOObjectDetectionResultsAsMasks
TypedDict. Return type of COCOObjectDetectionResults.as_masks().
| Field | Type | Description |
|---|---|---|
image_ids | np.ndarray | (N,) source image ids. |
category_ids | np.ndarray | (N,) category ids. |
image_heights | np.ndarray | (N,) source image heights. |
image_widths | np.ndarray | (N,) source image widths. |
scores | np.ndarray | (N,) detection confidence scores. |
bboxes | np.ndarray | None | (N, 4) float32 boxes in [x, y, w, h] format, or None. |
segmentations | list[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().
| Field | Type | Description |
|---|---|---|
image_ids | np.ndarray | (N,) source image ids. |
category_ids | np.ndarray | (N,) category ids. |
image_heights | np.ndarray | (N,) source image heights. |
image_widths | np.ndarray | (N,) source image widths. |
scores | np.ndarray | (N,) detection confidence scores. |
bboxes | np.ndarray | None | (N, 4) float32 boxes in [x, y, w, h] format, or None. |
segmentations | list[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().
| Field | Type | Description |
|---|---|---|
id | int | Annotation id. |
image_id | int | Source image id. |
category_id | int | Category id. |
bbox | np.ndarray | (4,) float32 box in [x, y, w, h] format. |
area | float | Annotation area, >= 0. |
iscrowd | bool | Crowd flag; selected the rasterization path. |
segmentation | np.ndarray | None | Segmentation rasterized to a binary mask, or None if absent. |
COCOObjectDetectionAnnotationsAsMasks
TypedDict. Return type of COCOObjectDetectionAnnotations.as_masks().
| Field | Type | Description |
|---|---|---|
ids | np.ndarray | (N,) annotation ids. |
image_ids | np.ndarray | (N,) source image ids. |
category_ids | np.ndarray | (N,) category ids. |
bboxes | np.ndarray | (N, 4) float32 boxes in [x, y, w, h] format. |
areas | np.ndarray | (N,) annotation areas, each >= 0. |
iscrowds | np.ndarray | (N,) crowd flags; selected each entry's rasterization path. |
segmentations | list[np.ndarray | None] | Length-N list of binary masks, or None per entry without a segmentation. |

