基础
什么是COCO数据集
COCO全称Common Objects in COntext,是微软团队提供的一个可以用来进行图像识别的数据集,数据集分为训练集、验证集、测试集,数据集共有80个对象类别。
COCO数据集现在有3种标注类型:
- object instances 目标实例
- object keypoints 目标上的关键点
- image caption
COCO的标注数据使用JSON格式存储。
基本结构
以上三种标注类型共享以下的基本类型:
1 | { |
其中annotation类型实现了多态,会根据不同的任务生成不同的标注格式。
Object Instance 类型的标注格式
因为我们的目的是将VOC格式的目标检测数据集转换为COCO格式,这里我们暂时只关注Object instances类型的标注格式。
- 整体JSON文件格式
此种格式的文件从头到尾按顺序分为以下段落:
1 | { |
info, licenses, images这三个结构体定义共享,而annotation, category这两个结构体在不同JSON文件中也不同。
annotations字段
1
2
3
4
5
6
7
8
9annotation{
"id": int,
"image_id": int,
"category_id": int,
"segmentation": RLE or [polygon],
"area": float,
"bbox": [x,y,width,height],
"iscrowd": 0 or 1,
}categories字段
存储当前对象所属category的id,以及所属supercategory的name。1
2
3
4
5{
"id": int,
"name": str,
"supercategory": str,
}从instances_val2017.json文件中摘出的2个category实例如下所示:
1
2
3
4
5
6
7
8
9
10
11{
"supercategory": "person",
"id": 1,
"name": "person"
},
{
"supercategory": "vehicle",
"id": 2,
"name": "bicycle"
},
......
转换脚本
这里直接把脚本贴在下面:
注意我们的训练集标签需要重新设置为“rice”
1 | # -*- coding=utf-8 -*- |