def main(): """Main.""" args = parse_args() # env initialization env_name = "PongNoFrameskip-v4" env = atari_env_generator(env_name, args.max_episode_steps) # set a random seed common_utils.set_random_seed(args.seed, env) # run NOWTIMES = datetime.datetime.now() curr_time = NOWTIMES.strftime("%y%m%d_%H%M%S") cfg = Config.fromfile(args.cfg_path) cfg.agent.env_info = dict( env_name="PongNoFrameskip-v4", observation_space=env.observation_space, action_space=env.action_space, is_discrete=True, ) cfg.agent.log_cfg = dict(agent=cfg.agent.type, curr_time=curr_time) build_args = dict(args=args, env=env) agent = build_agent(cfg.agent, build_args) if not args.test: agent.train() elif args.test and args.grad_cam: agent.test_with_gradcam() else: agent.test()
def _init_env(self): """Initialize gym environment.""" if self.env_info.is_atari: self.env = atari_env_generator(self.env_info.name, self.args.max_episode_steps) else: self.env = gym.make(self.env_info.name) env_utils.set_env(self.env, self.args)
def main(): """Main.""" args = parse_args() # env initialization env_name = "PongNoFrameskip-v4" env = atari_env_generator(env_name, args.max_episode_steps, frame_stack=args.framestack) # set a random seed common_utils.set_random_seed(args.seed, env) # run NOWTIMES = datetime.datetime.now() curr_time = NOWTIMES.strftime("%y%m%d_%H%M%S") cfg = Config.fromfile(args.cfg_path) # If running integration test, simplify experiment if args.integration_test: cfg = common_utils.set_cfg_for_intergration_test(cfg) env_info = dict( name=env.spec.id, observation_space=env.observation_space, action_space=env.action_space, is_atari=True, ) log_cfg = dict(agent=cfg.agent.type, curr_time=curr_time, cfg_path=args.cfg_path) build_args = dict( env=env, env_info=env_info, log_cfg=log_cfg, is_test=args.test, load_from=args.load_from, is_render=args.render, render_after=args.render_after, is_log=args.log, save_period=args.save_period, episode_num=args.episode_num, max_episode_steps=env.spec.max_episode_steps, interim_test_num=args.interim_test_num, ) agent = build_agent(cfg.agent, build_args) if not args.test: agent.train() elif args.test and args.grad_cam: agent.test_with_gradcam() elif args.test and args.saliency_map: agent.test_with_saliency_map() else: agent.test()
def _init_env(self): """Intialize worker local environment.""" if self.is_atari: self.env = atari_env_generator(self.env_name, self.max_episode_steps, frame_stack=True) else: self.env = gym.make(self.env_name) env_utils.set_env(self.env, self.max_episode_steps) random.seed(self.rank) env_seed = random.randint(0, 999) set_random_seed(env_seed, self.env)
def main(): """Main.""" args = parse_args() # env initialization env_name = "PongNoFrameskip-v4" env = atari_env_generator(env_name, args.max_episode_steps) # set a random seed common_utils.set_random_seed(args.seed, env) # run NOWTIMES = datetime.datetime.now() curr_time = NOWTIMES.strftime("%y%m%d_%H%M%S") cfg = Config.fromfile(args.cfg_path) cfg.agent["log_cfg"] = dict(agent=cfg.agent.type, curr_time=curr_time) build_args = dict(args=args, env=env) agent = build_agent(cfg.agent, build_args) if not args.test: agent.train() else: agent.test()
def _thunk(rank: int): env = atari_env_generator(env_name, max_episode_steps, frame_stack=frame_stack) env.seed(777 + rank + 1) return env