-
Notifications
You must be signed in to change notification settings - Fork 72
/
eval_covmat.py.py
48 lines (40 loc) · 1.42 KB
/
eval_covmat.py.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
import os
import argparse
import pickle
import torch
from utils.datasets import PackedConformationDataset
from utils.evaluation.covmat import CovMatEvaluator, print_covmat_results
from utils.misc import *
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('path', type=str)
parser.add_argument('--num_workers', type=int, default=8)
parser.add_argument('--ratio', type=int, default=2)
parser.add_argument('--start_idx', type=int, default=0)
args = parser.parse_args()
assert os.path.isfile(args.path)
# Logging
tag = args.path.split('/')[-1].split('.')[0]
logger = get_logger('eval', os.path.dirname(args.path), 'log_eval_'+tag+'.txt')
# Load results
logger.info('Loading results: %s' % args.path)
with open(args.path, 'rb') as f:
packed_dataset = pickle.load(f)
logger.info('Total: %d' % len(packed_dataset))
# Evaluator
evaluator = CovMatEvaluator(
num_workers = args.num_workers,
ratio = args.ratio,
print_fn=logger.info,
)
results = evaluator(
packed_data_list = list(packed_dataset),
start_idx = args.start_idx,
)
df = print_covmat_results(results, print_fn=logger.info)
# Save results
csv_fn = args.path[:-4] + '_covmat.csv'
results_fn = args.path[:-4] + '_covmat.pkl'
df.to_csv(csv_fn)
with open(results_fn, 'wb') as f:
pickle.dump(results, f)