详细解说可以看这个视频:COCO File Format
COCO的标注文件分为如下5个部分:
annotation = {
'info': {},
'licenses': [],
'images': [],
'annotations': [],
'categories': []
}
annotation[‘info’]
info部分记录了整个数据集的名称、URL、版本、时间等基本信息。不包含具体的数据信息。例如:
annotation['info'] = {
'description': 'COCO 2017 Dataset',
'url': 'http://cocodataset.org',
'version': '1.0',
'year': 2017,
'contributor': 'COCO Consortium',
'date_created': '2017/09/01'
}
annotation[‘licenses’]
licenses部分记录了数据集中的数据遵循了哪些license。不包含具体的数据信息。例如:
annotation['licenses'] = [
{
'url': '',
'id': 1,
'name':
},
{
'url': '',
'id': 2,
'name':
},
{
'url': '',
'id': 3,
'name':
}
]
annotations[‘images’]
images部分记录了每幅图像的基础信息,包括遵循的license、文件名、COCO URL、宽高、采集时间、flickr URL、id。通过id可以在后面的annotation部分查询到该图像的标注信息。
annotations['images'] = [
{
'license': 1,
'file_name': '000000397133.jpg',
'coco_url': 'http://images.cocodataset.org/val2017/000000397133.jpg',
'height': 427,
'width': 640,
'date_captured': '2013-11-14 17:02:52',
'flickr_url': 'http://farm7.staticflickr.com/6116/6255196340_da26cf2c9e_z.jpg',
'id': 397133
},
...
]
annotation[‘annotations’]
annotations部分记录了标注信息,包括segmentation、bbox、面积(area)、是否为群体(iscrowd)、image_id、类别(category_id)、instance id(id)。
注意,这里的’image_id’对应的是前面images部分的’id’,而这里的’id’指的是每个instance的’id’。
每个dict记录的是一个instance的标注,而不是整幅图像。
annotation['annotations'] = [
{
'segmentation': []
'area': 702.1057
'iscrowd': 0
'image_id': 289343
'bbox': [473.07, 395.93, 38.65, 28.67]
'category_id': 18
'id': 1768
},
{
'segmentation':
'area':
'iscrowd':
'image_id':
'bbox':
'category_id':
'id':
},
...
]
详解:
segmentation
该部分标注的是分割任务所需的mask。
注意,一个segmentation中可能包含不止一个mask,原因是一个instance可能被遮挡,从而对应多个mask(例如大象被树干挡住,从而变成了两部分)。
mask有两种标注方式。一种方式是多边形标注(polygon),其中每一个list都对应一个多边形,形式如下:
{
...
'segmentation': [
[x00, y00, x01, y01,..., x0n, y0n],
[x10, y10, x11, y11,..., x1n, y1n],
...
]
...
}
另一种方式是run-length encoding(RLE),通常用于标注iscrowd为1的instance,形式如下(其中’counts’的具体解释请看最上面的视频链接):
{
...
'segmentation': {
'size': [height, width],
'counts': [b0, f0, b1, f1, ...]
}
...
}
bbox
bbox标注的是instance的包围框(bounding box),其格式是:[x, y, width, height]
area
mask覆盖的面积(像素总数),可用来筛选不同面积的instance。
image_id
对应于前面’images’部分的’id’,用来唯一标识一幅图像。
id
用来唯一标识一个instance。
category_id
对应于后面’categories’部分的’id’,用来唯一标识一个类别。
annotation[‘categories’]
annotation['categories'] = [
{
'supercategory': 'vehicle',
'id': 2,
'name': 'bicycle'
},
{
'supercategory': 'animal',
'id': 22,
'name': 'elephant'
}
...
]
全部类别如下:
supercategory | subcategory | id |
---|---|---|
person | person | 1 |
vehicle | bicycle | 2 |
vehicle | car | 3 |
vehicle | motorcycle | 4 |
vehicle | airplane | 5 |
vehicle | bus | 6 |
vehicle | train | 7 |
vehicle | truck | 8 |
vehicle | boat | 9 |
outdoor | traffic light | 10 |
outdoor | fire hydrant | 11 |
outdoor | stop sign | 13 |
outdoor | parking meter | 14 |
outdoor | bench | 15 |
animal | bird | 16 |
animal | cat | 17 |
animal | dog | 18 |
animal | horse | 19 |
animal | sheep | 20 |
animal | cow | 21 |
animal | elephant | 22 |
animal | bear | 23 |
animal | zebra | 24 |
animal | giraffe | 25 |
accessory | backpack | 27 |
accessory | umbrella | 28 |
accessory | handbag | 31 |
accessory | tie | 32 |
accessory | suitcase | 33 |
sports | frisbee | 34 |
sports | skis | 35 |
sports | snowboard | 36 |
sports | sports ball | 37 |
sports | kite | 38 |
sports | baseball bat | 39 |
sports | baseball glove | 40 |
sports | skateboard | 41 |
sports | surfboard | 42 |
sports | tennis racket | 43 |
kitchen | bottle | 44 |
kitchen | wine glass | 46 |
kitchen | cup | 47 |
kitchen | fork | 48 |
kitchen | knife | 49 |
kitchen | spoon | 50 |
kitchen | bowl | 51 |
food | banana | 52 |
food | apple | 53 |
food | sandwich | 54 |
food | orange | 55 |
food | broccoli | 56 |
food | carrot | 57 |
food | hot dog | 58 |
food | pizza | 59 |
food | donut | 60 |
food | cake | 61 |
furniture | chair | 62 |
furniture | couch | 63 |
furniture | potted plant | 64 |
furniture | bed | 65 |
furniture | dining table | 67 |
furniture | toilet | 70 |
electronic | tv | 72 |
electronic | laptop | 73 |
electronic | mouse | 74 |
electronic | remote | 75 |
electronic | keyboard | 76 |
electronic | cell phone | 77 |
appliance | microwave | 78 |
appliance | oven | 79 |
appliance | toaster | 80 |
appliance | sink | 81 |
appliance | refrigerator | 82 |
indoor | book | 84 |
indoor | clock | 85 |
indoor | vase | 86 |
indoor | scissors | 87 |
indoor | teddy bear | 88 |
indoor | hair drier | 89 |
indoor | toothbrush | 90 |