-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathlabelling.py
129 lines (111 loc) · 4.08 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
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 = 1
break
elif result == 'Disgust': # surprise
result = 2
break
elif result == 'Fear': # surprise
result = 3
break
elif result == 'Happiness': # surprise
result = 4
break
elif result == 'Other': # surprise
result = 5
break
elif result == 'Sadness': # surprise
result = 6
break
elif result == 'Surprise': # surprise
result = 7
break
# print("found: %s" % (videoName) )
# print(result)
# break
counter += 1
# 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
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