Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] atari_wrapper - numpy problem (AttributeError: 'numpy.random._generator.Generator' object has no attribute 'randint') #875

Closed
semihtasbas opened this issue Apr 19, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@semihtasbas
Copy link

Hi,

I try to use your Atari example in doc, but I receive an error about numpy. I couldn't find a solution about that. I even delete my anaconda and setup environment from scratch. I shared details below.

from stable_baselines3.common.env_util import make_atari_env
from stable_baselines3.common.vec_env import VecFrameStack
from stable_baselines3 import A2C

# There already exists an environment generator
# that will make and wrap atari environments correctly.
# Here we are also multi-worker training (n_envs=4 => 4 environments)
env = make_atari_env('PongNoFrameskip-v4', n_envs=4, seed=0)
# Frame-stacking with 4 frames
env = VecFrameStack(env, n_stack=4)

model = A2C('CnnPolicy', env, verbose=1)
model.learn(total_timesteps=25_000)

obs = env.reset()
while True:
    action, _states = model.predict(obs)
    obs, rewards, dones, info = env.step(action)
    env.render()

Output:

A.L.E: Arcade Learning Environment (version 0.7.5+db37282)
[Powered by Stella]
Using cuda device
Wrapping the env in a VecTransposeImage.
Traceback (most recent call last):
  File "/home/x/PycharmProjects/tries/main.py", line 207, in <module>
    model.learn(total_timesteps=25_000)
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/a2c/a2c.py", line 200, in learn
    reset_num_timesteps=reset_num_timesteps,
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/on_policy_algorithm.py", line 243, in learn
    total_timesteps, eval_env, callback, eval_freq, n_eval_episodes, eval_log_path, reset_num_timesteps, tb_log_name
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/base_class.py", line 429, in _setup_learn
    self._last_obs = self.env.reset()  # pytype: disable=annotation-type-mismatch
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/vec_env/vec_transpose.py", line 110, in reset
    return self.transpose_observations(self.venv.reset())
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/vec_env/vec_frame_stack.py", line 58, in reset
    observation = self.venv.reset()  # pytype:disable=annotation-type-mismatch
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py", line 61, in reset
    obs = self.envs[env_idx].reset()
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/gym/core.py", line 292, in reset
    return self.env.reset(**kwargs)
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/gym/core.py", line 333, in reset
    return self.env.reset(**kwargs)
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/gym/core.py", line 319, in reset
    observation = self.env.reset(**kwargs)
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/atari_wrappers.py", line 59, in reset
    self.env.reset(**kwargs)
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/atari_wrappers.py", line 106, in reset
    obs = self.env.reset(**kwargs)
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/atari_wrappers.py", line 154, in reset
    return self.env.reset(**kwargs)
  File "/home/x/anaconda3/envs/rl/lib/python3.7/site-packages/stable_baselines3/common/atari_wrappers.py", line 36, in reset
    noops = self.unwrapped.np_random.randint(1, self.noop_max + 1)
AttributeError: 'numpy.random._generator.Generator' object has no attribute 'randint'

Process finished with exit code 1
  • I installed pytorch from official website, package:Conda
  • Python = 3.7.13
  • PyTorch = 1.11.0
  • Gym version = 0.21.0
  • Numpy= 1.21.5
  • Stable Baseline = 1.5.0
    (from pip list)
@semihtasbas semihtasbas added the bug Something isn't working label Apr 19, 2022
@araffin
Copy link
Member

araffin commented Apr 19, 2022

Hello,
This is due to latest ale-py version, and fixed in 3c468ff or #780
This easiest fix for you is pip install ale-py==0.7.4 or pip install git+https://github.com/DLR-RM/stable-baselines3 (use master version of SB3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants