第一步、coco数据集下载链接
不过还在罗嗦一句,第一组是train数据,第二组是val验证数据集,第三组是test验证数据集。数据包括了物体检测和keypoints身体关键点的检测。
http://images.cocodataset.org/zips/train2017.zip
http://images.cocodataset.org/annotations/annotations\_trainval2017.zip
http://images.cocodataset.org/zips/val2017.zip
http://images.cocodataset.org/annotations/stuff\_annotations\_trainval2017.zip
http://images.cocodataset.org/zips/test2017.zip
http://images.cocodataset.org/annotations/image\_info\_test2017.zip
这些就是全部的microsoft coco数据集2017的链接了。
COCO数据集现在有3种标注类型:object instances(目标实例), object keypoints(目标上的关键点), and image captions(看图说话)
此外,每种类型又包含了训练和验证,所以共6个JSON文件
第二步、基本的JSON结构体类型
这3种类型共享下面所列的基本类型,包括info、image、license,而annotation类型则呈现出了多态:
{
"info": info, "licenses": [license], "images": [image], "annotations": [annotation], } info{ "year": int, "version": str, "description": str, "contributor": str, "url": str, "date_created": datetime, } license{ "id": int, "name": str, "url": str, } image{ "id": int, "width": int, "height": int, "file_name": str, "license": int, "flickr_url": str, "coco_url": str, "date_captured": datetime, }
1,info类型,比如一个info类型的实例:
"info":{
"description":"This is stable 1.0 version of the 2014 MS COCO dataset.", "url":"http:\/\/mscoco.org", "version":"1.0","year":2014, "contributor":"Microsoft COCO group", "date_created":"2015-01-27 09:11:52.357475" },
2,Images是包含多个image实例的数组,对于一个image类型的实例:
{
"license":3, "file_name":"COCO_val2014_000000391895.jpg", "coco_url":"http:\/\/mscoco.org\/images\/391895", "height":360,"width":640,"date_captured":"2013-11-14 11:18:45", "flickr_url":"http:\/\/farm9.staticflickr.com\/8186\/8119368305_4e622c8349_z.jpg", "id":391895 },
3,licenses是包含多个license实例的数组,对于一个license类型的实例:
{
"url":"http:\/\/creativecommons.org\/licenses\/by-nc-sa\/2.0\/", "id":1, "name":"Attribution-NonCommercial-ShareAlike License" },
第三部、认识Object Keypoint 类型的标注格式
1,整体JSON文件格式
比如上图中的person_keypoints_train2017.json、person_keypoints_val2017.json这两个文件就是这种格式。
Object Keypoint这种格式的文件从头至尾按照顺序分为以下段落,看起来和Object Instance一样啊:
{
"info": info,
"licenses": [license],
"images": [image],
"annotations": [annotation],
"categories": [category]
}
是的,你打开这两个文件,虽然内容很多,但从文件开始到结尾按照顺序就是这5段。其中,info、licenses、images这三个结构体/类型 在第一节中已经说了,在不同的JSON文件中这三个类型是一样的,定义是共享的。不共享的是annotation和category这两种结构体,他们在不同类型的JSON文件中是不一样的。
images数组和annotations数组的元素数量是相等的,等于图片的数量。
2,annotations字段
这个类型中的annotation结构体包含了Object Instance中annotation结构体的所有字段,再加上2个额外的字段。
新增的keypoints是一个长度为3*k的数组,其中k是category中keypoints的总数量。每一个keypoint是一个长度为3的数组,第一和第二个元素分别是x和y坐标值,第三个元素是个标志位v,v为0时表示这个关键点没有标注(这种情况下x=y=v=0),v为1时表示这个关键点标注了但是不可见(被遮挡了),v为2时表示这个关键点标注了同时也可见。
num_keypoints表示这个目标上被标注的关键点的数量(v>0),比较小的目标上可能就无法标注关键点。
annotation{
"keypoints": [x1,y1,v1,...], "num_keypoints": int, "id": int, "image_id": int, "category_id": int, "segmentation": RLE or [polygon], "area": float, "bbox": [x,y,width,height], "iscrowd": 0 or 1, }
从person_keypoints_val2017.json文件中摘出一个annotation的实例如下:
{
"segmentation": [[125.12,539.69,140.94,522.43,100.67,496.54,84.85,469.21,73.35,450.52,104.99,342.65,168.27,290.88,179.78,288,189.84,286.56,191.28,260.67,202.79,240.54,221.48,237.66,248.81,243.42,257.44,256.36,253.12,262.11,253.12,275.06,299.15,233.35,329.35,207.46,355.24,206.02,363.87,206.02,365.3,210.34,373.93,221.84,363.87,226.16,363.87,237.66,350.92,237.66,332.22,234.79,314.97,249.17,271.82,313.89,253.12,326.83,227.24,352.72,214.29,357.03,212.85,372.85,208.54,395.87,228.67,414.56,245.93,421.75,266.07,424.63,276.13,437.57,266.07,450.52,284.76,464.9,286.2,479.28,291.96,489.35,310.65,512.36,284.76,549.75,244.49,522.43,215.73,546.88,199.91,558.38,204.22,565.57,189.84,568.45,184.09,575.64,172.58,578.52,145.26,567.01,117.93,551.19,133.75,532.49]], "num_keypoints": 10, "area": 47803.27955, "iscrowd": 0, "keypoints": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,142,309,1,177,320,2,191,398,2,237,317,2,233,426,2,306,233,2,92,452,2,123,468,2,0,0,0,251,469,2,0,0,0,162,551,2], "image_id": 425226,"bbox": [73.35,206.02,300.58,372.5],"category_id": 1, "id": 183126 },
3,categories字段
最后,对于每一个category结构体,相比Object Instance中的category新增了2个额外的字段,keypoints是一个长度为k的数组,包含了每个关键点的名字;skeleton定义了各个关键点之间的连接性(比如人的左手腕和左肘就是连接的,但是左手腕和右手腕就不是)。目前,COCO的keypoints只标注了person category (分类为人)。
定义如下:
{
"id": int, "name": str, "supercategory": str, "keypoints": [str], "skeleton": [edge] }
从person_keypoints_val2017.json文件中摘出一个category的实例如下:
{
"supercategory": "person", "id": 1, "name": "person", "keypoints": ["nose","left_eye","right_eye","left_ear","right_ear","left_shoulder","right_shoulder","left_elbow","right_elbow","left_wrist","right_wrist","left_hip","right_hip","left_knee","right_knee","left_ankle","right_ankle"], "skeleton": [[16,14],[14,12],[17,15],[15,13],[12,13],[6,12],[7,13],[6,7],[6,8],[7,9],[8,10],[9,11],[2,3],[1,2],[1,3],[2,4],[3,5],[4,6],[5,7]] }
参考文献:https://blog.csdn.net/gqixf/article/details/79280224