cloud9でjupyter notebookを起動しそこで発生したエラーの内容が分かりません。
python
1%matplotlib inline 2import gym 3import random 4from gym import envs 5from gym import wrappers 6import numpy as np 7import keras 8from keras.models import Sequential 9from keras.layers import Dense 10 11ENV_NAME = 'CartPole-v0' # Gymの環境名 12NUM_EPISODES = 12000 # プレイするエピソード数 13 14NUM_ACTIONS = 2 15NUM_STATES = 4 16NUM_GAMES_TRAIN = 500 17BATCH_SIZE = 20 18MAX_REPLAY_STATES = 100 19JUMP_FPS = 2 20 21RENDER = True 22SAVE_NETWORK_PATH = 'saved_networks/' + ENV_NAME 23SAVE_SUMMARY_PATH = 'summary/' + ENV_NAME 24 25def create_model(n_inputs, n_outputs): 26 model = Sequential() 27 model.add(Dense(8, activation='relu', input_dim=n_inputs)) 28 model.add(Dense(16, activation='relu')) 29 model.add(Dense(n_outputs, activation='linear')) 30 model.summary() 31 32 model.compile('adam', loss = 'mse') 33 return model 34 35def main(): 36 37 env = gym.make(ENV_NAME) 38 39 # training結果を出力 40 # env = gym.wrappers.Monitor(env, 'training') 41 42 # env.observation_space #Boxが返ってくるから .shapeでタプルを取得 43 in_dim = env.observation_space.shape[0] 44 # env.action_space #Discreteが返ってくる 取れないから数字を見る 45 print(env.action_space) 46 out_dim = 2 47 48 #stepが返してくるStateの数と、取りうる入力の数を使う 49 model = create_model(in_dim, out_dim) 50 # env = wrappers.Monitor(env, './cartpole-experiment-1') 51 52 replay = [] #リプレイメモリ 53 54 gamma = 0.99 #割引率 55 epsilon = 1 #ランダム行動を行う確率 56 57 for i_episode in range(NUM_GAMES_TRAIN): 58 new_state = env.reset() 59 done = False 60 t = 0 61 total_reward = 0 62 total_loss = 0 63 64 while not done: 65 if RENDER: 66 env.render() 67 68 #actionを決定 - epsilonはエピソードごとに減少 69 #初期状態ではネットワークの初期化時のランダム性に影響を受けやすいから徐々に減らす? 70 if random.random() < epsilon: 71 action = env.action_space.sample() 72 else: 73 #累積報酬の期待値をそれぞれのactionについて予測 74 q = model.predict(new_state.reshape(1, NUM_STATES))[0] 75 action = np.argmax(q) 76 77 old_state = new_state 78 new_state, reward, done, info = env.step(action) #actionを実行 79 80 #リプレイメモリに保存 81 replay.append([old_state, action, reward, new_state, done]) 82 83 #リプレイメモリからランダムに取り除く - 多分メモリ節約 84 if len(replay) > MAX_REPLAY_STATES: 85 replay.pop(np.random.randint(MAX_REPLAY_STATES) + 1) 86 87 #フレームをスキップする 88 if JUMP_FPS != 1 and (t % JUMP_FPS) != 0: # We skip this train, but already add data 89 t = t+1 90 continue 91 92 #リプレイメモリからミニバッチを作成 93 batch_len = min(len(replay), BATCH_SIZE) 94 mini_batch = random.sample(replay, batch_len) 95 96 #学習用の入力と教師データの配列 97 X_train = np.zeros((batch_len, NUM_STATES)) #指定は次元数 98 Y_train = np.zeros((batch_len, NUM_ACTIONS)) 99 100 for i in range(batch_len): 101 old_state_rep, action_rep, reward_rep, new_state_rep, done_rep, = mini_batch[i] 102 X_train[i] = old_state_rep #学習データ 103 104 #教師データの作成 105 old_q = model.predict(old_state_rep.reshape(1, NUM_STATES))[0] 106 new_q = model.predict(new_state_rep.reshape(1, NUM_STATES))[0] 107 if done_rep: 108 #終了したということは取った行動が間違いだったということなので -1 にしてる? 109 old_q[action_rep] = -1 110 else: 111 #終了しなかったときは、現在の報酬と将来取りうる最大累積報酬 112 old_q[action_rep] = reward_rep + gamma * np.max(new_q) 113 114 Y_train[i] = old_q #教師データ 115 116 loss = model.train_on_batch(X_train, Y_train) 117 118 t = t+1 119 total_reward += reward 120 total_loss += loss; 121 122 if done: 123 print("Episode={}, time={}, reward={}, epsilon={:.4f}, loss={}"\ 124 .format(i_episode, t, total_reward, epsilon, total_loss/t)) 125 if epsilon >= 0.1: 126 epsilon -= (1 / (NUM_GAMES_TRAIN)) 127 128 129if __name__ == '__main__': 130 main()
エラー内容
OSError Traceback (most recent call last) <ipython-input-1-865a9e3dbb3e> in <module>() 127 128 if __name__ == '__main__': --> 129 main() <ipython-input-1-865a9e3dbb3e> in main() 64 while not done: 65 if RENDER: ---> 66 env.render() 67 68 #actionを決定 - epsilonはエピソードごとに減少 /usr/local/lib/python3.4/dist-packages/gym/core.py in render(self, mode, close) 151 elif mode not in modes: 152 raise error.UnsupportedMode('Unsupported rendering mode: {}. (Supported modes for {}: {})'.format(mode, self, modes)) --> 153 return self._render(mode=mode, close=close) 154 155 def close(self): /usr/local/lib/python3.4/dist-packages/gym/core.py in _render(self, mode, close) 283 284 def _render(self, mode='human', close=False): --> 285 return self.env.render(mode, close) 286 287 def _close(self): /usr/local/lib/python3.4/dist-packages/gym/core.py in render(self, mode, close) 151 elif mode not in modes: 152 raise error.UnsupportedMode('Unsupported rendering mode: {}. (Supported modes for {}: {})'.format(mode, self, modes)) --> 153 return self._render(mode=mode, close=close) 154 155 def close(self): /usr/local/lib/python3.4/dist-packages/gym/envs/classic_control/cartpole.py in _render(self, mode, close) 112 113 if self.viewer is None: --> 114 from gym.envs.classic_control import rendering 115 self.viewer = rendering.Viewer(screen_width, screen_height) 116 l,r,t,b = -cartwidth/2, cartwidth/2, cartheight/2, -cartheight/2 /usr/local/lib/python3.4/dist-packages/gym/envs/classic_control/rendering.py in <module>() 21 22 try: ---> 23 from pyglet.gl import * 24 except ImportError as e: 25 reraise(prefix="Error occured while running `from pyglet.gl import *`",suffix="HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'. If you're running on a server, you may need a virtual frame buffer; something like this should work: 'xvfb-run -s \"-screen 0 1400x900x24\" python <your_script.py>'") /usr/local/lib/python3.4/dist-packages/pyglet/gl/__init__.py in <module>() 95 __version__ = '$Id$' 96 ---> 97 from pyglet.gl.lib import GLException 98 from pyglet.gl.gl import * 99 from pyglet.gl.glu import * /usr/local/lib/python3.4/dist-packages/pyglet/gl/lib.py in <module>() 140 from pyglet.gl.lib_agl import link_GL, link_GLU, link_AGL 141 else: --> 142 from pyglet.gl.lib_glx import link_GL, link_GLU, link_GLX 143 /usr/local/lib/python3.4/dist-packages/pyglet/gl/lib_glx.py in <module>() 48 __all__ = ['link_GL', 'link_GLU', 'link_GLX'] 49 ---> 50 gl_lib = pyglet.lib.load_library('GL') 51 glu_lib = pyglet.lib.load_library('GLU') 52 /usr/local/lib/python3.4/dist-packages/pyglet/lib.py in load_library(self, *names, **kwargs) 133 for name in platform_names: 134 try: --> 135 lib = ctypes.cdll.LoadLibrary(name) 136 if _debug_lib: 137 print(name) /usr/lib/python3.4/ctypes/__init__.py in LoadLibrary(self, name) 427 428 def LoadLibrary(self, name): --> 429 return self._dlltype(name) 430 431 cdll = LibraryLoader(CDLL) /usr/lib/python3.4/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error) 349 350 if handle is None: --> 351 self._handle = _dlopen(self._name, mode) 352 else: 353 self._handle = handle OSError: dlopen: cannot load any more object with static TLS
あなたの回答
tips
プレビュー