-
Notifications
You must be signed in to change notification settings - Fork 0
/
inspect_coco_instances.py
60 lines (43 loc) · 1.73 KB
/
inspect_coco_instances.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import json
import numpy as np
import matplotlib.pyplot as plt
if __name__ == "__main__":
labels_txt = open("annotations/labels.txt").read()
labels = labels_txt.splitlines()
j = json.loads(open("annotations/instances_val2017.json").read())
category_stats = {}
print(j['info'])
# print([i for i in j['annotations']])
exit()
annots = j['annotations']
# print([a['category_id'] for a in annot[0:500]])
for annot in annots:
cat_id = annot['category_id']
if cat_id not in category_stats:
category_stats[cat_id] = {
'num_segments': [],
'area': []
}
# print(annot['segmentation'][0], len(annot['segmentation'][0]))
try:
annot['segmentation'][0]
except:
print("annot", annot)
# exit()
if 'counts' in annot['segmentation']:
category_stats[cat_id]['num_segments'].append(len(annot['segmentation']['counts']) // 2)
else:
category_stats[cat_id]['num_segments'].append(len(annot['segmentation'][0]) // 2)
category_stats[cat_id]['area'].append(annot['area'])
m_ = 0
for cat_id in category_stats:
plt.hist(category_stats[cat_id]['num_segments'], 100, density=True)
print(cat_id, labels[cat_id - 1])
plt.title(labels[cat_id - 1])
m = np.mean(np.array(category_stats[cat_id]['num_segments']))
m_ = m if m > m_ else m_
print("largest mean", m_)
plt.show()
# category_stats[cat_id]['num_segments'] = np.mean(np.array(category_stats[cat_id]['num_segments']))
# category_stats[cat_id]['area'] = np.mean(np.array(category_stats[cat_id]['area']))
# print(category_stats)