forked from soprof/face-identification-tpe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4_test_tpe.py
56 lines (38 loc) · 1.34 KB
/
4_test_tpe.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
import json
import matplotlib.pyplot as plt
import numpy as np
from bottleneck import Bottleneck
from cnn import build_cnn
from identification import get_scores, calc_metrics
from tpe import build_tpe
n_in = 256
n_out = 256
with open('data/meta.json', 'r') as f:
meta = json.load(f)
cnn = build_cnn(227, meta['n_subjects'])
cnn.load_weights('data/weights/weights.best.h5')
bottleneck = Bottleneck(cnn, ~1)
train_x, train_y = np.load('data/train_x.npy'), np.load('data/train_y.npy')
dev_x = np.load('data/dev_x.npy')
dev_protocol = np.load('data/dev_protocol.npy')
train_emb = bottleneck.predict(train_x, batch_size=256)
dev_emb = bottleneck.predict(dev_x, batch_size=256)
del train_x
W_pca = np.load('data/w_pca.npy')
tpe, tpe_pred = build_tpe(n_in, n_out, W_pca.T)
train_y = np.array(train_y)
subjects = list(set(train_y))
tpe.load_weights('data/weights/weights.tpe.mineer.h5')
dev_emb2 = tpe_pred.predict(dev_emb)
protocol = np.load('data/dev_protocol.npy')
tsc, isc = get_scores(dev_emb2, protocol)
eer, fars, frrs, dists = calc_metrics(tsc, isc)
print('EER: {}'.format(eer * 100))
plt.figure()
plt.hist(tsc, 20, color='g', normed=True, alpha=0.3)
plt.hist(isc, 20, color='r', normed=True, alpha=0.3)
plt.figure()
plt.loglog(fars, frrs)
plt.show()
for a, b, c in zip(fars, frrs, dists):
print('a: {:.2f} | r: {:.2f} | d: {:.2f}'.format(a, b, c))