agents icon indicating copy to clipboard operation
agents copied to clipboard

Loading Atari environments causes errors in render

Open neramas1221 opened this issue 2 years ago • 1 comments

Hi, I'm trying to load in the space invaders environment using tf_agent I tried to different approaches

env_name = 'ALE/SpaceInvaders-v5'
env = suite_atari.load(env_name)

env.reset()
env.render()

which gives the following error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-12-be1053842d2d>](https://localhost:8080/#) in <cell line: 3>()
      1 # PIL.Image.fromarray(env.render())
      2 env.reset()
----> 3 env.render()

4 frames
[/usr/local/lib/python3.9/dist-packages/tf_agents/environments/gym_wrapper.py](https://localhost:8080/#) in render(self, mode)
    264 
    265   def render(self, mode: Text = 'rgb_array') -> Any:
--> 266     return self._gym_env.render(mode, **self._render_kwargs)
    267 
    268   # pytype: disable=attribute-error

[/usr/local/lib/python3.9/dist-packages/gym/core.py](https://localhost:8080/#) in render(self, *args, **kwargs)
    327     ) -> Optional[Union[RenderFrame, List[RenderFrame]]]:
    328         """Renders the environment."""
--> 329         return self.env.render(*args, **kwargs)
    330 
    331     def close(self):

[/usr/local/lib/python3.9/dist-packages/gym/wrappers/order_enforcing.py](https://localhost:8080/#) in render(self, *args, **kwargs)
     49                 "set `disable_render_order_enforcing=True` on the OrderEnforcer wrapper."
     50             )
---> 51         return self.env.render(*args, **kwargs)
     52 
     53     @property

[/usr/local/lib/python3.9/dist-packages/gym/wrappers/env_checker.py](https://localhost:8080/#) in render(self, *args, **kwargs)
     51         if self.checked_render is False:
     52             self.checked_render = True
---> 53             return env_render_passive_checker(self.env, *args, **kwargs)
     54         else:
     55             return self.env.render(*args, **kwargs)

[/usr/local/lib/python3.9/dist-packages/gym/utils/passive_env_checker.py](https://localhost:8080/#) in env_render_passive_checker(env, *args, **kwargs)
    314             )
    315 
--> 316     result = env.render(*args, **kwargs)
    317 
    318     # TODO: Check that the result is correct

TypeError: render() takes 1 positional argument but 2 were given

When using the other method I get this error (error on restart)

env_name = 'ALE/SpaceInvaders-v5'
env = suite_gym.load(env_name)
env.reset()
env.render()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-15-be1053842d2d>](https://localhost:8080/#) in <cell line: 2>()
      1 # PIL.Image.fromarray(env.render())
----> 2 env.reset()
      3 env.render()

2 frames
[/usr/local/lib/python3.9/dist-packages/tf_agents/environments/py_environment.py](https://localhost:8080/#) in reset(self)
    193           corresponding to `observation_spec()`.
    194     """
--> 195     self._current_time_step = self._reset()
    196     return self._current_time_step
    197 

[/usr/local/lib/python3.9/dist-packages/tf_agents/environments/gym_wrapper.py](https://localhost:8080/#) in _reset(self)
    197 
    198     if self._match_obs_space_dtype:
--> 199       observation = self._to_obs_space_dtype(observation)
    200     return ts.restart(observation)
    201 

[/usr/local/lib/python3.9/dist-packages/tf_agents/environments/gym_wrapper.py](https://localhost:8080/#) in _to_obs_space_dtype(self, observation)
    244     matched_observations = []
    245     for spec, obs in zip(self._flat_obs_spec, flat_obs):
--> 246       matched_observations.append(np.asarray(obs, dtype=spec.dtype))
    247     return tf.nest.pack_sequence_as(self._observation_spec,
    248                                     matched_observations)

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

I'm not sure how to fix these or what could be the problem, any help is greatly appreciated

neramas1221 avatar Apr 09 '23 13:04 neramas1221

Hi, did you fix this issue? I am getting the same issue but with a simple minigrid code.

import gymnasium as gym
first_task = gym.make("MiniGrid-Unlock-v0")
first_task.reset(seed=0)
x = first_task.render('rgb_array')

Any help would be greatly appreciated!

meghbhalerao avatar Dec 05 '24 17:12 meghbhalerao