当前位置: 首页>>代码示例>>Python>>正文


Python gym.Wrapper方法代码示例

本文整理汇总了Python中gym.Wrapper方法的典型用法代码示例。如果您正苦于以下问题:Python gym.Wrapper方法的具体用法?Python gym.Wrapper怎么用?Python gym.Wrapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gym的用法示例。


在下文中一共展示了gym.Wrapper方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def __init__(self, env):
        gym.Wrapper.__init__(self, env)
        self.action_space = env.action_space
        self.timeout_space = gym.spaces.Box(low=np.array([0.0]), high=np.array([1.0]), dtype=np.float32)
        self.original_os = env.observation_space
        if isinstance(self.original_os, gym.spaces.Dict):
            import copy
            ordered_dict = copy.deepcopy(self.original_os.spaces)
            ordered_dict['value_estimation_timeout'] = self.timeout_space
            self.observation_space = gym.spaces.Dict(ordered_dict)
            self.dict_mode = True
        else:
            self.observation_space = gym.spaces.Dict({
                'original': self.original_os,
                'value_estimation_timeout': self.timeout_space
                })
            self.dict_mode = False
        self.ac_count = None
        while 1:
            if not hasattr(env, "_max_episode_steps"):  # Looking for TimeLimit wrapper that has this field
                env = env.env
                continue
            break
        self.timeout = env._max_episode_steps 
开发者ID:MaxSobolMark,项目名称:HardRLWithYoutube,代码行数:26,代码来源:retro_wrappers.py

示例2: get_wrapper_by_name

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def get_wrapper_by_name(env, classname):
    """Given an a gym environment possibly wrapped multiple times, returns a wrapper
    of class named classname or raises ValueError if no such wrapper was applied

    Parameters
    ----------
    env: gym.Env of gym.Wrapper
        gym environment
    classname: str
        name of the wrapper

    Returns
    -------
    wrapper: gym.Wrapper
        wrapper named classname
    """
    currentenv = env
    while True:
        if classname == currentenv.class_name():
            return currentenv
        elif isinstance(currentenv, gym.Wrapper):
            currentenv = currentenv.env
        else:
            raise ValueError("Couldn't find wrapper named %s" % classname) 
开发者ID:MaxSobolMark,项目名称:HardRLWithYoutube,代码行数:26,代码来源:misc_util.py

示例3: __init__

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def __init__(self, env, k, channel_order='hwc'):
        """Stack k last frames.

        Returns lazy array, which is much more memory efficient.

        See Also
        --------
        baselines.common.atari_wrappers.LazyFrames
        """
        gym.Wrapper.__init__(self, env)
        self.k = k
        self.frames = deque([], maxlen=k)
        self.stack_axis = {'hwc': 2, 'chw': 0}[channel_order]
        orig_obs_space = env.observation_space
        low = np.repeat(orig_obs_space.low, k, axis=self.stack_axis)
        high = np.repeat(orig_obs_space.high, k, axis=self.stack_axis)
        self.observation_space = spaces.Box(
            low=low, high=high, dtype=orig_obs_space.dtype) 
开发者ID:chainer,项目名称:chainerrl,代码行数:20,代码来源:atari_wrappers.py

示例4: remove_time_limit_wrapper

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def remove_time_limit_wrapper(env):
  """Removes top level TimeLimit Wrapper.

  Removes TimeLimit Wrapper from top level if exists, throws error if any other
  TimeLimit Wrapper is present in stack.

  Args:
    env: environment

  Returns:
    the env with removed time limit wrapper.
  """
  if isinstance(env, gym.wrappers.TimeLimit):
    env = env.env
  env_ = env
  while isinstance(env_, gym.Wrapper):
    if isinstance(env_, gym.wrappers.TimeLimit):
      raise ValueError("Can remove only top-level TimeLimit gym.Wrapper.")
    env_ = env_.env
  return env 
开发者ID:tensorflow,项目名称:tensor2tensor,代码行数:22,代码来源:gym_utils.py

示例5: is_unwrappable_to

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def is_unwrappable_to(env: gym.Env, to_wrapper: Type[gym.Wrapper]) -> bool:
    """Check if env can be unwrapped to to_wrapper.

    Parameters
    ----------
    env: gym.Env
        A gym environment (potentially wrapped).
    to_wrapper: Type[gym.Wrapper]
        A wrapper class extending gym.Wrapper.

    Returns
    -------
    bool
        True if env could be unwrapped to desired wrapper, False otherwise.
    """
    if isinstance(env, to_wrapper):
        return True
    while hasattr(env, 'env'):
        env = env.env
        if isinstance(env, to_wrapper):
            return True
    return False 
开发者ID:JohannesHeidecke,项目名称:irl-benchmark,代码行数:24,代码来源:wrapper.py

示例6: get_wrapper_by_name

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def get_wrapper_by_name(env, classname):
    currentenv = env
    while True:
        if classname in currentenv.__class__.__name__:
            return currentenv
        elif isinstance(env, gym.Wrapper):
            currentenv = currentenv.env
        else:
            raise ValueError("Couldn't find wrapper named %s"%classname) 
开发者ID:xuwd11,项目名称:cs294-112_hws,代码行数:11,代码来源:dqn_utils.py

示例7: __init__

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def __init__(self, env, warm_up_examples=0, warmup_action=0):
    gym.Wrapper.__init__(self, env)
    self.warm_up_examples = warm_up_examples
    self.warm_up_action = warmup_action
    self.observation_space = gym.spaces.Box(
        low=0, high=255, shape=(210, 160, 3), dtype=np.uint8) 
开发者ID:akzaidi,项目名称:fine-lm,代码行数:8,代码来源:gym_utils.py

示例8: __init__

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def __init__(self, env, noop_max=30):
        """Sample initial states by taking random number of no-ops on reset.
        No-op is assumed to be action 0.
        """
        gym.Wrapper.__init__(self, env)
        self.noop_max = noop_max
        self.override_num_noops = None
        self.noop_action = 0
        assert env.unwrapped.get_action_meanings()[0] == 'NOOP' 
开发者ID:Hwhitetooth,项目名称:lirpg,代码行数:11,代码来源:atari_wrappers.py

示例9: __init__

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def __init__(self, env):
        """Take action on reset for environments that are fixed until firing."""
        gym.Wrapper.__init__(self, env)
        assert env.unwrapped.get_action_meanings()[1] == 'FIRE'
        assert len(env.unwrapped.get_action_meanings()) >= 3 
开发者ID:MaxSobolMark,项目名称:HardRLWithYoutube,代码行数:7,代码来源:atari_wrappers.py

示例10: __init__

# 需要导入模块: import gym [as 别名]
# 或者: from gym import Wrapper [as 别名]
def __init__(self, env, noop_max=30):
    """Sample initial states by taking random number of no-ops on reset.
    No-op is assumed to be action 0.
    """
    gym.Wrapper.__init__(self, env)
    self.noop_max = noop_max
    self.override_num_noops = None
    if isinstance(env.action_space, gym.spaces.MultiBinary):
      self.noop_action = np.zeros(self.env.action_space.n, dtype=np.int64)
    else:
      # used for atari environments
      self.noop_action = 0
      assert env.unwrapped.get_action_meanings()[0] == 'NOOP' 
开发者ID:mjacar,项目名称:pytorch-trpo,代码行数:15,代码来源:atari_wrapper.py


注:本文中的gym.Wrapper方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。