-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patheval_avrg.py
66 lines (51 loc) · 1.58 KB
/
eval_avrg.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
import sys
import numpy as np
import glob
import utils
if len(sys.argv) < 2:
sys.exit("Usage: python eval_avrg.py <predictions_path> [subset=test]")
predictions_path_all = glob.glob(sys.argv[1] + "*")
print "shape of metadata_path_all"
print(len(predictions_path_all))
mybool = False
for predictions_path in predictions_path_all:
print(predictions_path)
if not mybool:
predictions = np.load(predictions_path)#.ravel()
mybool = True
else:
predictions = predictions + np.load(predictions_path)#.ravel()
print "shape of predictions"
print(predictions.shape)
print(predictions.max())
import data
if len(sys.argv) == 3:
subset = sys.argv[2]
assert subset in ['train', 'valid', 'test', 'test_valid']
else:
subset = 'test'
if subset == "test":
_, mask, y, _ = data.get_test()
elif subset == "train":
y = data.labels_train
mask = data.mask_train
elif subset == "train_valid":
y = data.labels
mask = data.mask
else:
y = data.labels_valid
mask = data.mask_valid
acc = utils.proteins_acc(predictions, y, mask)
print "Accuracy (%s) is: %.5f" % (subset,acc)
## Alternative model avrg!! ##
john = np.zeros((640,700,8))
for predictions_path in predictions_path_all:
print(predictions_path)
predictions = np.load(predictions_path)#.ravel()
predictions = np.argmax(predictions, axis=2)
for i in range(640):
for j in range(700):
num = predictions[i, j]
john[i, j, num] = john[i, j, num] + 1
acc = utils.proteins_acc(john, y, mask)
print "Alternative accuracy (%s) is: %.5f" % (subset,acc)