-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.py
70 lines (60 loc) · 2.27 KB
/
main.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
import os
os.environ["MUJOCO_GL"] = "egl"
import argparse
from datetime import datetime
from torch.utils.tensorboard import SummaryWriter
from dreamer.algorithms.dreamer import Dreamer
from dreamer.algorithms.plan2explore import Plan2Explore
from dreamer.utils.utils import load_config, get_base_directory
from dreamer.envs.envs import make_dmc_env, make_atari_env, get_env_infos
def main(config_file):
config = load_config(config_file)
if config.environment.benchmark == "atari":
env = make_atari_env(
task_name=config.environment.task_name,
seed=config.environment.seed,
height=config.environment.height,
width=config.environment.width,
skip_frame=config.environment.frame_skip,
pixel_norm=config.environment.pixel_norm,
)
elif config.environment.benchmark == "dmc":
env = make_dmc_env(
domain_name=config.environment.domain_name,
task_name=config.environment.task_name,
seed=config.environment.seed,
visualize_reward=config.environment.visualize_reward,
from_pixels=config.environment.from_pixels,
height=config.environment.height,
width=config.environment.width,
frame_skip=config.environment.frame_skip,
pixel_norm=config.environment.pixel_norm,
)
obs_shape, discrete_action_bool, action_size = get_env_infos(env)
log_dir = (
get_base_directory()
+ "/runs/"
+ datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
+ "_"
+ config.operation.log_dir
)
writer = SummaryWriter(log_dir)
device = config.operation.device
if config.algorithm == "dreamer-v1":
agent = Dreamer(
obs_shape, discrete_action_bool, action_size, writer, device, config
)
elif config.algorithm == "plan2explore":
agent = Plan2Explore(
obs_shape, discrete_action_bool, action_size, writer, device, config
)
agent.train(env)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--config",
type=str,
default="dmc-walker-walk.yml",
help="config file to run(default: dmc-walker-walk.yml)",
)
main(parser.parse_args().config)