-
Notifications
You must be signed in to change notification settings - Fork 36
/
eval.py
53 lines (38 loc) · 1.56 KB
/
eval.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
"""
Evaluates a trained model on a dataset.
Example usage:
python eval.py --datafile mazes.npz --mechanism news --model models.GPPN \
--k 15 --f 5 --load-file log/gppn-k15-f5/planner.final.pth
"""
from __future__ import print_function
from utils.experiment import (parse_args, create_save_dir, get_mechanism,
create_dataloader, print_stats)
from utils.runner import Runner
def main():
args = parse_args()
create_save_dir(args.save_directory)
mechanism = get_mechanism(args.mechanism)
# Create DataLoaders.
trainloader = create_dataloader(
args.datafile, "train", args.batch_size, mechanism, shuffle=True)
validloader = create_dataloader(
args.datafile, "valid", args.batch_size, mechanism, shuffle=False)
testloader = create_dataloader(
args.datafile, "test", args.batch_size, mechanism, shuffle=False)
runner = Runner(args, mechanism)
print("\n------------- Evaluating final model -------------")
print("\nTrain performance:")
print_stats(runner.test(trainloader))
print("\nValidation performance:")
print_stats(runner.test(testloader))
print("\nTest performance:")
print_stats(runner.test(validloader))
print("\n------------- Evaluating best model -------------")
print("\nTrain performance:")
print_stats(runner.test(trainloader, use_best=True))
print("\nValidation performance:")
print_stats(runner.test(testloader, use_best=True))
print("\nTest performance:")
print_stats(runner.test(validloader, use_best=True))
if __name__ == "__main__":
main()