-
Notifications
You must be signed in to change notification settings - Fork 0
/
segLab.py
107 lines (83 loc) · 2.46 KB
/
segLab.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import sys
import getopt
import os
import struct
import datetime
import json
import operator
from copy import deepcopy
from pprint import pprint
from collections import Counter
def main(jSONFile):
plt.imshow(np.random.random((50, 50)))
plt.colorbar()
plt.show()
run_seq_no = 1
prefix = '/ndn/eb/run/1/segment/' + str(run_seq_no) + '/segment/'
seq_num = 1
curr = []
for line in open(jSONFile, 'r'):
curr.append(json.loads(line))
curr_list = []
prev = []
for ann in curr:
temp = []
frameName = ann['frameName']
for k in ann["annotations"]:
temp.append({"label": ''.join([i for i in k["label"] if not i.isdigit()]), "frameName": frameName})
curr_list.append(temp)
frame_list = []
initial_frame = curr_list[0]
last_frame = initial_frame
frame_table = Counter()
for item in initial_frame:
frame_table[item['label']] += 1
# print(frame_table)
for k in curr_list:
ann_table = Counter()
for item in k:
ann_table[item['label']] += 1
# print(ann_table)
if not segmentDetection(frame_table, ann_table):
frame_list.append(labeling(initial_frame, last_frame, frame_table))
seg_name = prefix + str(seq_num)
seq_num += 1
print(seg_name)
initial_frame = k
last_frame = initial_frame
frame_table = ann_table
else:
last_frame = k
print(frame_list)
return frame_list
def labeling(first, last, table):
data_object = {"labels": [], "start": first[-1]["frameName"], "end": last[-1]["frameName"]}
for k, v in table.items():
data_object["labels"].append({"item": k, "frequency": v})
data_json = json.dumps(data_object)
print(data_json)
return data_json
def distanceCalculation():
pass
def segmentDetection(f_table, a_table):
common_count = 0
common_item = 0
total_count = 0
total_item = 0
# print(a_table)
for it, n in a_table.items():
common_count += min(n, f_table[it])
if common_count > 0:
common_item += 1
total_item += 1
total_count += n
if common_count / total_count > 0.8:
return True
elif common_item / total_item > 0.9:
return True
elif common_count / total_count + common_item / total_item > 1:
return True
else:
return False
if __name__ == '__main__':
main(sys.argv[1])