Skip to content

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.

FieldTypeDescription
sizelist[int]Mask dimensions as [height, width].
countsstrCompressed 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.

FieldTypeDescription
sizelist[int]Mask dimensions as [height, width].
countslist[int]Uncompressed COCO RLE counts as non-negative integers.

COCORLESegmentationLike

Type alias:

python
COCORLESegmentation | COCOUncompressedRLESegmentation

Accepted input form for segmentation and segmentations constructor parameters. Both compressed and uncompressed inputs are normalized to COCORLESegmentation during construction.

COCOPolygonSegmentation

Type alias:

python
list[list[float]]

Canonical polygon segmentation representation. Each inner list contains the flattened coordinates of one polygon:

python
[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:

python
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().

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, width, height] 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, width, height] format, or None.
segmentationCOCOPolygonSegmentation | NoneSegmentation extracted as polygon contours, or None if absent.

COCOObjectDetectionResultsAsMasks

TypedDict. Return type of COCOObjectDetectionResults.as_masks().

Here, N is the number of detection results.

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, width, height] 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().

Here, N is the number of detection results.

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, width, height] format, or None.
segmentationslist[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().

FieldTypeDescription
idintAnnotation ID.
image_idintSource image ID.
category_idintCategory ID.
bboxnp.ndarray(4,) float32 box in [x, y, width, height] format.
areafloatAnnotation area, >= 0.
iscrowdboolWhether the annotation represents a crowd region.
segmentationnp.ndarray | NoneSegmentation 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.

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, width, height] format.
areasnp.ndarray(N,) annotation areas, each >= 0.
iscrowdsnp.ndarray(N,) flags indicating whether each annotation represents a crowd region.
segmentationslist[np.ndarray | None]Length-N list of uint8 binary masks, or None per entry without a segmentation.