COCO annotation format
One JSON file per dataset: images, annotations and categories, with boxes in pixels, polygon or RLE segmentation, keypoints and captions.
- Data
- Images
- Labels
- BoxesPolygonsMasksKeypointsCaptions
- Files
.json- Import / export
- Yes / Yes
What is the COCO format?
COCO is the annotation format of the COCO (Common Objects in Context) dataset. A dataset is a single JSON file with the keys info, licenses, images, annotations and categories. Every annotation points to its image with image_id and to its class with category_id.
An object has a bbox as [x, y, width, height] in pixels and a segmentation: a list of polygon vertices, or a run-length-encoded (RLE) mask, which COCO uses for groups of objects (iscrowd: 1). Keypoint annotations add keypoints as x, y, v triplets, where v is 0 (not labeled), 1 (labeled, not visible) or 2 (labeled and visible); their category names the points and lists the skeleton edges. Captions are annotations with a caption string and no category.
Folder structure and an example
project
└── dataset
├── annotations
│ └── instances.json
└── images
├── 0001.png
├── 0002.png
└── 0003.png{
"images": [
{ "id": 1, "file_name": "IMG_1836.jpeg", "width": 1067, "height": 800 }
],
"annotations": [
{
"id": 1,
"image_id": 1,
"category_id": 2,
"bbox": [752.0, 421.0, 257.0, 167.0],
"segmentation": [[752.0, 421.0, 1009.0, 421.0, 1009.0, 588.0, 752.0, 588.0]],
"area": 42919.0,
"iscrowd": 0
}
],
"categories": [
{ "id": 1, "name": "kiwi", "supercategory": "kiwi" },
{ "id": 2, "name": "lemon", "supercategory": "lemon" }
]
}Import and export COCO in Supervisely
Import COCO into Supervisely
- Import data (Auto Import)
Drop the images and
instances.jsoninto a new project. The built-in converter reads instances, keypoints and captions, and can add annotations to images already in a dataset by matching file names. - Import COCO
Imports a custom COCO dataset from Team Files, or the original COCO 2014 and 2017 datasets: polygons with holes, boxes and captions.
- Import COCO Keypoints
Imports COCO keypoint annotations as keypoint graphs.
Export from Supervisely to COCO
- Export to COCO
Writes
instances.jsonper dataset: polygons, rectangles and bitmaps become COCO polygons and boxes, keypoint graphs become COCO keypoints, and acaptiontag becomes captions. Holes are not kept. - Export to COCO mask
The export to use when polygons have holes or the project has polylines.
- Export COCO Keypoints
Exports keypoint graphs as COCO keypoints.
- Python SDK
After
sly.Project.download(),sly.convert.project_to_coco()converts a downloaded project to COCO.
All apps are in the Ecosystem, under Import and Export. Every project is stored in Supervisely JSON in between.
Converting COCO to and from Supervisely JSON
| COCO | Supervisely JSON | Notes |
|---|---|---|
categories[].name | class title in meta.json | Each category becomes a class. |
bbox [x, y, w, h] | rectangle, exterior [[x, y], [x + w, y + h]] | Auto Import puts boxes in a rectangle class of their own, named with a _bbox suffix, linked to the polygon of the same object. |
segmentation as polygons | polygon: exterior, holes in interior | Import COCO keeps holes. Export to COCO writes the outer contour only; Export to COCO mask keeps holes. |
segmentation as RLE | polygon | Auto Import decodes the mask and traces it into polygon contours. |
keypoints with the category keypoints and skeleton | graph (keypoint structure) | Only keypoints with v = 2 are imported. |
caption | image tag caption (any_string) | Export to COCO writes captions from this tag. |
| COCO polygon and box | bitmap | On export, bitmaps become COCO polygons and boxes. |
info, licenses | (not kept) | Import COCO drops the dataset, license and image information of the file. |