-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathone_shot_tests.py
54 lines (37 loc) · 1.22 KB
/
one_shot_tests.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
predictor_file = 'ConvARC_OSFC.opf'
embedder_file = 'ConvARC_OS.emf'
embedding_size = 256
import numpy as np
from main import deserialize
from data_workers import OmniglotOSLake, OmniglotVinyals
np.random.seed(1969)
if embedder_file is None:
predictor = deserialize(predictor_file)
else:
def predictor(X):
predictor = deserialize(predictor_file)
embedder = deserialize(embedder_file)
embeddings = embedder(X).reshape(-1, 20, embedding_size)
return predictor(embeddings)
print "\n ... testing on the set by Brenden Lake et al"
worker = OmniglotOSLake()
X_OS, t_OS = worker.fetch_batch()
all_acc = []
for run in range(20):
X = X_OS[run]
t = t_OS[run]
y = predictor(X).reshape(20, 20).argmax(axis=1)
run_acc = np.mean(y == t) * 100.0
print "run ", run + 1, ": ", run_acc
all_acc.append(run_acc)
print "accuracy: ", np.mean(all_acc), "%"
print "\n\n ... testing on the method of Vinyals et al"
worker = OmniglotVinyals(num_trials=20)
all_acc = []
for run in range(20):
X, t = worker.fetch_batch()
y = predictor(X).reshape(20, 20).argmax(axis=1)
run_acc = np.mean(y == t) * 100.0
print "run ", run + 1, ": ", run_acc
all_acc.append(run_acc)
print "accuracy: ", np.mean(all_acc), "%"