In the latest version of the COCO dataset (COCO 2017), there are a total of 80 object categories. they are, respectively:
ID: | coco/yaml Name: | yaml id: |
---|---|---|
1 | person | 0 |
2 | bicycle | 1 |
3 | car | 2 |
4 | motorcycle | 3 |
5 | airplane | 4 |
6 | bus | 5 |
7 | train | 6 |
8 | truck | 7 |
9 | boat | 8 |
10 | traffic light | 9 |
11 | fire hydrant | 10 |
13 | stop sign | 11 |
14 | parking meter | 12 |
15 | bench | 13 |
16 | bird | 14 |
17 | cat | 15 |
18 | dog | 16 |
19 | horse | 17 |
20 | sheep | 18 |
21 | cow | 19 |
22 | elephant | 20 |
23 | bear | 21 |
24 | zebra | 22 |
25 | giraffe | 23 |
27 | backpack | 24 |
28 | umbrella | 25 |
31 | handbag | 26 |
32 | tie | 27 |
33 | suitcase | 28 |
34 | frisbee | 29 |
35 | skis | 30 |
36 | snowboard | 31 |
37 | sports ball | 32 |
38 | kite | 33 |
39 | baseball bat | 34 |
40 | baseball glove | 35 |
41 | skateboard | 36 |
42 | surfboard | 37 |
43 | tennis racket | 38 |
44 | bottle | 39 |
46 | wine glass | 40 |
47 | cup | 41 |
48 | fork | 42 |
49 | knife | 43 |
50 | spoon | 44 |
51 | bowl | 45 |
52 | banana | 46 |
53 | apple | 47 |
54 | sandwich | 48 |
55 | orange | 49 |
56 | broccoli | 50 |
57 | carrot | 51 |
58 | hot dog | 52 |
59 | pizza | 53 |
60 | donut | 54 |
61 | cake | 55 |
62 | chair | 56 |
63 | couch | 57 |
64 | potted plant | 58 |
65 | bed | 59 |
67 | dining table | 60 |
70 | toilet | 61 |
72 | tv | 62 |
73 | laptop | 63 |
74 | mouse | 64 |
75 | remote | 65 |
76 | keyboard | 66 |
77 | cell phone | 67 |
78 | microwave | 68 |
79 | oven | 69 |
80 | toaster | 70 |
81 | sink | 71 |
82 | refrigerator | 72 |
84 | book | 73 |
85 | clock | 74 |
86 | vase | 75 |
87 | scissors | 76 |
88 | teddy bear | 77 |
89 | hair drier | 78 |
90 | toothbrush | 79 |
The code is implemented as follows, or click the link to download:
import json
# COCO数据集的路径和注释文件名称
dataDir = 'D:/test/1_dataset'
annFile = '{}/annotations/instances_train2017.json'.format(dataDir)
# 注:coco.yaml要复制到跟python脚本一致的目录下
cocoYamlFile = 'coco.yaml'
# 读取注释文件
with open(annFile, 'r') as f:
ann_data = json.load(f)
# 获取所有物体类别的ID号和名称
categories = {
}
for category in ann_data['categories']:
categories[category['id']] = category['name']
# 打印所有物体类别的ID号和名称
# for id, name in categories.items():
# print("ID: {}, Name: {}".format(id, name))
import yaml
# 加载coco.yaml文件,获取ID号和对应名称的对应关系
with open(cocoYamlFile, 'r',encoding='utf-8') as f:
coco_yaml = yaml.safe_load(f)
# 获取ID号和对应名称的对应关系
name_mapping = coco_yaml['names']
id_mapping = {
v : k for k, v in name_mapping.items()}
# 打印所有物体类别的ID号、名称和在coco.yaml中的对应关系
for id, name in categories.items():
coco_name = id_mapping[name]
print("ID: {}, Name: {}, Coco Name: {}".format(id, name, coco_name))
注:数据集下载地址:
官网:https://cocodataset.org/#download
下载方法:
直接点击下载,或者右键复制链接,在linux系统中wget 粘贴链接即可:
如:
wget http://images.cocodataset.org/zips/train2017.zip