COCO Dataset Format
lastmod 2022-09-08created 2022-09-0414 edits
COCO has several annotation types, such as object detection, keypoint detection, stuff segmentation, panoptic segmentation, densepose, and image captioning.
Annotations are stored using JSON.
Basic data structure
All Annotations share the basic data structure below.
{
"info": info,
"images": [image],
"annotations": [annotation],
"licenses": [license]
}
info {
"year": int,
"version": str,
"description": str,
"contributor": str,
"url": str,
"date_created": datetime,
}
image {
"id": int,
"width": int,
"height": int,
"file_name": str,
"license": int,
"flickr_url": str,
"coco_url": str,
"date_captured": datetime,
}
license {
"id": int,
"name": str,
"url": str,
}
Object Detection
Each "Object Instance Annotation" contains a series of fields, including the object's "Category ID" and "Segmentation Mask".
Depending on whether the instance represents
- a single object (
iscrowd=0, in which case polygons are used) or - a collection of objects (
iscrowd=1, in which case #RLE is used)
the "Segmentation Format" differs.
- A single object (
iscrowd=0) may require multiple polygons, for example if it is occluded. - Crowd annotations (
iscrowd=1) are used to label large groups of objects (e.g. a crowd of people).
In addition, an enclosing bounding box is provided for each object (box coordinates are measured from the top left corner of the image and are 0-indexed).
Finally, the categories field of the annotation structure stores the mapping of "Category ID" to category and supercategory names.
annotation {
"id" : int,
"image_id" : int,
"category_id" : int,
"segmentation" : RLE or [polygon],
"area" : float,
"bbox" : [x,y,width,height],
"iscrowd" : 0 or 1,
}
categories [
{
"id" : int,
"name" : str,
"supercategory" : str,
}
]
Sample
{
"images": [
{
"height": 1088,
"width": 1920,
"id": 1,
"file_name": "scene00706.png"
}
],
"annotations": [
{
"iscrowd": 0,
"image_id": 1,
"bbox": [
1524,
812,
60,
41
],
"segmentation": [
[
1564,
815,
1559,
824,
1548,
831,
1538,
832,
1525,
834,
1524,
843,
1532,
848,
1550,
852,
1565,
850,
1583,
839,
1584,
828,
1580,
817,
1575,
811
]
],
"category_id": 0,
"id": 1,
"area": 1378
}
],
"categories": [
{
"id": 0,
"name": "smoke",
"supercategory": "smoke"
}
]
}
area
It means Segmentation Area.
You can use mask.area function to compute it.
Projects
- labelme2coco
- A lightweight package for converting the labelme format to coco dataset format.
- https://github.com/fcakyon/labelme2coco
From labelme
- https://github.com/fcakyon/labelme2coco/blob/master/labelme2coco/labelme2coco.py
- https://github.com/wkentaro/labelme/blob/1d6ea6951c025a7db0540c7eac77577bc1507efa/labelme/utils/image.py
- https://github.com/wkentaro/labelme/blob/1d6ea6951c025a7db0540c7eac77577bc1507efa/labelme/cli/draw_json.py
See also
Favorite site
- COCO - Common Objects in Context # Data format
- [Recommended] Create COCO Annotations From Scratch — Immersive Limit