COCO(Common Objects in Context)格式是一种广泛用于图像识别和分割任务的数据格式,尤其是在目标检测、语义分割等任务中。COCO格式的核心包括以下几个部分:
- images: 包含图像的基本信息(如文件名、大小、ID等)。
- annotations: 包含每个目标的标注信息,如边界框、类别、分割掩码等。
- categories: 定义所有类别的信息。
- licenses: 图片的授权信息(可选)。
- info: 数据集的基本信息(可选)。
COCO格式的JSON文件大致结构如下:
{"info": {"year": 2025,"version": "1.0","description": "COCO-style Dataset","contributor": "User","date_created": "2025-02-21"},"images": [{"id": 1,"width": 640,"height": 480,"file_name": "image1.jpg","license": 1,"flickr_url": "http://example.com/image1","coco_url": "http://example.com/image1"}],"annotations": [{"id": 1,"image_id": 1,"category_id": 1,"bbox": [100, 150, 200, 250], // [x, y, width, height]"area": 50000,"segmentation": [[100, 150, 100, 250, 300, 250, 300, 150]], // Polygon segmentation"iscrowd": 0}],"categories": [{"id": 1,"name": "cat","supercategory": "animal"}]
}
主要字段解释:
- images:
id
: 图像的唯一标识符。file_name
: 图像文件名。width
,height
: 图像的宽高。license
: 图片的授权ID。
- annotations:
id
: 标注的唯一标识符。image_id
: 该标注对应的图像ID。category_id
: 目标类别ID。bbox
: 边界框的坐标[x, y, width, height]
。area
: 目标区域的面积。segmentation
: 分割掩码(可以是多边形的坐标点数组)。iscrowd
: 是否为拥挤对象,0表示没有,1表示是。
- categories:
id
: 类别的唯一标识符。name
: 类别名称。supercategory
: 类别的父类别。
这种格式便于进行目标检测、图像分割等任务的标注和数据管理。