-
Notifications
You must be signed in to change notification settings - Fork 4
/
labelling.py
157 lines (141 loc) · 5.17 KB
/
labelling.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
def collectinglabel(Table, sub, videoName, workplace, db, objective_flag):
# note: cross cases must be put on top
# SAMM-CASME case
if "SAMM_CASME" in db:
for var in range(len(Table[0, :, 0])):
result = -1
# for casme: sub[3:]
# for samm: sub
if videoName == Table[0, var, 1] and sub == Table[0, var, 0]:
result = Table[0, var, 2]
result -= 1
break
elif videoName == Table[0, var, 1] and sub[3:] == Table[0, var, 0]:
result = Table[0, var, 2]
result -= 1
break
# SMIC only case
elif "SMIC" in db:
counter = 0
for var in ((Table[0, :, 0])):
result = -1
# print(var)
if videoName == var:
result = int(Table[0, counter, 1])
if result == 1: # negative
result = 0
break
elif result == 2: # positive
result = 1
break
elif result == 3: # surprise
result = 2
break
# print("found: %s" % (videoName) )
# break
counter += 1
# SAMM only case
elif "SAMM" in db:
counter = 0
if objective_flag == 0:
for var in ((Table[0, :, 0])):
result = -1
# print(Table[0,counter, 1])
if videoName == var or videoName in var:
result = (Table[0, counter, 1])
if result == 'Anger': # negative
result = 0
break
elif result == 'Contempt': # positive
result = 5
break
elif result == 'Disgust': # surprise
result = 2
break
elif result == 'Fear': # surprise
result = 2
break
elif result == 'Happiness': # surprise
result = 4
break
elif result == 'Other': # surprise
result = 5
break
elif result == 'Sadness': # surprise
result = 2
break
elif result == 'Surprise': # surprise
result = 1
break
# print("found: %s" % (videoName) )
# print(result)
# break
counter += 1
elif "Aug" in db:
for var in range(len(Table)):
result = -1
if ( videoName == Table[var,1] or Table[var, 1] in videoName ) and sub == Table[var,0]:
if Table[var,2]=='positive':
result=0
break
if Table[var,2]=='negative':
result=1
break
if Table[var,2]=='surprise':
result=2
break
if Table[var,2]=='others':
result=3
break
# CASME2 usually.
else:
for var in range(len(Table)):
result = -1
if ( videoName == Table[var,1] or Table[var, 1] in videoName ) and sub == Table[var,0]:
# print(Table[var])
# if Table[var,2]=='happiness':
# result=0
# break
# if Table[var,2]=='disgust':
# result=1
# break
# if Table[var,2]=='repression':
# result=2
# break
# if Table[var,2]=='surprise':
# result=3
# break
# if Table[var,2]=='others':
# result=4
# break
# if Table[var,2]=='sadness':
# result = 5
# break
# if Table[var,2]=='fear':
# result = 6
# break
# popravljeno na ver3
#print(Table[var])
if Table[var,2]=='positive':
result=0
break
if Table[var,2]=='negative':
result=1
break
if Table[var,2]=='surprise':
result=2
break
if Table[var,2]=='others':
result=3
break
if result != -1 :
with open(workplace + db + '_label.txt','a') as f:
f.write(str(result) + '\n')
f.close()
elif result == -1:
if db == 'SMIC':
print ('Cannot find the matching label for %s'%(videoName))
else:
print ('Cannot find the matching label for %s of %s'%(videoName,sub))
# file_to_be_ignored = Table[videoName]
# return file_to_be_ignored