當前位置: 首頁>>代碼示例>>Python>>正文


Python wrappers.Unvectorize方法代碼示例

本文整理匯總了Python中universe.wrappers.Unvectorize方法的典型用法代碼示例。如果您正苦於以下問題:Python wrappers.Unvectorize方法的具體用法?Python wrappers.Unvectorize怎麽用?Python wrappers.Unvectorize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在universe.wrappers的用法示例。


在下文中一共展示了wrappers.Unvectorize方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create_flash_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_flash_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)

    reg = universe.runtime_spec('flashgames').server_registry
    height = reg[env_id]["height"]
    width = reg[env_id]["width"]
    env = CropScreen(env, height, width, 84, 18)
    env = FlashRescale(env)

    keys = ['left', 'right', 'up', 'down', 'x']
    env = DiscreteToFixedKeysVNCActions(env, keys)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    env.configure(fps=5.0, remotes=remotes, start_timeout=15 * 60, client_id=client_id,
                  vnc_driver='go', vnc_kwargs={
                    'encoding': 'tight', 'compress_level': 0,
                    'fine_quality_level': 50, 'subsample_level': 3})
    return env 
開發者ID:YuhangSong,項目名稱:DHP,代碼行數:24,代碼來源:envs.py

示例2: test_boundary_simple

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_boundary_simple():
    env = gym.make('flashgames.DuskDrive-v0')
    env = wrappers.Unvectorize(env)
    env.configure(vnc_driver=FakeVNCSession, rewarder_driver=FakeRewarder, remotes='vnc://example.com:5900+15900')
    env.reset()

    rewarder_client = get_rewarder_client(env)
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '1'})
    rewarder_client._manual_recv('v0.reply.env.reset', {}, {'episode_id': '1'})

    rewarder_client._manual_recv('v0.env.reward', {'reward': 1, 'done': False, 'info': {}}, {'episode_id': '1'})
    rewarder_client._manual_recv('v0.env.reward', {'reward': 2, 'done': True, 'info': {}}, {'episode_id': '1'})
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '2'})

    # We have reward of 3 for episode 1, and episode 2 should now be resetting
    observation, reward, done, info = env.step([])
    assert info['mask.masked.observation']
    assert info['mask.masked.action']
    assert (reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (3, True, 'resetting', '2') 
開發者ID:openai,項目名稱:universe,代碼行數:21,代碼來源:test_semantics.py

示例3: test_smoke

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_smoke(env_id):
    """Check that environments start up without errors and that we can extract rewards and observations"""
    gym.undo_logger_setup()
    logging.getLogger().setLevel(logging.INFO)

    env = gym.make(env_id)
    if env.metadata.get('configure.required', False):
        if os.environ.get('FORCE_LATEST_UNIVERSE_DOCKER_RUNTIMES'):  # Used to test universe-envs in CI
            configure_with_latest_docker_runtime_tag(env)
        else:
            env.configure(remotes=1)

    env = wrappers.Unvectorize(env)

    env.reset()
    _rollout(env, timestep_limit=60*30) # Check a rollout 
開發者ID:openai,項目名稱:universe,代碼行數:18,代碼來源:test_envs.py

示例4: create_vncatari_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_vncatari_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)
    env = GymCoreAction(env)
    env = AtariRescale42x42(env)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)

    logger.info('Connecting to remotes: %s', remotes)
    fps = env.metadata['video.frames_per_second']
    env.configure(remotes=remotes, start_timeout=15 * 60, fps=fps, client_id=client_id)
    return env 
開發者ID:YuhangSong,項目名稱:DHP,代碼行數:17,代碼來源:envs.py

示例5: create_atari_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id):
    env = gym.make(env_id)
    env = Vectorize(env)
    env = AtariRescale42x42(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    return env 
開發者ID:YuhangSong,項目名稱:DHP,代碼行數:9,代碼來源:envs.py

示例6: create_atari_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id):
    env = gym.make(env_id)
    if len(env.observation_space.shape) > 1:
        print('Preprocessing env')
        env = Vectorize(env)
        env = AtariRescale42x42(env)
        env = NormalizedEnv(env)
        env = Unvectorize(env)
    else:
        print('No preprocessing because env is too small')
    return env 
開發者ID:atgambardella,項目名稱:pytorch-es,代碼行數:13,代碼來源:envs.py

示例7: test_vnc_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_vnc_env():
    env = gym.make('flashgames.DuskDrive-v0')
    env = wrappers.Unvectorize(env)
    env.configure(vnc_driver=FakeVNCSession, rewarder_driver=FakeRewarder, remotes='vnc://example.com:5900+15900')
    env.reset()

    rewarder_client = get_rewarder_client(env)

    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '1'})

    observation, reward, done, info = env.step([spaces.KeyEvent.by_name('a', down=True)])
    assert (observation, reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (None, 0, False, None, None)

    rewarder_client._manual_recv('v0.reply.env.reset', {}, {'episode_id': '1'})

    observation, reward, done, info = env.step([spaces.KeyEvent.by_name('a', down=True)])
    assert (observation, reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (None, 0, False, 'resetting', '1')

    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '1'})

    rewarder_client._manual_recv('v0.env.reward', {'reward': 10, 'done': False, 'info': {}}, {'episode_id': '1'})
    rewarder_client._manual_recv('v0.env.reward', {'reward': 15, 'done': False, 'info': {}}, {'episode_id': '1'})
    rewarder_client._manual_recv('v0.env.reward', {'reward': -3, 'done': False, 'info': {}}, {'episode_id': '1'})

    observation, reward, done, info = env.step([spaces.KeyEvent.by_name('a', down=True)])
    assert sorted(observation.keys()) == ['text', 'vision']
    assert observation['text'] == []
    assert observation['vision'].shape == (768, 1024, 3)
    assert (reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (22, False, 'running', '1')
    assert info['stats.reward.count'] == 3 
開發者ID:openai,項目名稱:universe,代碼行數:32,代碼來源:test_semantics.py

示例8: test_boundary_multiple

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_boundary_multiple():
    env = gym.make('flashgames.DuskDrive-v0')
    env = wrappers.Unvectorize(env)
    env.configure(vnc_driver=FakeVNCSession, rewarder_driver=FakeRewarder, remotes='vnc://example.com:5900+15900')
    env.reset()

    rewarder_client = get_rewarder_client(env)
    # episode 2
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '2'})
    rewarder_client._manual_recv('v0.reply.env.reset', {}, {'episode_id': '2'})
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '2'})
    rewarder_client._manual_recv('v0.env.reward', {'reward': 2, 'done': True, 'info': {}}, {'episode_id': '2'})

    # episode 3
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '3'})
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '3'})
    rewarder_client._manual_recv('v0.env.reward', {'reward': 3, 'done': True, 'info': {}}, {'episode_id': '3'})

    # episode 4
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '4'})
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '4'})
    rewarder_client._manual_recv('v0.env.reward', {'reward': 4, 'done': False, 'info': {}}, {'episode_id': '4'})

    observation, reward, done, info = env.step([])
    assert not info.get('mask.masked.observation')
    assert not info.get('mask.masked.action')
    assert (reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (2, True, 'running', '4')
    assert (info['env_status.complete.env_state'], info['env_status.complete.episode_id']) == ('running', '2')

    observation, reward, done, info = env.step([])
    assert (reward, done, info['env_status.env_state'], info['env_status.episode_id']) == (4, False, 'running', '4') 
開發者ID:openai,項目名稱:universe,代碼行數:33,代碼來源:test_semantics.py

示例9: test_peek

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def test_peek():
    env = gym.make('flashgames.DuskDrive-v0')
    env = wrappers.Unvectorize(env)
    env.configure(vnc_driver=FakeVNCSession, rewarder_driver=FakeRewarder, remotes='vnc://example.com:5900+15900')
    env.reset()

    rewarder_client = get_rewarder_client(env)
    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '1'})
    rewarder_client._manual_recv('v0.reply.env.reset', {}, {'episode_id': '1'})

    observation, reward, done, info = env.step([spaces.PeekReward])

    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'resetting', 'fps': 60}, {'episode_id': '2'})
    observation, reward, done, info = env.step([spaces.PeekReward])
    assert info['mask.masked.observation']
    assert info['mask.masked.action']
    assert info['env_status.episode_id'] == '1'
    assert info['env_status.env_state'] == 'resetting'
    assert info['env_status.peek.episode_id'] == '2'
    assert info['env_status.peek.env_state'] == 'resetting'

    rewarder_client._manual_recv('v0.env.describe', {'env_id': 'flashgames.DuskDrive-v0', 'env_state': 'running', 'fps': 60}, {'episode_id': '2'})
    observation, reward, done, info = env.step([spaces.PeekReward])
    assert not info.get('mask.masked.observation')
    assert not info.get('mask.masked.action')
    assert info['env_status.episode_id'] == '1'
    assert info['env_status.env_state'] == 'resetting'
    assert info['env_status.peek.episode_id'] == '2'
    assert info['env_status.peek.env_state'] == 'running' 
開發者ID:openai,項目名稱:universe,代碼行數:31,代碼來源:test_semantics.py

示例10: make_environment

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def make_environment(name, **args):
    """Make an environment of a given name, possibly using extra arguments."""
    env = environment_registry.get(name, Environment)
    if name in environment_registry:
        env = env(**args)
    else:
        env = env(name, **args)
    if "atari.atari_env" in env.unwrapped.__module__:
        to_dict = env.to_dict
        env = Vectorize(env)
        env = AtariRescale42x42(env)
        env = Unvectorize(env)
        env.to_dict = to_dict
    return env 
開發者ID:arnomoonens,項目名稱:DeepRL,代碼行數:16,代碼來源:registration.py

示例11: create_flash_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_flash_env(env_id, client_id, remotes, **_):
    env = gym.make(env_id)
    env = Vision(env)
    env = Logger(env)
    env = BlockingReset(env)

    reg = universe.runtime_spec('flashgames').server_registry
    height = reg[env_id]["height"]
    width = reg[env_id]["width"]
    env = CropScreen(env, height, width, 84, 18)
    env = FlashRescale(env)

    keys = ['left', 'right', 'up', 'down', 'x']
    if env_id == 'flashgames.NeonRace-v0':
        # Better key space for this game.
        keys = ['left', 'right', 'up', 'left up', 'right up', 'down', 'up x']
    logger.info('create_flash_env(%s): keys=%s', env_id, keys)

    env = DiscreteToFixedKeysVNCActions(env, keys)
    env = EpisodeID(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    env.configure(fps=5.0, remotes=remotes, start_timeout=15 * 60, client_id=client_id,
                  vnc_driver='go', vnc_kwargs={
                    'encoding': 'tight', 'compress_level': 0,
                    'fine_quality_level': 50, 'subsample_level': 3})
    return env 
開發者ID:Nat-D,項目名稱:FeatureControlHRL,代碼行數:29,代碼來源:envs.py

示例12: create_atari_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id):
    env = gym.make(env_id)
    if len(env.observation_space.shape) > 1:
        env = Vectorize(env)
        env = Unvectorize(env)
    return env

# process each frame 
開發者ID:andrewliao11,項目名稱:pytorch-a3c-mujoco,代碼行數:10,代碼來源:envs.py

示例13: create_mario

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_mario(env_id, client_id, envWrap=True, record=False, outdir=None,
                    noLifeReward=False, acRepeat=0, **_):
    import ppaquette_gym_super_mario
    from ppaquette_gym_super_mario import wrappers
    if '-v' in env_id.lower():
        env_id = 'ppaquette/' + env_id
    else:
        env_id = 'ppaquette/SuperMarioBros-1-1-v0'  # shape: (224,256,3)=(h,w,c)

    # Mario workaround: Simultaneously launching multiple vizdoom processes makes program stuck,
    # so use the global lock in multi-threading/multi-processing
    # see: https://github.com/ppaquette/gym-super-mario/tree/master/ppaquette_gym_super_mario
    client_id = int(client_id)
    time.sleep(client_id * 50)
    env = gym.make(env_id)
    modewrapper = wrappers.SetPlayingMode('algo')
    acwrapper = wrappers.ToDiscrete()
    env = modewrapper(acwrapper(env))
    env = env_wrapper.MarioEnv(env)

    if record and outdir is not None:
        env = gym.wrappers.Monitor(env, outdir, force=True)

    if envWrap:
        frame_skip = acRepeat if acRepeat>0 else 6
        fshape = (42, 42)
        env.seed(None)
        if noLifeReward:
            env = env_wrapper.NoNegativeRewardEnv(env)
        env = env_wrapper.BufferedObsEnv(env, skip=frame_skip, shape=fshape, maxFrames=False)
        if frame_skip > 1:
            env = env_wrapper.SkipEnv(env, skip=frame_skip)
    elif noLifeReward:
        env = env_wrapper.NoNegativeRewardEnv(env)

    env = Vectorize(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    # env.close() # TODO: think about where to put env.close !
    return env 
開發者ID:pathak22,項目名稱:noreward-rl,代碼行數:42,代碼來源:envs.py

示例14: create_atari_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id, record=False, outdir=None, **_):
    env = gym.make(env_id)
    if record and outdir is not None:
        env = gym.wrappers.Monitor(env, outdir, force=True)
    env = Vectorize(env)
    env = AtariRescale42x42(env)
    env = DiagnosticsInfo(env)
    env = Unvectorize(env)
    return env 
開發者ID:pathak22,項目名稱:noreward-rl,代碼行數:11,代碼來源:envs.py

示例15: create_atari_env

# 需要導入模塊: from universe import wrappers [as 別名]
# 或者: from universe.wrappers import Unvectorize [as 別名]
def create_atari_env(env_id):
  env = gym.make(env_id)
  env = Vectorize(env)
  env = AtariRescale42x42(env)
  env = DiagnosticsInfo(env)
  env = Unvectorize(env)
  env.runner = RunnerThread(env, 20)
  return env 
開發者ID:carpedm20,項目名稱:a3c-tensorflow,代碼行數:10,代碼來源:atari.py


注:本文中的universe.wrappers.Unvectorize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。