forked from kenziyuliu/MS-G3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ensemble.py
52 lines (42 loc) · 1.73 KB
/
ensemble.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
import argparse
import pickle
import os
import numpy as np
from tqdm import tqdm
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--dataset',
required=True,
choices={'kinetics', 'ntu/xsub', 'ntu/xview', 'ntu120/xsub', 'ntu120/xset'},
help='the work folder for storing results')
parser.add_argument('--alpha',
default=1,
help='weighted summation',
type=float)
parser.add_argument('--joint-dir',
help='Directory containing "epoch1_test_score.pkl" for joint eval results')
parser.add_argument('--bone-dir',
help='Directory containing "epoch1_test_score.pkl" for bone eval results')
arg = parser.parse_args()
dataset = arg.dataset
with open('./data/' + dataset + '/val_label.pkl', 'rb') as label:
label = np.array(pickle.load(label))
with open(os.path.join(arg.joint_dir, 'epoch1_test_score.pkl'), 'rb') as r1:
r1 = list(pickle.load(r1).items())
with open(os.path.join(arg.bone_dir, 'epoch1_test_score.pkl'), 'rb') as r2:
r2 = list(pickle.load(r2).items())
right_num = total_num = right_num_5 = 0
for i in tqdm(range(len(label[0]))):
_, l = label[:, i]
_, r11 = r1[i]
_, r22 = r2[i]
r = r11 + r22 * arg.alpha
rank_5 = r.argsort()[-5:]
right_num_5 += int(int(l) in rank_5)
r = np.argmax(r)
right_num += int(r == int(l))
total_num += 1
acc = right_num / total_num
acc5 = right_num_5 / total_num
print('Top1 Acc: {:.4f}%'.format(acc * 100))
print('Top5 Acc: {:.4f}%'.format(acc5 * 100))