-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
77 lines (69 loc) · 1.89 KB
/
test.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
67
68
69
70
71
72
73
74
75
76
77
import argparse
import torch
import utils
from models import MlpPolicy
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
dtype = torch.double
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-pp", "--policy_path", type=str, required=True, help="path to policy weights"
)
parser.add_argument(
"-hd",
"--policy_hidden_dim",
type=int,
required=True,
help="dimension of hidden layer",
)
parser.add_argument(
"-en",
"--env_name",
type=str,
required=True,
help="name of gym envrionment to test in",
)
parser.add_argument(
"-ne",
"--num_episodes",
type=int,
default=10,
help="number of episodes to test for",
)
parser.add_argument(
"-d", "--deterministic", help="use deterministic policy", action="store_true"
)
parser.add_argument(
"-el",
"--max_episode_len",
type=int,
default=1000,
help="maximum number of steps per episode",
)
parser.add_argument(
"-ld",
"--log_dir",
type=str,
required=False,
help="directory to store log file in",
)
parser.add_argument(
"-v", "--verbose", help="increase output verbosity", action="store_true"
)
args = parser.parse_args()
env = utils.make_env(args.env_name)
observation_size = env.observation_space.shape[0]
action_size = env.action_space.n
policy = MlpPolicy(observation_size, action_size, args.policy_hidden_dim)
checkpoint = torch.load(args.policy_path)
policy.load_state_dict(checkpoint["policy_state_dict"])
utils.test_policy(
policy,
env,
args.num_episodes,
args.deterministic,
args.max_episode_len,
args.log_dir,
args.verbose,
)
env.close()