获取 COCO 数据集分布信息

Author Avatar
Patrick 2月 09, 2021

使用 COCO API 来获得数据集中的数据分布信息,参考CSDN 文章

1
2
3
4
5
6
7
8
9
10
from pycocotools.coco import COCO

coco=COCO(PATH_TO_COCO_JSON)

# 获取所有类别对应的名称与 id,一共有 80 类,id 号则是 1~90
cat_info = [(c['id'], c['name']) for c in coco.cats.values()]

for cat_id, cat_name in cat_info:
anns = coco.catToImgs[cat_id]
print("{} | {} | {:.2%} | {} | {:.2%}".format(cat_name, len(set(anns)), len(set(anns)) / len(coco.imgs), len(anns), len(anns) / len(coco.anns)))

其中 val2017 分布如下:

类别名 图像数 类别比例 框数 框比例
person 2693 53.86% 11004 29.92%
bicycle 149 2.98% 316 0.86%
car 535 10.70% 1932 5.25%
motorcycle 159 3.18% 371 1.01%
airplane 97 1.94% 143 0.39%
bus 189 3.78% 285 0.77%
train 157 3.14% 190 0.52%
truck 250 5.00% 415 1.13%
boat 121 2.42% 430 1.17%
traffic light 191 3.82% 637 1.73%
fire hydrant 86 1.72% 101 0.27%
stop sign 69 1.38% 75 0.20%
parking meter 37 0.74% 60 0.16%
bench 235 4.70% 413 1.12%
bird 125 2.50% 440 1.20%
cat 184 3.68% 202 0.55%
dog 177 3.54% 218 0.59%
horse 128 2.56% 273 0.74%
sheep 65 1.30% 361 0.98%
cow 87 1.74% 380 1.03%
elephant 89 1.78% 255 0.69%
bear 49 0.98% 71 0.19%
zebra 85 1.70% 268 0.73%
giraffe 101 2.02% 232 0.63%
backpack 228 4.56% 371 1.01%
umbrella 174 3.48% 413 1.12%
handbag 292 5.84% 540 1.47%
tie 145 2.90% 254 0.69%
suitcase 105 2.10% 303 0.82%
frisbee 84 1.68% 115 0.31%
skis 120 2.40% 241 0.66%
snowboard 49 0.98% 69 0.19%
sports ball 169 3.38% 263 0.72%
kite 91 1.82% 336 0.91%
baseball bat 97 1.94% 146 0.40%
baseball glove 100 2.00% 148 0.40%
skateboard 127 2.54% 179 0.49%
surfboard 149 2.98% 269 0.73%
tennis racket 167 3.34% 225 0.61%
bottle 379 7.58% 1025 2.79%
wine glass 110 2.20% 343 0.93%
cup 390 7.80% 899 2.44%
fork 155 3.10% 215 0.58%
knife 181 3.62% 326 0.89%
spoon 153 3.06% 253 0.69%
bowl 314 6.28% 626 1.70%
banana 103 2.06% 379 1.03%
apple 76 1.52% 239 0.65%
sandwich 98 1.96% 177 0.48%
orange 85 1.70% 287 0.78%
broccoli 71 1.42% 316 0.86%
carrot 81 1.62% 371 1.01%
hot dog 51 1.02% 127 0.35%
pizza 153 3.06% 285 0.77%
donut 62 1.24% 338 0.92%
cake 124 2.48% 316 0.86%
chair 580 11.60% 1791 4.87%
couch 195 3.90% 261 0.71%
potted plant 172 3.44% 343 0.93%
bed 149 2.98% 163 0.44%
dining table 501 10.02% 697 1.90%
toilet 149 2.98% 179 0.49%
tv 207 4.14% 288 0.78%
laptop 183 3.66% 231 0.63%
mouse 88 1.76% 106 0.29%
remote 145 2.90% 283 0.77%
keyboard 106 2.12% 153 0.42%
cell phone 214 4.28% 262 0.71%
microwave 54 1.08% 55 0.15%
oven 115 2.30% 143 0.39%
toaster 8 0.16% 9 0.02%
sink 187 3.74% 225 0.61%
refrigerator 101 2.02% 126 0.34%
book 230 4.60% 1161 3.16%
clock 204 4.08% 267 0.73%
vase 137 2.74% 277 0.75%
scissors 28 0.56% 36 0.10%
teddy bear 94 1.88% 191 0.52%
hair drier 9 0.18% 11 0.03%
toothbrush 34 0.68% 57 0.15%

train2017 分布如下

类别名 图像数 类别比例 框数 框比例
person 64115 54.20% 262465 30.52%
bicycle 3252 2.75% 7113 0.83%
car 12251 10.36% 43867 5.10%
motorcycle 3502 2.96% 8725 1.01%
airplane 2986 2.52% 5135 0.60%
bus 3952 3.34% 6069 0.71%
train 3588 3.03% 4571 0.53%
truck 6127 5.18% 9973 1.16%
boat 3025 2.56% 10759 1.25%
traffic light 4139 3.50% 12884 1.50%
fire hydrant 1711 1.45% 1865 0.22%
stop sign 1734 1.47% 1983 0.23%
parking meter 705 0.60% 1285 0.15%
bench 5570 4.71% 9838 1.14%
bird 3237 2.74% 10806 1.26%
cat 4114 3.48% 4768 0.55%
dog 4385 3.71% 5508 0.64%
horse 2941 2.49% 6587 0.77%
sheep 1529 1.29% 9509 1.11%
cow 1968 1.66% 8147 0.95%
elephant 2143 1.81% 5513 0.64%
bear 960 0.81% 1294 0.15%
zebra 1916 1.62% 5303 0.62%
giraffe 2546 2.15% 5131 0.60%
backpack 5528 4.67% 8720 1.01%
umbrella 3968 3.35% 11431 1.33%
handbag 6841 5.78% 12354 1.44%
tie 3810 3.22% 6496 0.76%
suitcase 2402 2.03% 6192 0.72%
frisbee 2184 1.85% 2682 0.31%
skis 3082 2.61% 6646 0.77%
snowboard 1654 1.40% 2685 0.31%
sports ball 4262 3.60% 6347 0.74%
kite 2261 1.91% 9076 1.06%
baseball bat 2506 2.12% 3276 0.38%
baseball glove 2629 2.22% 3747 0.44%
skateboard 3476 2.94% 5543 0.64%
surfboard 3486 2.95% 6126 0.71%
tennis racket 3394 2.87% 4812 0.56%
bottle 8501 7.19% 24342 2.83%
wine glass 2533 2.14% 7913 0.92%
cup 9189 7.77% 20650 2.40%
fork 3555 3.01% 5479 0.64%
knife 4326 3.66% 7770 0.90%
spoon 3529 2.98% 6165 0.72%
bowl 7111 6.01% 14358 1.67%
banana 2243 1.90% 9458 1.10%
apple 1586 1.34% 5851 0.68%
sandwich 2365 2.00% 4373 0.51%
orange 1699 1.44% 6399 0.74%
broccoli 1939 1.64% 7308 0.85%
carrot 1683 1.42% 7852 0.91%
hot dog 1222 1.03% 2918 0.34%
pizza 3166 2.68% 5821 0.68%
donut 1523 1.29% 7179 0.83%
cake 2925 2.47% 6353 0.74%
chair 12774 10.80% 38491 4.48%
couch 4423 3.74% 5779 0.67%
potted plant 4452 3.76% 8652 1.01%
bed 3682 3.11% 4192 0.49%
dining table 11837 10.01% 15714 1.83%
toilet 3353 2.83% 4157 0.48%
tv 4561 3.86% 5805 0.67%
laptop 3524 2.98% 4970 0.58%
mouse 1876 1.59% 2262 0.26%
remote 3076 2.60% 5703 0.66%
keyboard 2115 1.79% 2855 0.33%
cell phone 4803 4.06% 6434 0.75%
microwave 1547 1.31% 1673 0.19%
oven 2877 2.43% 3334 0.39%
toaster 217 0.18% 225 0.03%
sink 4678 3.95% 5610 0.65%
refrigerator 2360 2.00% 2637 0.31%
book 5332 4.51% 24715 2.87%
clock 4659 3.94% 6334 0.74%
vase 3593 3.04% 6613 0.77%
scissors 947 0.80% 1481 0.17%
teddy bear 2140 1.81% 4793 0.56%
hair drier 189 0.16% 198 0.02%
toothbrush 1007 0.85% 1954 0.23%