-
Notifications
You must be signed in to change notification settings - Fork 15
/
metrics_test.py
83 lines (77 loc) · 4.58 KB
/
metrics_test.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
from __future__ import print_function
import numpy as np
import tensorflow as tf
from metrics import accuracy_for_multi_labels
from prediction import prediction_for_multi_labels
def test_accuracy_for_multi_labels():
num_of_labels = 4
num_of_classes = 5
outputs = np.array([[4.99681782, 2.5449166, 3.59851902, 2.93910773, 4.17776855,
0.82802286, 0.7660328, 0.12681463, 1.06140617, 4.09380737,
1.20046922, 0.65646037, 2.69502235, 1.19470781, 0.73385955,
0.44339209, 2.86514447, 4.14568994, 2.6289632, 0.39199794],
[3.09852315, 0.47730157, 1.58699892, 2.82020567, 3.58467503,
4.65120107, 1.74212269, 4.3349567, 3.59780674, 3.36965552,
4.72054533, 3.43597533, 4.54475683, 2.94840863, 4.15017575,
0.77346597, 1.73233179, 4.72401863, 4.82410535, 2.66244787],
[4.09532858, 2.18927335, 3.41796497, 1.06257277, 4.59626738,
1.07984969, 1.48959167, 4.11504586, 1.84053099, 0.18985388,
1.64658045, 3.05094146, 0.57888684, 3.38604911, 2.56712342,
1.14614549, 3.70737666, 1.6989225, 2.33104953, 3.33577786],
[1.53485214, 3.92794649, 4.0452425, 1.7745993, 1.69337229,
0.03228188, 2.55190603, 1.71395322, 3.64202675, 0.92880045,
1.75798402, 1.61594338, 3.37993585, 2.12929893, 4.28906818,
2.97361642, 4.32325568, 0.19917952, 2.51286098, 2.55798653],
[0.80739248, 0.18273517, 4.87117453, 4.29166104, 2.72126087,
0.46191234, 2.14900509, 3.83688963, 2.44600884, 4.34881122,
4.56694027, 0.4768854, 3.87800566, 0.02566184, 4.9239864,
2.25733771, 1.91447157, 0.20578796, 0.11195605, 4.28163385],
[0.33973778, 4.1497402, 3.81487573, 3.9842531, 1.79923239,
2.96962849, 3.5104444, 4.70109585, 3.63469214, 3.21617235,
2.4060019, 4.33236642, 2.49415596, 4.0081272, 3.49519607,
3.92563381, 0.40659552, 0.52358287, 1.02667035, 0.71006217],
[3.92315635, 3.81223511, 1.90268283, 2.4643171, 4.79768325,
1.95603233, 4.4950626, 1.41904349, 3.47883992, 0.40089586,
3.55676389, 4.65740336, 0.22694078, 1.50637295, 3.57101888,
3.05543341, 4.90039912, 2.39803593, 1.16041763, 0.57390039],
[1.35758684, 0.86832658, 4.40503158, 2.31449119, 4.70593785,
2.83028668, 4.00291333, 2.46070415, 2.42569892, 3.63232648,
0.05173801, 3.64824024, 1.94524601, 2.92093634, 4.95776275,
4.3641641, 1.74693578, 1.43486961, 0.71867051, 3.85289734],
[0.79532995, 0.04225455, 0.90453193, 4.14272626, 0.6975047,
0.08842952, 2.42948905, 2.54846674, 4.94954695, 3.75107859,
4.6077492, 0.89163213, 2.50115542, 0.03165254, 4.75373429,
2.71096527, 2.07635828, 1.21502929, 4.57668165, 0.18099578],
[4.27672129, 3.51281143, 1.17071046, 2.74572427, 0.53170123,
0.30948912, 1.16988546, 4.93860773, 1.2809703, 2.94217718,
4.07134319, 3.78792574, 2.62190736, 0.9544619, 2.71195486,
2.53130831, 2.47942593, 2.9706149, 0.77646827, 2.89172347]])
outputs = outputs.astype(np.float32)
predictions = prediction_for_multi_labels(outputs, num_of_labels, num_of_classes)
# targets = np.array([[0, 4, 2, 2],
# [4, 0, 0, 3],
# [4, 2, 3, 1],
# [2, 3, 4, 1],
# [2, 4, 4, 4],
# [1, 2, 1, 0],
# [4, 1, 1, 1],
# [4, 1, 4, 0],
# [3, 3, 4, 3],
# [0, 2, 0, 2]])
targets = np.array([[0, 4, 2, 2],
[4, 0, 0, 3],
[4, 2, 3, 1],
[2, 2, 4, 1],
[2, 4, 4, 4],
[1, 2, 1, 0],
[4, 3, 1, 1],
[4, 1, 4, 0],
[3, 3, 1, 3],
[1, 1, 0, 2]])
accuracy = accuracy_for_multi_labels(predictions, targets)
with tf.Session() as sess:
preds, acc = sess.run([predictions, accuracy])
print("predictions:", preds)
print("acc:", acc)
if __name__ == '__main__':
test_accuracy_for_multi_labels()