-
Notifications
You must be signed in to change notification settings - Fork 22
/
read_npz.py
124 lines (95 loc) · 3.86 KB
/
read_npz.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
import argparse
import os
import sys
import math
import cv2
import numpy as np
import multiprocessing
from sklearn.metrics import confusion_matrix
relative_path = "/data4/lilin/zjg_code"
caffe_root = relative_path + "/temporal-segment-networks/lib/caffe-action/"
sys.path.insert(0, caffe_root + 'python')
from pyActionRecog import parse_directory
from pyActionRecog import parse_split_file
from pyActionRecog.utils.video_funcs import default_aggregation_func, ave_aggregation_func, sci_crop_aggregation_func, sci_stream_aggregation_func, sci_crop_stream_aggregation_func
num_scores = 1
# nn = float(7)/13
# print nn
#
# r = np.load("/data/lilin/lilin_code/zjg_code/tle/ucf101_split_1_rgb_seg124_3dropout_imagenet_stage_2_lr_0.0001_iter_600.npz")
# r = np.load("/data/lilin/lilin_code/zjg_code/tle/ucf101_split_1_rgb_seg124_3dropout_stage_2_lr_0.00001_iter_2100.npz")
# video_scores_1 = r['scores']
# #video_scores_1 = video_scores_1.reshape(3783,10,101)
# video_labels_1 = r['labels']
r = np.load("/data/lilin/lilin_code/zjg_code/tle/hmdb51_split_1_tsn_flow_score.npz")
video_scores = r['scores']
video_labels = r['labels']
def gated_fusion(i):
video_pred = [np.argmax(default_aggregation_func(x[i], normalization=False)) for x in video_scores]
video_labels = [x[num_scores] for x in video_scores]
cf = confusion_matrix(video_labels, video_pred).astype(float)
cls_cnt = cf.sum(axis=1)
cls_hit = np.diag(cf)
cls_acc = cls_hit/cls_cnt
print cls_acc
print 'Accuracy {:.02f}%'.format(np.mean(cls_acc)*100)
def ave_fusion(i, j, weight = 1):
video_pred = [np.argmax(ave_aggregation_func(x[i], x[j], weight = weight)) for x in video_scores]
video_labels = [x[num_scores] for x in video_scores]
cf = confusion_matrix(video_labels, video_pred).astype(float)
cls_cnt = cf.sum(axis=1)
cls_hit = np.diag(cf)
cls_acc = cls_hit/cls_cnt
print cls_acc
print 'Accuracy {:.02f}%'.format(np.mean(cls_acc)*100)
def ave_fusion(x, y, weight = 1):
video_pred = [np.argmax(ave_aggregation_func(x[i], x[j], weight = weight)) for x in video_scores]
video_labels = [x[num_scores] for x in video_scores]
cf = confusion_matrix(video_labels, video_pred).astype(float)
cls_cnt = cf.sum(axis=1)
cls_hit = np.diag(cf)
cls_acc = cls_hit/cls_cnt
print cls_acc
print 'Accuracy {:.02f}%'.format(np.mean(cls_acc)*100)
def sci_fusion_crop(i, j):
video_pred = [np.argmax(sci_crop_aggregation_func(x[i], x[j])) for x in video_scores]
video_labels = [x[num_scores] for x in video_scores]
cf = confusion_matrix(video_labels, video_pred).astype(float)
cls_cnt = cf.sum(axis=1)
cls_hit = np.diag(cf)
cls_acc = cls_hit/cls_cnt
print cls_acc
print 'Accuracy {:.02f}%'.format(np.mean(cls_acc)*100)
def sci_fusion_stream(i, j):
video_pred = [np.argmax(sci_stream_aggregation_func(x[i], x[j])) for x in video_scores]
video_labels = [x[num_scores] for x in video_scores]
cf = confusion_matrix(video_labels, video_pred).astype(float)
cls_cnt = cf.sum(axis=1)
cls_hit = np.diag(cf)
cls_acc = cls_hit/cls_cnt
print cls_acc
print 'Accuracy {:.02f}%'.format(np.mean(cls_acc)*100)
def sci_fusion_crop_stream(i, j):
video_pred = [np.argmax(sci_crop_stream_aggregation_func(x[i], x[j])) for x in video_scores]
video_labels = [x[num_scores] for x in video_scores]
cf = confusion_matrix(video_labels, video_pred).astype(float)
cls_cnt = cf.sum(axis=1)
cls_hit = np.diag(cf)
cls_acc = cls_hit/cls_cnt
print cls_acc
print 'Accuracy {:.02f}%'.format(np.mean(cls_acc)*100)
print "Gated fusion\n"
gated_fusion(0)
# print "ave fusion\n"
# ave_fusion(1, 2)
# print "weighted ave fusion\n"
# ave_fusion(1, 2, weight = 2)
#
# print "sci fusion crop\n"
# sci_fusion_crop(1, 2)
# #
# print "sci fusion stream \n"
# sci_fusion_stream(1, 2)
#
# print "sci fusion crop stream \n"
# sci_fusion_crop_stream(1, 2)