COCO Types
SUMMARY
Shared segmentation and return types used by the COCO datatypes.
Segmentation Types
COCORLESegmentation
TypedDict. Canonical representation of a compressed COCO Run-Length Encoding (RLE) segmentation.
This representation is used for internal storage and output.
| Field | Type | Description |
|---|---|---|
size | list[int] | Mask dimensions as [height, width]. |
counts | str | Compressed COCO RLE counts encoded as a UTF-8 string. |
COCOUncompressedRLESegmentation
TypedDict. Input representation of an uncompressed COCO RLE segmentation.
The counts field contains raw run lengths instead of a compressed string. During construction, this representation is converted to COCORLESegmentation.
| Field | Type | Description |
|---|---|---|
size | list[int] | Mask dimensions as [height, width]. |
counts | list[int] | Uncompressed COCO RLE counts as non-negative integers. |
COCORLESegmentationLike
Type alias:
COCORLESegmentation | COCOUncompressedRLESegmentationAccepted input form for segmentation and segmentations constructor parameters. Both compressed and uncompressed inputs are normalized to COCORLESegmentation during construction.
COCOPolygonSegmentation
Type alias:
list[list[float]]Canonical polygon segmentation representation. Each inner list contains the flattened coordinates of one polygon:
[x1, y1, x2, y2, ...]A segmentation may contain one or more polygons, and each polygon must contain at least three points. This representation is used for internal storage and returned by as_polygon() and as_polygons().
COCOPolygonSegmentationLike
Type alias:
Sequence[Sequence[float] | np.ndarray]Accepted input form for segmentation and segmentations constructor parameters. Polygon coordinates may be provided as lists, tuples, or NumPy arrays and are normalized to COCOPolygonSegmentation during 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, width, height] 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, width, height] format, or None. |
segmentation | COCOPolygonSegmentation | None | Segmentation extracted as polygon contours, or None if absent. |
COCOObjectDetectionResultsAsMasks
TypedDict. Return type of COCOObjectDetectionResults.as_masks().
Here, N is the number of detection results.
| 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, width, height] 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().
Here, N is the number of detection results.
| 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, width, height] format, or None. |
segmentations | list[COCOPolygonSegmentation | None] | Length-N list of polygon segmentations, 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, width, height] format. |
area | float | Annotation area, >= 0. |
iscrowd | bool | Whether the annotation represents a crowd region. |
segmentation | np.ndarray | None | Segmentation rasterized to a uint8 binary mask, or None if absent. |
COCOObjectDetectionAnnotationsAsMasks
TypedDict. Return type of COCOObjectDetectionAnnotations.as_masks().
Here, N is the number of annotations.
| 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, width, height] format. |
areas | np.ndarray | (N,) annotation areas, each >= 0. |
iscrowds | np.ndarray | (N,) flags indicating whether each annotation represents a crowd region. |
segmentations | list[np.ndarray | None] | Length-N list of uint8 binary masks, or None per entry without a segmentation. |

