Exemple #1
0
def wrap_modified_rr(env, episode_life=True, episode_reward=False, episode_frame=False,
                     norm_rewards=True,
                     frame_stack=False, scale=False):
    """Configure environment for DeepMind-style Atari modified as described in RUDDER paper;
    """
    if episode_life:
        print("Episode Life")
        env = EpisodicLifeEnv(env)
    if episode_reward:
        print("Episode Reward")
        env = EpisodicRewardEnv(env)
    if episode_frame:
        print("Episode Frame")
        env = EpisodicFrameEnv(env)
    _ori_r_games = ['DoubleDunk', 'Boxing', 'Freeway', 'Pong',
                    'Bowling', 'Skiing', 'IceHockey', 'Enduro']
    original_reward = any([game in env.spec.id for game in _ori_r_games])

    if 'FIRE' in env.unwrapped.get_action_meanings():
        env = FireResetEnv(env)
    env = WarpFrame(env)
    if scale:
        env = ScaledFloatFrame(env)
    if norm_rewards and not original_reward:
        print("Normalizing reward....")
        env = NormRewardEnv(env, 100.)
    else:
        print("Normal reward")
    if frame_stack:
        env = FrameStack(env, 4)
    return env
Exemple #2
0
def wrap_deepmind(env,
                  downsample=True,
                  episode_life=True,
                  clip_rewards=True,
                  frame_stack=False,
                  scale=False,
                  color=False):
    """Configure environment for DeepMind-style Atari.
    """
    if ("videopinball" in str(env.spec.id).lower()) or ('tennis' in str(
            env.spec.id).lower()):
        env = WarpFrame(env, width=160, height=210, grayscale=False)
    if episode_life:
        env = EpisodicLifeEnv(env)
    if 'FIRE' in env.unwrapped.get_action_meanings():
        env = FireResetEnv(env)
    if downsample:
        env = WarpFrame(env, grayscale=False)
    if not color:
        env = GrayscaleWrapper(env)
    if scale:
        env = ScaledFloatFrame(env)
    if clip_rewards:
        env = ClipRewardEnv(env)
    if frame_stack:
        env = FrameStack(env, 4)
    return env
def atari_play_env(env):

    env = EpisodicLifeEnv(env)

    if 'FIRE' in env.unwrapped.get_action_meanings():
        env = FireResetEnv(env)

    return env
Exemple #4
0
def _wrap_deepmind_ram(env):
    """Applies various Atari-specific wrappers to make learning easier."""
    env = EpisodicLifeEnv(env)
    env = NoopResetEnv(env, noop_max=30)
    env = MaxAndSkipEnv(env, skip=4)
    if 'FIRE' in env.unwrapped.get_action_meanings():
        env = FireResetEnv(env)
    env = ClipRewardEnv(env)
    return env
def wrap_env(env, episode_life=False):
    if episode_life:
        env = EpisodicLifeEnv(env)
    env = NoopResetEnv(env, 30)
    env = MaxAndSkipEnv(env, 4)
    if env.unwrapped.get_action_meanings()[1] == 'FIRE':
        env = FireResetEnv(env)
    env = WarpFrame(env)  # , width=84, height=84)
    env = FrameStack(env, 4)
    env = ScaledFloatFrame(env)
    return env
Exemple #6
0
 def _thunk():
     env = gym.make(**env_base)
     env = NoopResetEnv(env, noop_max=30)
     env = MaxAndSkipEnv(env, skip=4)
     env = RewardCollector(env)
     env = EpisodicLifeEnv(env)
     env = ClipRewardEnv(env)
     env = WarpFrame(env)
     env = ScaledFloatFrame(env)
     env = TransposeImage(env)
     env = UnrealEnvBaseWrapper(env)
     return env
 def create_env(self, env):
     env = gym.make(env)
     env = NoopResetEnv(env, noop_max=30)
     env = MaxAndSkipEnv(env, skip=4)
     env = RewardCollector(env)
     env = EpisodicLifeEnv(env)
     env = ClipRewardEnv(env)
     env = WarpFrame(env)
     env = FrameStack(env, 4)
     env = ConvertToNumpy(env)
     env = TransposeImage(env)
     env = ScaledFloatFrame(env)
     return env
Exemple #8
0
def wrap_deepmind(env, episode_life=True, clip_rewards=True, frame_stack=False, scale=False):
    """Configure environment for DeepMind-style Atari.
    """
    if episode_life:
        env = EpisodicLifeEnv(env)
    if 'FIRE' in env.unwrapped.get_action_meanings():
        env = FireResetEnv(env)
    env = WarpFrame(env)
    if scale:
        env = ScaledFloatFrame(env)
    if clip_rewards:
        env = ClipRewardEnv(env)
    if frame_stack:
        env = FrameStack(env, 4)
    return env
Exemple #9
0
 def _thunk():
     env = gym.make(env_id)
     env.seed(seed + rank)
     env = NoopResetEnv(env, noop_max=30)
     env = MaxAndSkipEnv(env, skip=2)
     env = WarpFrame(env)
     # Janky Fix to Resize Environments to be 50x50
     env.width = 50
     env.height = 50
     env = ScaledFloatFrame(env)
     if not eval:
         env = ClipRewardEnv(env)
         env = EpisodicLifeEnv(env)
     env = FrameStack(env, 3)
     env = TransposeOb(env)
     return env
Exemple #10
0
def wrap_atari(env, stack_frames=4, training=True, crop_top=True):
    if training:
        env = EpisodicLifeEnv(env)

    env = NoopResetEnv(env)

    if 'FIRE' in env.unwrapped.get_action_meanings():
        if (training):
            env = FireResetEnv(env)
        else:
            env = FireAfterLifeLost(env)

    env = ProcessFrame(env, 18 if crop_top else 0)
    env = ImageToPyTorch(env)
    env = FrameStack(env, stack_frames)
    return env
 def wrap_deepmind_custom(env,
                          episode_life=True,
                          clip_rewards=True,
                          frame_stack=frame_stack,
                          scale=False):
     if episode_life:
         env = EpisodicLifeEnv(env)
     if 'FIRE' in env.unwrapped.get_action_meanings():
         env = FireResetEnv(env)
     env = WarpFrame(env, size=size)
     if augment:
         env = AugmentColor(env)
     if scale:
         env = ScaledFloatFrame(env)
     if clip_rewards:
         env = ClipRewardEnv(env)
     if frame_stack:
         env = FrameStack(env, frame_stack)
     return env
Exemple #12
0
def make_env(env_name='PongNoFrameskip-v4',
             size=84,
             skip=4,
             scale=True,
             is_train=True):
    env = gym.make(env_name)
    env = NoopResetEnv(env, noop_max=30)
    if is_train:
        env = MaxAndSkipEnv(env, skip=skip)
    if env.unwrapped.ale.lives() > 0:
        env = EpisodicLifeEnv(env)
    if 'FIRE' in env.unwrapped.get_action_meanings():
        env = FireResetEnv(env)
    env = WarpFrame(env, width=size, height=size,
                    grayscale=True)  # obs_space is now (84,84,1)
    if scale:
        env = ScaledFloatFrame(env)
    env = ChannelFirstFrameStack(env, 4)
    return env
Exemple #13
0
def deepmind_wrap(atari_env,
                  episode_life=True,
                  clip_rewards=True,
                  frame_stack=False,
                  scale=False):
    """ matching deepmind papers
    """
    if episode_life:
        env = EpisodicLifeEnv(atari_env)
    if 'FIRE' in env.unwrapped.get_action_meanings():
        env = FireResetEnv(env)
    env = WarpFrame(env)
    if scale:
        env = ScaledFloatFrame(env)
    if clip_rewards:
        env = ClipRewardEnv(env)
    if frame_stack:
        env = FrameStack(env, 4)
    return env
Exemple #14
0
    def _thunk():
        episodic_life = True
        env = gym.make(env_id)

        env.seed(seed + rank)
        env.frameskip = 1

        if log_dir is not None:
            env = bench.Monitor(env, os.path.join(log_dir, str(rank)))
        if episodic_life:
            env = EpisodicLifeEnv(env)

        env = NoopResetEnv(env, noop_max=30)
        env = MaxAndSkipEnv(env, skip=1)

        if 'FIRE' in env.unwrapped.get_action_meanings():
            env = FireResetEnv(env)
        if grey_scale:
            env = WarpMiniPacmanFrameGreyScale(env)
        else:
            env = WarpMiniPacmanFrameRGB(env)
        return env
Exemple #15
0
    def __init__(self,
                 env,
                 stack=4,
                 episodic_life=False,
                 episodic_score=False,
                 clip_reward=False):
        """

        - grayscale
        - resize
        - crop
        - stack

        See Also
        --------
        baselines.common.atari_wrappers.LazyFrames
        """

        # env = EpisodicLifeEnv(env) # no effect on Pong

        if episodic_life:
            env = EpisodicLifeEnv(env)

        gym.Wrapper.__init__(self, env)
        self.stack = stack
        self.frames = deque([], maxlen=stack)

        shp = env.observation_space.shape
        # self.observation_space = gym.spaces.Box(low=0, high=1.0, shape=(
        #     shp[2] * stack, shp[0], shp[1]), dtype=np.float)
        self.observation_space = gym.spaces.Box(low=0,
                                                high=255,
                                                shape=(shp[2] * stack, shp[0],
                                                       shp[1]),
                                                dtype=np.uint8)

        self.episodic_score = episodic_score
        self.clip_reward = clip_reward
def custom_wrapper(env,
                   deterministic_reset=True,
                   episode_life=True,
                   warp=True,
                   grayscale=False,
                   frame_stack=True,
                   frames=4,
                   ATARI_labels=True):
    if deterministic_reset:
        env = DeterminsticNoopResetEnv(env, 66)
    if episode_life:
        env = EpisodicLifeEnv(env)
    if warp:
        env = WarpFrame(env, height=100, width=100, grayscale=grayscale)

    if not frame_stack:
        assert frames == 1, "Framestack is false and frames are larger than 1."
    if frame_stack:
        assert frames > 1, 'Frames should not be 1 if framestack is on'
        env = FrameStack(env, frames)
    if ATARI_labels:
        env = AtariARIWrapper(env)
    return env