可以参考官方代码:https://github.com/dengdan/coco/blob/master/PythonAPI/pycocoDemo.ipynb
coco的标注格式如下:
{"info":
{"description": "This is stable 1.0 version of the 2017 MS COCO dataset.",
"url": "http://mscoco.org", "version": "1.0", "year": 2017,
"contributor": "Microsoft COCO group",
"date_created": "2017-11-11 02:11:36.777541"
},
"images": [
{"license": 2,"file_name": "000000289343.jpg",
"coco_url": "http://images.cocodataset.org/val2017/000000289343.jpg",
"height": 640,"width": 529,"date_captured": "2013-11-15 00:35:14",
"flickr_url": "http://farm5.staticflickr.com/4029/4669549715_7db3735de0_z.jpg","id": 289343},
...
{"license": 1,"file_name": "000000329219.jpg",
"coco_url": "http://images.cocodataset.org/val2017/000000329219.jpg",
"height": 427,"width": 640,"date_captured": "2013-11-14 19:21:56",
"flickr_url": "http://farm9.staticflickr.com/8104/8505307842_465524a6a6_z.jpg",
"id": 329219},
...
],
"annotations": [
{"segmentation": [[510.66,423.01,511.72,420.03,510.45,416.0,510...,423.01]],
"area": 702.1057499999998,
"iscrowd": 0,
"image_id": 289343,
"bbox": [473.07,395.93,38.65,28.67], "category_id": 18, "id": 1768
},
...
{"segmentation": [[304.09,266.18,308.95,263.56,313.06,262.81,...,266.55]],
"area": 4290.290900000001,
"iscrowd": 0,
"image_id": 329219,
"bbox": [297.73,252.34,60.21,108.45],"category_id": 18,"id": 8032}
],
"licenses": [
{"url": "http://creativecommons.org/licenses/by-nc-sa/2.0/",
"id": 1, "name": "Attribution-NonCommercial-ShareAlike License"},
...
{"url": "http://www.usa.gov/copyright.shtml",
"id": 8, "name": "United States Government Work"}
],
"categories": [
{"supercategory": "person", "id": 1, "name": "person"},
...
{"supercategory": "indoor", "id": 90, "name": "toothbrush"}
]
}