-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscore_test_em.py
66 lines (46 loc) · 1.34 KB
/
score_test_em.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 argparse
import json
import os
import numpy as np
import torch
from deconv.gmm.online_deconv_gmm import OnlineDeconvGMM
from deconv.gmm.data import DeconvDataset
def score_em(datafile, results_dir, output_file):
data = np.load(datafile)
test_data = SGDDeconvDataset(
torch.Tensor(data['X_test']),
torch.Tensor(data['C_test'])
)
rf = os.listdir(results_dir)
param_files = [
f for f in rf if f.startswith('em_512') and f.endswith('.pkl')
]
gmm = OnlineDeconvGMM(
512,
7,
batch_size=500
)
scores = []
for p in param_files:
weights, means, covars = torch.load(
results_dir + p,
map_location=torch.device('cpu')
)
gmm.weights = weights
gmm.means = means
gmm.covars = covars
test_score = gmm.score_batch(test_data)
print(test_score)
scores.append(test_score)
print('Test Score: {} +- {}'.format(
np.mean(scores),
np.std(scores)
))
json.dump(scores, open(output_file, 'w'))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('datafile')
parser.add_argument('results_dir')
parser.add_argument('output_file')
args = parser.parse_args()
score_em(args.datafile, args.results_dir, args.output_file)