-
Notifications
You must be signed in to change notification settings - Fork 33
/
train_expert.py
46 lines (38 loc) · 1.21 KB
/
train_expert.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
import os
import argparse
from datetime import datetime
import torch
from gail_airl_ppo.env import make_env
from gail_airl_ppo.algo import SAC
from gail_airl_ppo.trainer import Trainer
def run(args):
env = make_env(args.env_id)
env_test = make_env(args.env_id)
algo = SAC(
state_shape=env.observation_space.shape,
action_shape=env.action_space.shape,
device=torch.device("cuda" if args.cuda else "cpu"),
seed=args.seed
)
time = datetime.now().strftime("%Y%m%d-%H%M")
log_dir = os.path.join(
'logs', args.env_id, 'sac', f'seed{args.seed}-{time}')
trainer = Trainer(
env=env,
env_test=env_test,
algo=algo,
log_dir=log_dir,
num_steps=args.num_steps,
eval_interval=args.eval_interval,
seed=args.seed
)
trainer.train()
if __name__ == '__main__':
p = argparse.ArgumentParser()
p.add_argument('--num_steps', type=int, default=10**6)
p.add_argument('--eval_interval', type=int, default=10**4)
p.add_argument('--env_id', type=str, default='Hopper-v3')
p.add_argument('--cuda', action='store_true')
p.add_argument('--seed', type=int, default=0)
args = p.parse_args()
run(args)