浏览代码

Allow multiple visual observations (#2003)

* Add allow_multiple_visual_obs option to the UnityEnv class

* Edit associated documentation for the `allow_multiple_visual_obs` option
/develop-generalizationTraining-TrainerController
Arthur Juliani 5 年前
当前提交
0db2f8bf
共有 2 个文件被更改,包括 24 次插入6 次删除
  1. 12
      gym-unity/README.md
  2. 18
      gym-unity/gym_unity/envs/unity_env.py

12
gym-unity/README.md


* `flatten_branched` will flatten a branched discrete action space into a Gym Discrete.
Otherwise, it will be converted into a MultiDiscrete. Defaults to `False`.
* `allow_multiple_visual_obs` will return a list of observation instead of only
one if disabled. Defaults to `False`.
## Limitation
## Limitations
* By default the first visual observation is provided as the `observation`, if
present. Otherwise vector observations are provided.
* By default, the first visual observation is provided as the `observation`, if
present. Otherwise, vector observations are provided. You can receive all visual
observations by using the `allow_multiple_visual_obs=True` option in the gym
parameters. If set to `True`, you will receive a list of `observation` instead
of only the first one.
* All `BrainInfo` output from the environment can still be accessed from the
`info` provided by `env.step(action)`.
* Stacked vector observations are not supported.

18
gym-unity/gym_unity/envs/unity_env.py


multiagent=False,
flatten_branched=False,
no_graphics=False,
allow_multiple_visual_obs=False,
):
"""
Environment initialization

:param multiagent: Whether to run in multi-agent mode (lists of obs, reward, done).
:param flatten_branched: If True, turn branched discrete action spaces into a Discrete space rather than MultiDiscrete.
:param no_graphics: Whether to run the Unity simulator in no-graphics mode
:param allow_multiple_visual_obs: If True, return a list of visual observations instead of only one.
"""
self._env = UnityEnvironment(
environment_filename, worker_id, no_graphics=no_graphics

self.game_over = (
False
) # Hidden flag used by Atari environments to determine if the game is over
self._allow_multiple_visual_obs = allow_multiple_visual_obs
# Check brain configuration
if len(self._env.brains) != 1:

else:
self.uint8_visual = uint8_visual
if brain.number_visual_observations > 1:
if brain.number_visual_observations > 1 and not self._allow_multiple_visual_obs:
"Please note that only the first will be provided in the observation."
"You must define allow_multiple_visual_obs=True to received them all. "
"Otherwise, please note that only the first will be provided in the observation."
)
if brain.num_stacked_vector_observations != 1:

visual_obs = info.visual_observations
if isinstance(visual_obs, list):
visual_obs = np.array(visual_obs)
self.visual_obs = self._preprocess_single(visual_obs[0][0, :, :, :])
if self._allow_multiple_visual_obs:
visual_obs_list = []
for obs in visual_obs:
visual_obs_list.append(self._preprocess_single(obs[0, :, :, :]))
self.visual_obs = visual_obs_list
else:
self.visual_obs = self._preprocess_single(visual_obs[0][0, :, :, :])
default_observation = self.visual_obs
else:
default_observation = info.vector_observations[0, :]

正在加载...
取消
保存