前提・実現したいこと
donkeycarで強化学習の勉強をしようとしています。
環境設定等を終わらせ、シミュレーターを起動するところまではできました。
gym-donkeycarにddqn.pyというサンプルコードがあるのでこれを実行しようとしてエラーがでました。
環境構築の手順
https://docs.donkeycar.com/guide/install_software/#step-1-install-software-on-host-pc
https://docs.donkeycar.com/guide/simulator/#train
発生している問題・エラーメッセージ
実行文:python ddqn.py --sim /home/<path>/DonkeySimLinux/donkey_sim.x86_64
--simをやりたいのですが、エラーを見ると--env_nameで処理されているのかもしれません。
Traceback (most recent call last): File "ddqn.py", line 365, in <module> run_ddqn(args) File "ddqn.py", line 224, in run_ddqn env = gym.make(args.env_name, conf=conf) File "/home/user/anaconda3/envs/donkey/lib/python3.7/site-packages/gym/envs/registration.py", line 145, in make return registry.make(id, **kwargs) File "/home/user/anaconda3/envs/donkey/lib/python3.7/site-packages/gym/envs/registration.py", line 89, in make spec = self.spec(path) File "/home/user/anaconda3/envs/donkey/lib/python3.7/site-packages/gym/envs/registration.py", line 131, in spec raise error.UnregisteredEnv('No registered env with id: {}'.format(id)) gym.error.UnregisteredEnv: No registered env with id: donkey-warehouse-v0
該当のソースコード
condaで環境を作っています。
サイトからymlをダウンロードして、その環境だと[tf2]でしたが、ddqn.pyでは一部[tf1]じゃないと動かない部分があったので、その部分だけ[tensorflow.compat.v1]に書き換えています。(202行目付近)
python
1""" 2file: ddqn.py 3author: Felix Yu 4date: 2018-09-12 5original: https://github.com/flyyufelix/donkey_rl/blob/master/donkey_rl/src/ddqn.py 6""" 7import argparse 8import os 9import random 10import signal 11import sys 12import uuid 13from collections import deque 14 15import cv2 16import gym 17import numpy as np 18import tensorflow as tf 19from tensorflow.keras import backend as K 20from tensorflow.compat.v1.keras import backend as K1 21from tensorflow.keras.layers import Activation, Conv2D, Dense, Flatten 22from tensorflow.keras.models import Sequential 23from tensorflow.keras.optimizers import Adam 24 25#文字数制限に引っかかったので省略しました。 26 27 # only needed if TF==1.13.1 28 # config = tf.ConfigProto() 29 config = tf.compat.v1.ConfigProto() 30 config.gpu_options.allow_growth = True 31 # sess = tf.Session(config=config) 32 sess = tf.compat.v1.Session(config=config) 33 K1.set_session(sess) 34 35 conf = { 36 "exe_path": args.sim, 37 "host": "127.0.0.1", 38 "port": args.port, 39 "body_style": "donkey", 40 "body_rgb": (128, 128, 128), 41 "car_name": "me", 42 "font_size": 100, 43 "racer_name": "DDQN", 44 "country": "USA", 45 "bio": "Learning to drive w DDQN RL", 46 "guid": str(uuid.uuid4()), 47 "max_cte": 10, 48 } 49 50 # Construct gym environment. Starts the simulator if path is given. 51 env = gym.make(args.env_name, conf=conf) 52 53 # not working on windows... 54 def signal_handler(signal, frame): 55 print("catching ctrl+c") 56 env.unwrapped.close() 57 sys.exit(0) 58 59 signal.signal(signal.SIGINT, signal_handler) 60 signal.signal(signal.SIGTERM, signal_handler) 61 signal.signal(signal.SIGABRT, signal_handler) 62 63 # Get size of state and action from environment 64 state_size = (img_rows, img_cols, img_channels) 65 action_space = env.action_space # Steering and Throttle 66 67 try: 68 agent = DQNAgent(state_size, action_space, train=not args.test) 69 70 throttle = args.throttle # Set throttle as constant value 71 72 episodes = [] 73 74 if os.path.exists(args.model): 75 print("load the saved model") 76 agent.load_model(args.model) 77 78 for e in range(EPISODES): 79 80 print("Episode: ", e) 81 82 done = False 83 obs = env.reset() 84 85 episode_len = 0 86 87 x_t = agent.process_image(obs) 88 89 s_t = np.stack((x_t, x_t, x_t, x_t), axis=2) 90 # In Keras, need to reshape 91 s_t = s_t.reshape(1, s_t.shape[0], s_t.shape[1], s_t.shape[2]) # 1*80*80*4 92 93 while not done: 94 95 # Get action for the current state and go one step in environment 96 steering = agent.get_action(s_t) 97 action = [steering, throttle] 98 next_obs, reward, done, info = env.step(action) 99 100 x_t1 = agent.process_image(next_obs) 101 102 x_t1 = x_t1.reshape(1, x_t1.shape[0], x_t1.shape[1], 1) # 1x80x80x1 103 s_t1 = np.append(x_t1, s_t[:, :, :, :3], axis=3) # 1x80x80x4 104 105 # Save the sample <s, a, r, s'> to the replay memory 106 agent.replay_memory(s_t, np.argmax(linear_bin(steering)), reward, s_t1, done) 107 agent.update_epsilon() 108 109 if agent.train: 110 agent.train_replay() 111 112 s_t = s_t1 113 agent.t = agent.t + 1 114 episode_len = episode_len + 1 115 if agent.t % 30 == 0: 116 print( 117 "EPISODE", 118 e, 119 "TIMESTEP", 120 agent.t, 121 "/ ACTION", 122 action, 123 "/ REWARD", 124 reward, 125 "/ EPISODE LENGTH", 126 episode_len, 127 "/ Q_MAX ", 128 agent.max_Q, 129 ) 130 131 if done: 132 133 # Every episode update the target model to be same with model 134 agent.update_target_model() 135 136 episodes.append(e) 137 138 # Save model for each episode 139 if agent.train: 140 agent.save_model(args.model) 141 142 print( 143 "episode:", 144 e, 145 " memory length:", 146 len(agent.memory), 147 " epsilon:", 148 agent.epsilon, 149 " episode length:", 150 episode_len, 151 ) 152 153 except KeyboardInterrupt: 154 print("stopping run...") 155 finally: 156 env.unwrapped.close() 157 158 159if __name__ == "__main__": 160 161 # Initialize the donkey environment 162 # where env_name one of: 163 env_list = [ 164 "donkey-warehouse-v0", 165 "donkey-generated-roads-v0", 166 "donkey-avc-sparkfun-v0", 167 "donkey-generated-track-v0", 168 "donkey-roboracingleague-track-v0", 169 "donkey-waveshare-v0", 170 "donkey-minimonaco-track-v0", 171 "donkey-warren-track-v0", 172 "donkey-thunderhill-track-v0", 173 ] 174 175 parser = argparse.ArgumentParser(description="ddqn") 176 parser.add_argument( 177 "--sim", 178 type=str, 179 default="manual", 180 help="path to unity simulator. maybe be left at manual if you would like to start the sim on your own.", 181 ) 182 parser.add_argument("--model", type=str, default="rl_driver.h5", help="path to model") 183 parser.add_argument("--test", action="store_true", help="agent uses learned model to navigate env") 184 parser.add_argument("--port", type=int, default=9091, help="port to use for websockets") 185 parser.add_argument("--throttle", type=float, default=0.3, help="constant throttle for driving") 186 parser.add_argument( 187 "--env_name", type=str, default="donkey-warehouse-v0", help="name of donkey sim environment", choices=env_list 188 ) 189 190 args = parser.parse_args() 191 192 run_ddqn(args)
補足情報(FW/ツールのバージョンなど)
[donkey-generated-track-v0]はgym-donkeyにあるようです。
https://gym-donkeycar.readthedocs.io/en/latest/readme.html
また、上記サイトの[Example Usage]も試しましたが、同様のエラーがでました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。