文章目录
COCO数据集的标签文件 .json
.json 文件的本质是一个字典
1. 读取文件,显示文件中的信息,代码如下:
import json
filedir = "instances_val2014.json"
annos = json.loads(open(filedir).read())
print(type(annos)) # <class 'dict'>
print(len(annos)) # 5
print(annos.keys()) # 键
print(annos["info"]) # 键值
print(annos["images"])
print(annos["licenses"])
print(annos["annotations"])
print(annos["categories"])
2. json 中文件的类型如下:
<class 'dict'>
3. 字典的长度是:
5
4. 字典的 key 有:
dict_keys(['info', 'images', 'licenses', 'annotations', 'categories'])
5. 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'
}
6. images 对应键值的 部分内容为:
{'license': 3,
'file_name': 'COCO_val2014_000000016744.jpg',
'coco_url': 'http://mscoco.org/images/16744',
'height': 335,
'width': 500,
'date_captured': '2013-11-20 14:29:03',
'flickr_url': 'http://farm3.staticflickr.com/2393/2228750191_11de3ec047_z.jpg',
'id': 16744
},
..... 不断的重复 其他相同格式的数据
7. licenses 对应键值的内容为:
[{'url': 'http://creativecommons.org/licenses/by-nc-sa/2.0/', 'id': 1, 'name': 'Attribution-NonCommercial-ShareAlike License'},
{'url': 'http://creativecommons.org/licenses/by-nc/2.0/', 'id': 2, 'name': 'Attribution-NonCommercial License'},
{'url': 'http://creativecommons.org/licenses/by-nc-nd/2.0/', id': 3, 'name': 'Attribution-NonCommercial-NoDerivs License'},
{'url': 'http://creativecommons.org/licenses/by/2.0/', 'id': 4, 'name': 'Attribution License'},
{'url': 'http://creativecommons.org/licenses/by-sa/2.0/', 'id': 5, 'name': 'Attribution-ShareAlike License'},
{'url': 'http://creativecommons.org/licenses/by-nd/2.0/', 'id': 6, 'name': 'Attribution-NoDerivs License'},
{'url': 'http://flickr.com/commons/usage/', 'id': 7, 'name': 'No known copyright restrictions'},
{'url': 'http://www.usa.gov/copyright.shtml', 'id': 8, 'name': 'United States Government Work'}
]
8. annotations 对应键值的部分内容为:
'image_id': 356347,
'bbox': [396.94, 6.47, 242.7, 407.73],
'category_id': 51,
'id': 713208},
{'segmentation': [[167.01, 139.45, 167.09, 143.41, 167.33, 144.44, 169.39, 148.79, 171.92, 150.77, 182.21, 150.77, 184.1, 148.95, 184.58, 139.69, 172.63, 139.69]],
'area': 177.08010000000021,
'iscrowd': 0,
重复前面的内容......
'image_id': 356347,
.......
9. categories 对应键值的内容如下:
[{'supercategory': 'person', 'id': 1, 'name': 'person'}, # 第一个数据
{'supercategory': 'vehicle', 'id': 2, 'name': 'bicycle'},
{'supercategory': 'vehicle', 'id': 3, 'name': 'car'},
{'supercategory': 'vehicle', 'id': 4, 'name': 'motorcycle'},
{'supercategory': 'vehicle', 'id': 5, 'name': 'airplane'},
{'supercategory': 'vehicle', 'id': 6, 'name': 'bus'},
...
不断重前面内容....... COCO 数据集一有 90个类别
...
{'supercategory': 'indoor', 'id': 90, 'name': 'toothbrush'} # 最后一个数据
]
完
版权声明:本文为weixin_42419002原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。