-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
209 lines (146 loc) · 5.62 KB
/
main.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import os
import sys
import cPickle
# device example: cpu, cuda0, cuda1, gpu0, gpu1
def set_environ(device, cnmem):
device_env = "device=" + device
theano_env = "mode=FAST_RUN," + device_env + ",floatX=float32,"
if device != "cpu":
cnmem_env = "lib.cnmem=" + cnmem
theano_env = theano_env + "," + cnmem_env
os.environ["THEANO_FLAGS"] = theano_env
#######################################################################################################################
def solve_cad(mode=0, fold="fold_1"):
data_path = ("./data/CAD-120/" + fold)
backup_path = "./backup/"
solver = CADSolver(data_path, backup_path, fold)
acc, n, target, output = solver.solve(mode)
print acc, n
return acc, n, target, output
def test_cad(mode=0):
fold = ["fold_1", "fold_2", "fold_3", "fold_4"]
modes = ["activity", "sub_detect", "obj_detect", "sub_anti", "obj_anti"]
list_all_acc = []
list_all_target = []
list_all_output = []
for i in range(5):
all_acc = 0.0
all_n = 0
all_target = []
all_output = []
for f in fold:
acc, n, target, output = solve_cad(mode=mode, fold=f)
all_acc += acc
all_n += n
all_target.extend(target)
all_output.extend(output)
print all_acc / all_n
list_all_target.extend(all_target)
list_all_output.extend(all_output)
list_all_acc.append([all_acc / all_n])
np.save(("CAD_acc_" + modes[mode]), list_all_acc)
np.save(("CAD_target_" + modes[mode]), list_all_target)
np.save(("CAD_output_" + modes[mode]), list_all_output)
#######################################################################################################################
def m2i_evaluate(y, thh1, thh2, shh, ske1, ske2, view):
list_acc = []
list_output = []
list_target = []
all_acc = 0
trials = 0
for t in range(5):
permutations = shuffle(40)
for fold in range(5):
trials += 1
[train_y, train_thh1, train_thh2, train_ske1, train_ske2, train_shh,
test_y, test_thh1, test_thh2, test_ske1, test_ske2, test_shh] = \
m2i_get_data(y, thh1, thh2, shh, ske1, ske2, fold, view, permutations)
solver = M2ISolver(train_y, train_thh1, train_thh2, train_ske1, train_ske2, train_shh,
test_y, test_thh1, test_thh2, test_ske1, test_ske2, test_shh)
acc, output, target = solver.solve(view)
all_acc += acc
print (all_acc / trials)
list_acc.append(acc)
list_output.append(output)
list_target.append(target)
np.save("sub_m2i_acc.ny", list_acc)
np.save("sub_m2i_output.ny", list_output)
np.save("sub_m2i_target.ny", list_target)
def test_m2i(view):
main_path = './data/M2I'
path_to_dataset = '{1}/{0}.pik'.format("dataset", main_path)
data = cPickle.load(open(path_to_dataset))
y = data['labels']
thh1 = data['temporal_human_human_1']
thh2 = data['temporal_human_human_2']
ske1 = data['ske_1']
ske2 = data['ske_2']
shh = data['spatial_human_human']
m2i_evaluate(y, thh1, thh2, shh, ske1, ske2, view=view)
#######################################################################################################################
def sbu_evaluate(y, ske1, ske2, thh1, thh2, shh):
list_acc = []
list_output = []
list_target = []
all_acc = 0
trials = 0
for t in range(5):
permutations = shuffle(len(list_y))
for fold in range(5):
trials += 1
[train_y, train_ske1, train_ske2, train_thh1, train_thh2, train_shh,
test_y, test_ske1, test_ske2, test_thh1, test_thh2, test_shh] = \
get_train_test_data(y, ske1, ske2, thh1, thh2, shh, permutations, fold)
solver = SBUSolver(train_y, train_ske1, train_ske2, train_thh1, train_thh2, train_shh,
test_y, test_ske1, test_ske2, test_thh1, test_thh2, test_shh, fold)
acc, output, target = solver.solve()
all_acc += acc
print (all_acc / trials)
list_acc.append(acc)
list_output.append(output)
list_target.append(target)
np.save("sbu_acc.ny", list_acc)
np.save("sbu_output.ny", list_output)
np.save("sbu_target.ny", list_target)
def test_sbu():
main_path = './data/SBU'
path_to_dataset = '{1}/{0}.pik'.format("dataset", main_path)
data = cPickle.load(open(path_to_dataset))
y = data['labels']
thh1 = data['temporal_human_human_1']
thh2 = data['temporal_human_human_2']
ske1 = data['ske_1']
ske2 = data['ske_2']
shh = data['spatial_human_human']
sbu_evaluate(y, thh1, thh2, shh, ske1, ske2)
#######################################################################################################################
def cad():
for i in range(0, 4):
test_cad(mode=i)
def m2i():
for i in range(0, 1):
test_m2i(view=i)
def sbu():
for i in range(0, 1):
test_sbu()
# parameter : gpu device, cnmem value, dataset
# list datasets: cad, sbu, m2i
if __name__ == '__main__':
# set_environ(sys.argv[1], sys.argv[2])
set_environ("cpu", "0.8")
from solver.cad_solver import *
cad()
if sys.argv[3] == 'cad':
print "CAD"
from solver.cad_solver import *
cad()
elif sys.argv[3] == 'sbu':
print "SBU"
from solver.sbu_solver import *
sbu()
elif sys.argv[3] == 'm2i':
print "M2I"
from solver.m2i_solver import *
m2i()
else:
print "Fail..."