Stable-Baselines の SubprocVecEnvや、DummyVecEnvを実行するとGoogle Colab でクラッシュします。対処法はありますか?
Python
1!pip install stable-baselines==2.10.0 2%tensorflow_version 1.x 3 4 5import gym 6import numpy as np 7 8from stable_baselines.common.policies import MlpPolicy 9from stable_baselines.common.vec_env import SubprocVecEnv, DummyVecEnv 10from stable_baselines.common import set_global_seeds #, make_vec_env 11from stable_baselines import ACKTR 12 13import numpy as np 14 15from stable_baselines.common.policies import MlpPolicy 16from stable_baselines.common.vec_env import SubprocVecEnv 17from stable_baselines.common import set_global_seeds, make_vec_env 18from stable_baselines import ACKTR 19 20def make_env(env_id, rank, seed=0): 21 """ 22 Utility function for multiprocessed env. 23 24 :param env_id: (str) the environment ID 25 :param num_env: (int) the number of environments you wish to have in subprocesses 26 :param seed: (int) the inital seed for RNG 27 :param rank: (int) index of the subprocess 28 """ 29 def _init(): 30 env = gym.make(env_id) 31 env.seed(seed + rank) 32 return env 33 set_global_seeds(seed) 34 return _init 35 36if __name__ == '__main__': 37 38 # こちらはOK 39 env_id = "CartPole-v1" 40 # こちらは画像が入力なので、クラッシュ 41 env_id = "BreakoutDeterministic-v4" 42 num_cpu = 4 # Number of processes to use 43 # Create the vectorized environment 44 env = SubprocVecEnv([make_env(env_id, i) for i in range(num_cpu)]) 45 46 # Stable Baselines provides you with make_vec_env() helper 47 # which does exactly the previous steps for you: 48 # env = make_vec_env(env_id, n_envs=num_cpu, seed=0) 49 50 model = ACKTR(MlpPolicy, env, verbose=1) 51 model.learn(total_timesteps=25000) 52 53 obs = env.reset() 54 for _ in range(1000): 55 action, _states = model.predict(obs) 56 obs, rewards, dones, info = env.step(action)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。