Пример #1
0
    def __init__(self, width, height, fps, level):
        lab = deepmind_lab.Lab(level, [])

        self.env = deepmind_lab.Lab(level, ["RGB_INTERLACED"],
                                    config={
                                        "fps": str(fps),
                                        "width": str(width),
                                        "height": str(height)
                                    })

        self.env.reset()

        import pprint
        observation_spec = lab.observation_spec()
        print("Observation spec:")
        pprint.pprint(observation_spec)
        self.action_spec = self.env.action_spec()
        print("Action spec:")
        pprint.pprint(self.action_spec)

        self.indices = {a["name"]: i for i, a in enumerate(self.action_spec)}
        self.mins = np.array([a["min"] for a in self.action_spec])
        self.maxs = np.array([a["max"] for a in self.action_spec])
        self.num_actions = len(self.action_spec)
        print(self.num_actions)

        self.action = None
Пример #2
0
 def test_maze_layout_spread(self):
   layouts = set()
   for i in six.moves.range(MAZE_LAYOUT_TRIALS):
     print('phase 1: trial {} out of {}'.format(i+1, MAZE_LAYOUT_TRIALS))
     env = deepmind_lab.Lab(
         'tests/maze_generation_test', [MAZE_LAYOUT_OBSERVATION], config={})
     env.reset(seed=i+1)
     layouts.add(env.observations()[MAZE_LAYOUT_OBSERVATION])
   num_layouts = len(layouts)
   self.assertTrue(np.isclose(num_layouts, MAZE_LAYOUT_TRIALS))
   for i in six.moves.range(MAZE_LAYOUT_TRIALS):
     print('phase 2: trial {} out of {}'.format(i+1, MAZE_LAYOUT_TRIALS))
     env = deepmind_lab.Lab(
         'tests/maze_generation_test', [MAZE_LAYOUT_OBSERVATION],
         config={
             'mixerSeed': '0',
         })
     env.reset(seed=i+1)
     layouts.add(env.observations()[MAZE_LAYOUT_OBSERVATION])
   self.assertEqual(len(layouts), num_layouts)
   for i in six.moves.range(MAZE_LAYOUT_TRIALS):
     print('phase 3: trial {} out of {}'.format(i+1, MAZE_LAYOUT_TRIALS))
     env = deepmind_lab.Lab(
         'tests/maze_generation_test', [MAZE_LAYOUT_OBSERVATION],
         config={
             'mixerSeed': '1',
         })
     env.reset(seed=i+1)
     layouts.add(env.observations()[MAZE_LAYOUT_OBSERVATION])
   self.assertTrue(np.isclose(len(layouts) - num_layouts, MAZE_LAYOUT_TRIALS))
Пример #3
0
    def __init__(self, width, height, fps, level):
        lab = deepmind_lab.Lab(level, [])
        # 定义了 Deepmind 的对象
        # 加载的游戏脚本为 level
        # observations 中的元素分别给环境中的observation 命名
        self.env = deepmind_lab.Lab(level, ["RGB_INTERLEAVED"],
                                    config={
                                        "fps": str(fps),
                                        "width": str(width),
                                        "height": str(height)
                                    })

        self.env.reset()  # 在每个 epsido 结束后 调用会设置 is_running == False

        import pprint
        observation_spec = lab.observation_spec()  # 所有的 observations 的名称、类型、维度
        print("Observation spec:")
        pprint.pprint(observation_spec)
        self.action_spec = self.env.action_spec()  # 同理
        print("Action spec:")
        pprint.pprint(self.action_spec)

        self.indices = {a["name"]: i
                        for i, a in enumerate(self.action_spec)
                        }  # 变成所有 actions 的行为的索引
        self.mins = np.array([a["min"]
                              for a in self.action_spec])  # action 的 最小值序列
        self.maxs = np.array([a["max"]
                              for a in self.action_spec])  # action 的最大值序列
        self.num_actions = len(self.action_spec)  # 动作的数量
        print(self.num_actions)  # 7个动作

        self.action = None
Пример #4
0
 def testInitArgs(self):
     with self.assertRaisesRegexp(TypeError, 'must be dict, not list'):
         deepmind_lab.Lab('tests/demo_map', [], ['wrongconfig'])
     with self.assertRaisesRegexp(TypeError, 'str'):
         deepmind_lab.Lab('tests/demo_map', [], {'wrongtype': 3})
     with self.assertRaisesRegexp(TypeError, 'must be list, not None'):
         deepmind_lab.Lab('tests/demo_map', None, {})
     with self.assertRaisesRegexp(ValueError, 'Unknown observation'):
         deepmind_lab.Lab('tests/demo_map', ['nonexisting_obs'], {})
Пример #5
0
 def testInitArgs(self):
     with six.assertRaisesRegex(self, TypeError, 'must be dict, not list'):
         deepmind_lab.Lab('tests/empty_room_test', [], ['wrongconfig'])
     with six.assertRaisesRegex(self, TypeError, 'str|bad argument type'):
         deepmind_lab.Lab('tests/empty_room_test', [], {'wrongtype': 3})
     with six.assertRaisesRegex(self, TypeError, 'must be list, not None'):
         deepmind_lab.Lab('tests/empty_room_test', None, {})
     with six.assertRaisesRegex(self, ValueError, 'Unknown observation'):
         deepmind_lab.Lab('tests/empty_room_test', ['nonexisting_obs'], {})
Пример #6
0
    def test_maze_layout(self):
        env = deepmind_lab.Lab('tests/debug_observation_test',
                               [MAZE_LAYOUT_OBSERVATION],
                               config={})

        env.reset()
        self.assertEqual(env.observations()[MAZE_LAYOUT_OBSERVATION], TEST_MAP)
Пример #7
0
def get_game_environment(level="nav_maze_random_goal_01",
                         width=160,
                         height=160):
    """
    get deepmind_lab env (see:https://github.com/dongniu0927/lab/blob/master/docs/users/observations.md)
    :param level:
    :return:
    """
    # RGB_INTERLEAVED: Player view interleaved
    # RGBD_INTERLEAVED: Player view with depth
    # DEBUG.CAMERA.TOP_DOWN: top view
    # DEBUG.POS.TRANS: Player's world position
    # DEBUG.POS.ROT: orientation in degrees
    # DEBUG.FLAGS.RED_HOME: Red flag's home location and state
    obses = [
        "RGB_INTERLEAVED", "RGBD_INTERLEAVED", "DEBUG.POS.ROT",
        "DEBUG.CAMERA.TOP_DOWN", "DEBUG.POS.TRANS", "DEBUG.PLAYERS.TEAM",
        "DEBUG.PLAYERS.EYE.ROT", "DEBUG.FLAGS.RED_HOME",
        "DEBUG.PLAYERS.EYE.POS", "DEBUG.FLAGS.RED", "DEBUG.FLAGS.BLUE",
        "DEBUG.FLAGS.BLUE_HOME", "DEBUG.FLAGS.RED_HOME"
    ]
    lab = deepmind_lab.Lab(
        level, obses, {
            'fps': '30',
            'width': width,
            'height': height,
            "maxAltCameraWidth": width,
            "maxAltCameraHeight": height
        })
    lab.reset(seed=1)
    return lab
Пример #8
0
 def __init__(self,
              level,
              configs,
              observation_keys,
              height=84,
              width=84,
              frame_skip=4,
              fps=60,
              ):
     """
     Create the deepmind lab environment with level
     :param level: level
     :param configs: config
     :param observation_keys: available observations
     :param height: height for RGB observation
     :param width: width for RGB observation
     :param frame_skip: frame skip
     :param fps:
     """
     super(DeepmindLabEnvironment, self).__init__()
     # 相关的属性
     self.level = level
     self.viewer = None
     self.frame_skip = frame_skip
     config = {
         'fps': str(fps),
         'width': str(width),
         'height': str(height),
     }
     config.update(configs)
     env = deepmind_lab.Lab(level,
                            observation_keys,
                            config=config)
     self.lab = env
Пример #9
0
    def test_list_properties(self):
        env = deepmind_lab.Lab('tests/properties_test', [], config={})
        props = props_to_dictionary(env)
        expected_params = {
            'arg1': 'true',
            'arg2': '19',
            'arg3': 'hello',
            'arrArgs': {
                '1': 'arr1',
                '2': 'arr2',
                '3': 'arr3'
            },
            'subArgs': {
                'sub1': 'val1',
                'sub2': 'val2',
                'sub3': 'val3'
            }
        }
        self.assertEqual(props['params'], expected_params)
        env.write_property('params.arrArgs.1', 'newarr1')
        props = props_to_dictionary(env)
        self.assertEqual(props['params']['arrArgs']['1'], 'newarr1')
        env.write_property('params.arg1', 'false')

        self.assertIsNotNone(props['func'])
        self.assertIsNotNone(props['func']['times10'])

        for i in six.moves.range(10):
            self.assertEqual(env.read_property('func.times10.' + str(i)),
                             str(i * 10))
Пример #10
0
    def test_pickup_apple_run(self):
        env = deepmind_lab.Lab('tests/extra_entities_test',
                               ['DEBUG.POS.TRANS'],
                               config={
                                   'fps': '60',
                                   'width': '80',
                                   'height': '80'
                               })

        action_spec = env.action_spec()
        action_index = {
            action['name']: i
            for i, action in enumerate(action_spec)
        }

        action = np.zeros([len(action_spec)], dtype=np.intc)

        action[action_index['MOVE_BACK_FORWARD']] = 1

        reward = env.reset()
        expected_reward = 1
        for _ in six.moves.range(60):
            reward = env.step(action, 1)
            if reward > 0:
                self.assertEqual(reward, expected_reward)
                if expected_reward == 5:
                    break
                else:
                    expected_reward += 1
        else:
            print(env.observations()['DEBUG.POS.TRANS'])
            self.fail('Failed to pickup all apples!')
Пример #11
0
  def __init__(self, game, num_action_repeats, seed, is_test, config,
               action_set=DEFAULT_ACTION_SET, level_cache_dir=None):
    if is_test:
      config['allowHoldOutLevels'] = 'true'
      # Mixer seed for evalution, see
      # https://github.com/deepmind/lab/blob/master/docs/users/python_api.md
      config['mixerSeed'] = 0x600D5EED

    if game in games.ALL_GAMES:
      game = 'contributed/dmlab30/' + game

    config['datasetPath'] = FLAGS.dataset_path

    self._num_action_repeats = num_action_repeats
    self._random_state = np.random.RandomState(seed=seed)
    if FLAGS.homepath:
      deepmind_lab.set_runfiles_path(FLAGS.homepath)
    self._env = deepmind_lab.Lab(
        level=game,
        observations=['RGB_INTERLEAVED'],
        level_cache=LevelCache(level_cache_dir) if level_cache_dir else None,
        config={k: str(v) for k, v in config.items()},
    )
    self._action_set = action_set
    self.action_space = gym.spaces.Discrete(len(self._action_set))
    self.observation_space = gym.spaces.Box(
        low=0,
        high=255,
        shape=(config['height'], config['width'], 3),
        dtype=np.uint8)
Пример #12
0
    def set_lab_game_setup(self):
        level = 'nav_maze_static_01'
        level = 'small_maze'
        #level = 'small_maze_multimap'

        env = deepmind_lab.Lab(
            level,
            ['RGB_INTERLACED', 'DEBUG.POS.TRANS', 'DEBUG.CAMERA.TOP_DOWN'],
            config={
                'fps': str(60),
                'width': str(self.width),
                'height': str(self.width)
            })

        self.actions = [
            self._action(-20, 0, 0, 0, 0, 0, 0),  # look_left
            self._action(20, 0, 0, 0, 0, 0, 0),  # look_right
            # _action(  0,  10,  0,  0, 0, 0, 0), # look_up
            # _action(  0, -10,  0,  0, 0, 0, 0), # look_down
            self._action(0, 0, -1, 0, 0, 0, 0),  # strafe_left
            self._action(0, 0, 1, 0, 0, 0, 0),  # strafe_right
            self._action(0, 0, 0, 1, 0, 0, 0),  # forward
            self._action(0, 0, 0, -1, 0, 0, 0),  # backward
            # _action(  0,   0,  0,  0, 1, 0, 0), # fire
            # _action(  0,   0,  0,  0, 0, 1, 0), # jump
            # _action(  0,   0,  0,  0, 0, 0, 1)  # crouch
        ]
        return env
Пример #13
0
def run(length, width, height, fps, level, observation_spec):
    """Spins up an environment and runs the random agent."""
    env = deepmind_lab.Lab(level, [observation_spec],
                           config={
                               'fps': str(fps),
                               'width': str(width),
                               'height': str(height)
                           })

    env.reset()

    agent = DiscretizedRandomAgent()

    reward = 0

    t0 = time.time()

    for _ in xrange(length):
        if not env.is_running():
            print('Environment stopped early')
            env.reset()
            agent.reset()
        obs = env.observations()
        action = agent.step(reward, obs[observation_spec])
        reward = env.step(action, num_steps=1)

    t1 = time.time()
    duration = t1 - t0

    print(
        'resolution: %i x %i, spec: %s, steps: %i, duration: %.1f, fps: %.1f' %
        (width, height, observation_spec, length, duration, length / duration))
Пример #14
0
    def __init__(self,
                 level,
                 config,
                 num_action_repeats,
                 seed,
                 runfiles_path=None,
                 level_cache=None):

        # Define initial attributes
        self._num_action_repeats = num_action_repeats
        self._random_state = np.random.RandomState(seed=seed)
        self._width = config.get('width', None)
        self._height = config.get('height', None)

        # Determine observation space
        if FLAGS.depth:
            self._observation_spec = ['RGBD_INTERLEAVED']
        else:
            self._observation_spec = ['RGB_INTERLEAVED']
        if False:
            self._observation_spec.extend(['DEBUG.POS.TRANS', 'DEBUG.POS.ROT'])
        if False:
            self._observation_spec.extend(['DEBUG.POS.TRANS', 'DEBUG.POS.ROT'])

        # Configure deepmind environment
        if runfiles_path:
            deepmind_lab.set_runfiles_path(runfiles_path)
        config = {k: str(v) for k, v in config.iteritems()}
        self._env = deepmind_lab.Lab(
            level=level,
            observations=self._observation_spec,
            config=config,
            level_cache=level_cache,
        )
Пример #15
0
def run(length, width, height, fps, level, agent):
    """Spins up an environment and runs the random agent."""
    print('Starting run')
    env = deepmind_lab.Lab(
        level,
        ['RGB_INTERLACED'],
        config={
            'fps': str(fps),
            'width': str(width),
            'height': str(height)
        })

    env.reset()

    # Starts the random spring agent. As a simpler alternative, we could also
    if agent == "random_discrete":
        agent = DiscretizedRandomAgent()
    elif agent == "random_spring":
        agent = SpringAgent(env.action_spec())
    else:
        agent = DiscretizedRandomAgent()

    reward = 0

    for _ in xrange(length):
        if not env.is_running():
            print('Environment stopped early')
            env.reset()
            agent.reset()
        obs = env.observations()
        action = agent.step(reward, obs['RGB_INTERLACED'])
        reward = env.step(action, num_steps=1)
    print('Finished after %i steps. Total reward received is %f'
          % (length, agent.rewards))
Пример #16
0
    def __init__(self, level, observation_names, config):
        self._lab = deepmind_lab.Lab(level, observation_names, config)
        self._observation_names = observation_names
        self._needs_reset = True

        lab_action_specs = self._lab.action_spec()
        self._action_spec = {}
        self._action_map = {}
        self._action_count = len(lab_action_specs)
        for i, spec in enumerate(lab_action_specs):
            name = spec["name"]
            self._action_map[name] = i
            self._action_spec[name] = dm_env.specs.BoundedArray(
                dtype=np.dtype("int32"),
                shape=(),
                name=name,
                minimum=spec["min"],
                maximum=spec["max"])

        self._observation_spec = {}
        for spec in self._lab.observation_spec():
            name = spec["name"]
            shape = spec["shape"]
            if name in self._observation_names:
                if 0 in shape:
                    raise NotImplementedError(
                        "Dynamic shapes are not supported by dm_env; requested shape for "
                        "observation {} was {}.".format(name, shape))
                self._observation_spec[name] = dm_env.specs.Array(
                    dtype=spec["dtype"], shape=shape, name=name)
Пример #17
0
 def setUp(self):
   self._env = test_environment_decorator.TestEnvironmentDecorator(
       deepmind_lab.Lab(
           'seekavoid_arena_01',
           ['VEL.ROT', 'VEL.TRANS', 'DEBUG.POS.ROT', 'DEBUG.POS.TRANS']))
   self._controller = game_controller.GameController(self._env)
   self._env.reset()
Пример #18
0
 def testTempFolder(self):
   temp_folder = os.path.join(os.environ['TEST_TMPDIR'], 'test_temp_folder')
   lab = deepmind_lab.Lab(
       'contributed/dmlab30/explore_goal_locations_small', [], {},
       temp_folder=temp_folder)
   lab.reset()
   self.assertGreaterEqual(len(os.listdir(temp_folder)), 1)
Пример #19
0
 def __init__(
     self, level, mode, render_size=(64, 64), action_repeat=4,
     action_set=ACTION_SET_DEFAULT, level_cache=None, seed=None,
     runfiles_path=None):
   assert mode in ('train', 'test')
   import deepmind_lab
   if runfiles_path:
     print('Setting DMLab runfiles path:', runfiles_path)
     deepmind_lab.set_runfiles_path(runfiles_path)
   self._config = {}
   self._config['width'] = render_size[0]
   self._config['height'] = render_size[1]
   self._config['logLevel'] = 'WARN'
   if mode == 'test':
     self._config['allowHoldOutLevels'] = 'true'
     self._config['mixerSeed'] = 0x600D5EED
   self._action_repeat = action_repeat
   self._random = np.random.RandomState(seed)
   self._env = deepmind_lab.Lab(
       level='contributed/dmlab30/'+level,
       observations=['RGB_INTERLEAVED'],
       config={k: str(v) for k, v in self._config.items()},
       level_cache=level_cache)
   self._action_set = action_set
   self._last_image = None
   self._done = True
Пример #20
0
    def __init__(self,
                 scene,
                 colors='RGB_INTERLEAVED',
                 width=84,
                 height=84,
                 **kwargs):
        super(DeepmindLabEnv, self).__init__(**kwargs)

        if not scene in LEVELS:
            raise Exception('Scene %s not supported' % (scene))

        self._colors = colors
        self._lab = deepmind_lab.Lab(scene, [self._colors, 'DEBUG.POS.TRANS', 'DEBUG.POS.ROT',
            'VEL.TRANS', 'VEL.ROT'], \
            dict(fps = str(60), width = str(width), height = str(height)))

        self.action_space = gym.spaces.Discrete(len(ACTION_LIST))
        if colors == 'RGB_INTERLEAVED':
            self.observation_space = gym.spaces.Box(0,
                                                    255, (height, width, 3),
                                                    dtype=np.uint8)
        elif colors == 'RGBD_INTERLEAVED':
            self.observation_space = gym.spaces.Box(0,
                                                    255, (height, width, 4),
                                                    dtype=np.uint8)
        #self.observation_space = gym.spaces.Box(0, 255, (height, width, 3), dtype = np.uint8)

        self._last_observation = None
Пример #21
0
    def __init__(self,
                 level_id,
                 repeat_action=1,
                 state_attribute='RGB_INTERLACED',
                 settings={
                     'width': '320',
                     'height': '240',
                     'fps': '60',
                     'appendCommand': ''
                 }):
        """
        Initialize DeepMind Lab environment.

        Args:
            level_id: string with id/descriptor of the level, e.g. 'seekavoid_arena_01'.
            repeat_action: number of frames the environment is advanced, executing the given action during every frame.
            state_attribute: Attributes which represents the state for this environment, should adhere to the
                specification given in DeepMindLabEnvironment.state_spec(level_id).
            settings: dict specifying additional settings as key-value string pairs. The following options
                are recognized: 'width' (horizontal resolution of the observation frames), 'height'
                (vertical resolution of the observation frames), 'fps' (frames per second) and 'appendCommand'
                (commands for the internal Quake console).

        """
        self.level_id = level_id
        self.level = deepmind_lab.Lab(level=level_id,
                                      observations=[state_attribute],
                                      config=settings)
        self.repeat_action = repeat_action
        self.state_attribute = state_attribute
Пример #22
0
    def __init__(self,
                 level,
                 config,
                 num_action_repeats,
                 seed,
                 runfiles_path=None,
                 level_cache=None):
        self._num_action_repeats = num_action_repeats
        self._random_state = np.random.RandomState(seed=seed)
        if runfiles_path:
            deepmind_lab.set_runfiles_path(runfiles_path)
        config = {k: str(v) for k, v in config.items()}
        self._observation_spec = ['RGB_INTERLEAVED', 'INSTR']

        renderer = config['renderer']
        self.benchmark_mode = config['benchmark_mode']

        if self.benchmark_mode:
            print(
                'BENCHMARK MODE IS ON! USE THIS ONLY FOR TESTING AND THROUGHPUT MEASUREMENT!'
            )

        self._env = deepmind_lab.Lab(
            level=level,
            observations=self._observation_spec,
            config=config,
            level_cache=level_cache,
            renderer=renderer,
        )
def run(length, width, height, fps, level, record, demo, video):
  """Spins up an environment and runs the random agent."""
  config = {
      'fps': str(fps),
      'width': str(width),
      'height': str(height)
  }
  if record:
    config['record'] = record
  if demo:
    config['demo'] = demo
  if video:
    config['video'] = video
  env = deepmind_lab.Lab(level, ['RGB_INTERLACED'], config=config)

  env.reset()

  # Starts the random spring agent. As a simpler alternative, we could also
  # use DiscretizedRandomAgent().
  agent = SpringAgent(env.action_spec())

  reward = 0

  for _ in xrange(length):
    if not env.is_running():
      print('Environment stopped early')
      env.reset()
      agent.reset()
    obs = env.observations()
    action = agent.step(reward, obs['RGB_INTERLACED'])
    reward = env.step(action, num_steps=1)

  print('Finished after %i steps. Total reward received is %f'
        % (length, agent.rewards))
Пример #24
0
    def __init__(self, level, action_repeat, extra_cfg=None):
        self._width = self._height = 84
        self._main_observation = 'DEBUG.CAMERA_INTERLEAVED.PLAYER_VIEW_NO_RETICLE'
        self._action_repeat = action_repeat

        self._random_state = None

        observation_format = [self._main_observation, 'DEBUG.POS.TRANS']
        config = {'width': self._width, 'height': self._height}
        if extra_cfg is not None:
            config.update(extra_cfg)
        config = {k: str(v) for k, v in config.items()}

        renderer = 'hardware'

        self._dmlab = deepmind_lab.Lab(
            level, observation_format, config=config, renderer=renderer, level_cache=level_cache,
        )

        self._action_set = ACTION_SET
        self._action_list = np.array(self._action_set, dtype=np.intc)  # DMLAB requires intc type for actions

        self._last_observation = None

        self._render_scale = 5
        self._render_fps = 30
        self._last_frame = time.time()

        self.action_space = gym.spaces.Discrete(len(self._action_set))
        self.observation_space = gym.spaces.Box(low=0, high=255, shape=(self._height, self._width, 3), dtype=np.uint8)

        self.seed()
Пример #25
0
    def testSpecs(self):
        lab = deepmind_lab.Lab('tests/empty_room_test', [])
        observation_spec = lab.observation_spec()
        observation_spec_names = {o['name'] for o in observation_spec}
        observation_spec_lookup = {o['name']: o for o in observation_spec}
        action_names = {a['name'] for a in lab.action_spec()}
        observation_set = {
            'RGB_INTERLEAVED', 'RGB', 'RGBD_INTERLEAVED', 'RGBD',
            'BGR_INTERLEAVED', 'BGRD_INTERLEAVED'
        }
        self.assertGreaterEqual(observation_spec_names, observation_set)
        for k in observation_set:
            o = observation_spec_lookup[k]
            self.assertIn('shape', o)
            self.assertDictContainsSubset({'dtype': np.uint8}, o)

        self.assertSetEqual(
            action_names, {
                'LOOK_LEFT_RIGHT_PIXELS_PER_FRAME',
                'LOOK_DOWN_UP_PIXELS_PER_FRAME', 'STRAFE_LEFT_RIGHT',
                'MOVE_BACK_FORWARD', 'FIRE', 'JUMP', 'CROUCH'
            })

        for a in lab.action_spec():
            self.assertIs(type(a['min']), int)
            self.assertIs(type(a['max']), int)

        self.assertTrue(lab.close())
Пример #26
0
    def testSpecs(self):
        lab = deepmind_lab.Lab('tests/demo_map', [])
        observation_spec = lab.observation_spec()
        observation_names = {o['name'] for o in observation_spec}
        action_names = {a['name'] for a in lab.action_spec()}

        self.assertSetEqual(
            observation_names,
            {'RGB_INTERLACED', 'RGB', 'RGBD_INTERLACED', 'RGBD'})
        for o in observation_spec:
            self.assertIn('shape', o)
            self.assertDictContainsSubset({'dtype': np.uint8}, o)

        self.assertSetEqual(
            action_names, {
                'LOOK_LEFT_RIGHT_PIXELS_PER_FRAME',
                'LOOK_DOWN_UP_PIXELS_PER_FRAME', 'STRAFE_LEFT_RIGHT',
                'MOVE_BACK_FORWARD', 'FIRE', 'JUMP', 'CROUCH'
            })

        for a in lab.action_spec():
            self.assertIs(type(a['min']), int)
            self.assertIs(type(a['max']), int)

        self.assertTrue(lab.close())
Пример #27
0
def run(level_script, config, num_episodes):
    """Construct and start the environment."""
    env = deepmind_lab.Lab(level_script, ['RGB_INTERLEAVED'], config)
    env.reset()

    observation_spec = env.observation_spec()
    print('Observation spec:')
    pprint.pprint(observation_spec)

    action_spec = env.action_spec()
    print('Action spec:')
    pprint.pprint(action_spec)

    obs = env.observations()  # dict of Numpy arrays
    rgb_i = obs['RGB_INTERLEAVED']
    print('Observation shape:', rgb_i.shape)
    sys.stdout.flush()

    # Create an action to move forwards.
    action = np.zeros([7], dtype=np.intc)
    action[3] = 1

    score = 0
    for _ in six.moves.range(num_episodes):
        while env.is_running():
            # Advance the environment 4 frames while executing the action.
            reward = env.step(action, num_steps=4)

            if reward != 0:
                score += reward
                print('Score =', score)
                sys.stdout.flush()
Пример #28
0
    def __init__(self,
                 fps,
                 level,
                 width,
                 height,
                 frame_skip,
                 display=False,
                 shrink=True,
                 no_op_max=7):
        self._frame_skip = frame_skip
        self._no_op_max = no_op_max
        self._width = width
        self._height = height
        self._display = display
        self._shrink = shrink
        if display:
            width = 640
            height = 480

        self.env = deepmind_lab.Lab(level, ['RGB_INTERLACED'],
                                    config={
                                        'fps': str(fps),
                                        'width': str(width),
                                        'height': str(height)
                                    })

        self.s_t = None
        self.reset()
Пример #29
0
def worker(conn):
  level = ENV_NAME
  env = deepmind_lab.Lab(
    level,
    ['RGB_INTERLACED'],
    config={
      'fps': str(60),
      'width': str(84),
      'height': str(84)
    })
  conn.send(0)
  
  while True:
    command, arg = conn.recv()

    if command == COMMAND_RESET:
      env.reset()
      obs = env.observations()['RGB_INTERLACED']
      conn.send(obs)
    elif command == COMMAND_ACTION:
      reward = env.step(arg, num_steps=4)
      terminal = not env.is_running()
      if not terminal:
        obs = env.observations()['RGB_INTERLACED']
      else:
        obs = 0
      conn.send([obs, reward, terminal])
    elif command == COMMAND_TERMINATE:
      break
    else:
      print("bad command: {}".format(command))
  env.close()      
  conn.send(0)
  conn.close()
Пример #30
0
    def __init__(self,
                 scene,
                 action_repeat=4,
                 observation='RGB_INTERLEAVED',
                 config={},
                 renderer='hardware'):
        """Create an deepmind_lab env

        Args:
            scene (str): script for the deepmind_lab env. See available script:
                `<https://github.com/deepmind/lab/tree/master/game_scripts/levels>`_
            action_repeat (int): the interval at which the agent experiences the game
            observation (str):  observation format. See doc about the available observations:
                `<https://github.com/deepmind/lab/blob/master/docs/users/python_api.md>`_
            config (dict): config for env
            renderer (str): 'software' or 'hardware'. If set to 'hardware', EGL or GLX is
                used for rendering. Make sure you have GPU if you use 'hardware'.
        """
        super(DeepmindLabEnv, self).__init__()

        self._action_repeat = action_repeat
        self._observation = observation
        self._lab = deepmind_lab.Lab(
            scene, [self._observation], config=config, renderer=renderer)

        self._lab.reset()
        action_spec = self._lab.action_spec()
        action_list = action_discretize(action_spec)
        self.action_space = gym.spaces.Discrete(len(action_list))
        self._action_list = action_list

        obs = self._lab.observations()[observation]
        self.observation_space = gym.spaces.Box(
            0, 255, obs.shape, dtype=np.uint8)
        self._last_obs = obs