def make_env_all_params(rank, add_monitor, args): if args["env_kind"] == 'atari': env = gym.make(args['env']) assert 'NoFrameskip' in env.spec.id env = NoopResetEnv(env, noop_max=args['noop_max']) env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) env = ExtraTimeLimit(env, args['max_episode_steps']) if 'Montezuma' in args['env']: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) elif args["env_kind"] == 'mario': env = make_mario_env() elif args["env_kind"] == "retro_multi": env = make_multi_pong() elif args["env_kind"] == 'robopong': if args["env"] == "pong": env = make_robo_pong() elif args["env"] == "hockey": env = make_robo_hockey() elif args["env_kind"] == "my_games": env = gym.make(args['env']) env = MaxAndSkipEnv(env, skip=4) env = WarpFrame(env) env = FrameStack(env, 4) if add_monitor: env = Monitor(env, osp.join(logger.get_dir(), '%.2i' % rank)) return env
def make_env_all_params(rank, add_monitor, args): if args["env_kind"] == 'atari': env = gym.make(args['env']) assert 'NoFrameskip' in env.spec.id if args["stickyAtari"]: # 在智能体执行动作时增加随机性 env._max_episode_steps = args['max_episode_steps'] * 4 env = StickyActionEnv(env) else: env = NoopResetEnv(env, noop_max=args['noop_max']) env = MaxAndSkipEnv(env, skip=4) # 每个动作连续执行4步 env = ProcessFrame84(env, crop=False) # 处理观测 env = FrameStack(env, 4) # 将连续4帧叠加起来作为输入 env = ExtraTimeLimit(env, args['max_episode_steps']) if not args["stickyAtari"]: env = ExtraTimeLimit(env, args['max_episode_steps']) # 限制了一个周期的最大时间步 if 'Montezuma' in args['env']: # 记录智能体的位置, 所在的房间, 已经访问的房间 env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) elif args["env_kind"] == 'mario': # 超级马里奥 env = make_mario_env() elif args["env_kind"] == "retro_multi": # 多智能体游戏, Multi-Pong env = make_multi_pong() elif args["env_kind"] == 'robopong': if args["env"] == "pong": env = make_robo_pong() elif args["env"] == "hockey": env = make_robo_hockey() if add_monitor: env = Monitor(env, osp.join(logger.get_dir(), '%.2i' % rank)) return env
def make_env_all_params(rank, add_monitor, args): if args["env_kind"] == "atari": env = gym.make(args["env"]) assert "NoFrameskip" in env.spec.id # from self-supervised exploration via disagreement if args["stickyAtari"] == "true": env = StickyActionEnv(env) env._max_episode_steps = args["max_episode_steps"] * 4 env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) env = ExtraTimeLimit(env, args["max_episode_steps"]) if "Montezuma" in args["env"]: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) if args["noisy_tv"] == "true": env = NoisyTVEnvWrapper(env) # assert env.action_space == spaces.Discrete(7) elif args["env_kind"] == "mario": env = make_mario_env() if args["noisy_tv"] == "true": env = NoisyTVEnvWrapperMario(env) elif args["env_kind"] == "retro_multi": env = make_multi_pong() elif args["env_kind"] == "robopong": if args["env"] == "pong": env = make_robo_pong() elif args["env"] == "hockey": env = make_robo_hockey() if add_monitor: env = Monitor(env, osp.join(logger.get_dir(), "%.2i" % rank)) return env
def make_env_all_params(rank, add_monitor, args, logdir): if args["env_kind"] == 'atari': env = gym.make(args['env']) assert 'NoFrameskip' in env.spec.id env = NoopResetEnv(env, noop_max=args['noop_max']) env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) env = ExtraTimeLimit(env, args['max_episode_steps']) if 'Montezuma' in args['env']: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) elif args["env_kind"] == 'mario': env = make_mario_env() elif args["env_kind"] == "retro_multi": env = make_multi_pong() elif args["env_kind"] == 'robopong': if args["env"] == "pong": env = make_robo_pong() elif args["env"] == "hockey": env = make_robo_hockey() elif args["env_kind"] == "dm_suite": env = make_dm_suite(task=args["env"], logdir=logdir, to_record=args["to_record"]) if add_monitor: env = TempMonitor(env) return env
def make_env_all_params(rank, add_monitor, args, sleep_multiple=2): if args["env_kind"] == 'ObstacleTowerEnv': env = _make_obs_env(rank, add_monitor, args, sleep_multiple) elif args["env_kind"] == 'atari': env = gym.make(args['env']) assert 'NoFrameskip' in env.spec.id env = NoopResetEnv(env, noop_max=args['noop_max']) env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) env = ExtraTimeLimit(env, args['max_episode_steps']) if 'Montezuma' in args['env']: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) if rank == 2: env = RenderWrapper(env) elif args["env_kind"] == 'mario': env = make_mario_env() elif args["env_kind"] == "retro_multi": env = make_multi_pong() elif args["env_kind"] == 'robopong': if args["env"] == "pong": env = make_robo_pong() elif args["env"] == "hockey": env = make_robo_hockey() if add_monitor: logdir = osp.join('summaries', args["exp_name"]) logger.configure(logdir) env = Monitor(env, osp.join(logger.get_dir(), '%.2i' % rank)) return env
def make_env_all_params(rank, add_monitor, args): if args["env_kind"] == 'atari': env = gym.make(args['env']) assert 'NoFrameskip' in env.spec.id env = NoopResetEnv(env, noop_max=args['noop_max']) env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) env = ExtraTimeLimit(env, args['max_episode_steps']) if 'Montezuma' in args['env']: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) elif args["env_kind"] == 'mario': env = make_mario_env() elif args["env_kind"] == "retro_multi": env = make_multi_pong() elif args["env_kind"] == 'robopong': if args["env"] == "pong": env = make_robo_pong() elif args["env"] == "hockey": env = make_robo_hockey() if args["env_kind"] == 'atari' and add_monitor: #env = Monitor(env, osp.join(logger.get_dir(), '%.2i' % rank)) env = Monitor(env, os.path.join(os.getcwd(), 'test_video'), force=True, video_callable=lambda episode_id: episode_id % 20 == 0) #env = Monitor(env, os.path.join(os.getcwd(), 'test_video'),video_callable=lambda episode_id: True )#,force=True) return env
def make_env_all_params(rank, add_monitor, args): if args["env_kind"] == 'atari': env = gym.make(args['env']) assert 'NoFrameskip' in env.spec.id env = NoopResetEnv(env, noop_max=args['noop_max']) env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) env = ExtraTimeLimit(env, args['max_episode_steps']) if 'Montezuma' in args['env']: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) elif args["env_kind"] == 'field': import gym_fieldedmove env = gym.make('FieldedMove-v0') # env = FrameStack(env, 4) elif args["env_kind"] == "ple": import gym_ple env = gym.make(args['env']) env._max_episode_steps = args['max_episode_steps'] # env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) if add_monitor: env = Monitor(env, osp.join(logger.get_dir(), '%.2i' % rank)) return env
def make_env_all_params(rank, args): env = gym.make(GAME_NAME) env = NoopResetEnv(env, noop_max=NOOP_MAX) env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) # env = ExtraTimeLimit(env,10000) env = AddRandomStateToInfo(env) env = Monitor( env, os.path.join( 'C:/Users/Elias/OneDrive/Winfo Studium/SS19/Masterarbeit/logs', '%.2i' % rank)) return env
def make_env_all_params(rank, add_monitor, args): if args["env_kind"] == 'atari': env = gym.make(args['env']) assert 'NoFrameskip' in env.spec.id env = NoopResetEnv(env, noop_max=args['noop_max']) env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) env = ExtraTimeLimit(env, args['max_episode_steps']) if 'Montezuma' in args['env']: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) elif args["env_kind"] == 'mario': env = make_mario_env() elif args["env_kind"] == "retro_multi": env = make_multi_pong() elif args["env_kind"] == 'robopong': if args["env"] == "pong": env = make_robo_pong() elif args["env"] == "hockey": env = make_robo_hockey() if add_monitor: #print(osp.join(logger.get_dir(), '%.2i' % rank + '.monitor.csv')) env = Monitor(env, osp.join(logger.get_dir(), '%.2i' % rank)) """ env = DummyVecEnv([lambda: env]) env = VecVideoRecorder(env, directory = './vid', record_video_trigger=lambda step: step == 0, video_length= 100,) env.reset() """ #env = wrappers.Monitor(env,'./vid/',force = True,write_upon_reset = True, video_callable=lambda episode: True) #print(osp.join(logger.get_dir())) #env = Monitor(env, osp.join(logger.get_dir())) #env = Monitor(env, "./vid", video_callable=lambda episode_id: True,force=True) return env
def make_atari_env(self, args): """ duplicated code hack due to relative import errors """ env = gym.make(args["env"]) assert "NoFrameskip" in env.spec.id # from self-supervised exploration via disagreement if args["stickyAtari"] == "true": env = StickyActionEnv(env) env._max_episode_steps = args["max_episode_steps"] * 4 env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStackNoLazy(env, 4) env = ExtraTimeLimit(env, args["max_episode_steps"]) if "Montezuma" in args["env"]: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) if args["noisy_tv"] == "true": env = NoisyTVEnvWrapper(env) return env
def make_env_all_params(rank, add_monitor, args): if args["env_kind"] == 'atari': env = gym.make(args['env']) assert 'NoFrameskip' in env.spec.id if args["stickyAtari"]: env._max_episode_steps = args['max_episode_steps'] * 4 env = StickyActionEnv(env) else: env = NoopResetEnv(env, noop_max=args['noop_max']) env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) if not args["stickyAtari"]: env = ExtraTimeLimit(env, args['max_episode_steps']) if 'Montezuma' in args['env']: env = MontezumaInfoWrapper(env) env = AddRandomStateToInfo(env) elif args["env_kind"] == 'mario': env = make_mario_env() elif args["env_kind"] == "retro_multi": env = make_multi_pong() elif args["env_kind"] == 'unity': env = make_unity_maze(args["env"], seed=args["seed"], rank=rank, ext_coeff=args["ext_coeff"], recordUnityVid=args['recordUnityVid'], expID=args["unityExpID"], startLoc=args["startLoc"], door=args["door"], tv=args["tv"], testenv=args["testenv"], logdir=logger.get_dir()) if add_monitor: env = Monitor(env, osp.join(logger.get_dir(), '%.2i' % rank)) return env
ActionLoggingWrapper, ) def get_car_mask(frames, car_color=np.array([223, 183, 85])): mask = np.zeros(shape=frames[0].shape) for a_frame in frames: for i in range(a_frame.shape[0]): for j in range(a_frame.shape[1]): if np.array_equal(a_frame[i][j], car_color): mask[i][j] += 1 return mask env = gym.make("BankHeistNoFrameskip-v4") env = gym.wrappers.Monitor(env, "./video/", force=True) env._max_episode_steps = 4000 * 4 env = MaxAndSkipEnv(env, skip=4) env = ProcessFrame84(env, crop=False) env = FrameStack(env, 4) env = ExtraTimeLimit(env, 4000) env = AddRandomStateToInfo(env) obs = env.reset() for _ in range(100): obs, reward, done, info = env.step(env.action_space.sample()) import pdb pdb.set_trace()