From b4fa5624143643a3b7d641e4fd2c91f4af8cad74 Mon Sep 17 00:00:00 2001 From: Anish Muthali Date: Mon, 21 Oct 2019 20:50:27 -0700 Subject: [PATCH 1/3] Added basic test model --- DQN_model.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 DQN_model.py diff --git a/DQN_model.py b/DQN_model.py new file mode 100644 index 0000000..0682900 --- /dev/null +++ b/DQN_model.py @@ -0,0 +1,31 @@ +import os +import gym +import gym_donkeycar +import numpy as np +from stable_baselines.common.vec_env import DummyVecEnv +from stable_baselines.deepq.policies import MlpPolicy +from stable_baselines import DQN + +#SET UP ENVIRONMENT +os.environ['DONKEY_SIM_PATH'] = f"./DonkeySimMac/donkey_sim.app/Contents/MacOS/donkey_sim" +os.environ['DONKEY_SIM_PORT'] = str(9091) +os.environ['DONKEY_SIM_HEADLESS'] = str(1) # "1" is headless + +env = gym.make("donkey-warehouse-v0") +#gym.make("donkey-generated-roads-v0") + +timesteps = 100000 # Set this to a reasonable number +model_name = "dqn_model" # Change the model name to your preferences +training = True # Change this to test or use the model + +if training: + model = DQN(MlpPolicy, env, verbose=1) + model.learn(total_timesteps=timesteps) + model.save(model_name) +else: + model = DQN.load(model_name) + obv = env.reset() + for t in range(10000): + action, _states = model.predict(obv) # drive straight with small speed + # execute the action + obv, reward, done, info = env.step(action) From 106e4fc05d2e9fbb208ee4951cca03cdb7ead0e0 Mon Sep 17 00:00:00 2001 From: Ethan Burrell <30448729+ethanburrell@users.noreply.github.com> Date: Mon, 18 Nov 2019 19:46:36 -0800 Subject: [PATCH 2/3] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index df8801e..ab2928c 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ https://github.com/tawnkramer/gym-donkeycar/tree/master/examples Download program for your computer: https://github.com/tawnkramer/gym-donkeycar/releases +``` import os import gym import gym_donkeycar @@ -73,3 +74,5 @@ for t in range(100): action = np.array([0.0,0.5]) # drive straight with small speed # execute the action obv, reward, done, info = env.step(action) + +``` From 70576821c277f63405c49cd28224b29d0d961a02 Mon Sep 17 00:00:00 2001 From: Anish Muthali Date: Thu, 21 Nov 2019 20:43:42 -0800 Subject: [PATCH 3/3] Added gitignore + bad DQN model --- .gitignore | 2 ++ DQN_model.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bfc8844 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +unitylog.txt +env diff --git a/DQN_model.py b/DQN_model.py index 0682900..1365cef 100644 --- a/DQN_model.py +++ b/DQN_model.py @@ -3,27 +3,28 @@ import gym_donkeycar import numpy as np from stable_baselines.common.vec_env import DummyVecEnv -from stable_baselines.deepq.policies import MlpPolicy -from stable_baselines import DQN +from stable_baselines.ddpg.policies import CnnPolicy +from stable_baselines import DDPG #SET UP ENVIRONMENT -os.environ['DONKEY_SIM_PATH'] = f"./DonkeySimMac/donkey_sim.app/Contents/MacOS/donkey_sim" +os.environ['DONKEY_SIM_PATH'] = f"../DonkeySimMac/donkey_sim.app/Contents/MacOS/donkey_sim" os.environ['DONKEY_SIM_PORT'] = str(9091) -os.environ['DONKEY_SIM_HEADLESS'] = str(1) # "1" is headless +os.environ['DONKEY_SIM_HEADLESS'] = str(0) # "1" is headless env = gym.make("donkey-warehouse-v0") #gym.make("donkey-generated-roads-v0") timesteps = 100000 # Set this to a reasonable number -model_name = "dqn_model" # Change the model name to your preferences +model_name = "ddpg_model" # Change the model name to your preferences training = True # Change this to test or use the model if training: - model = DQN(MlpPolicy, env, verbose=1) + vec_env = DummyVecEnv([lambda: env]) + model = DDPG(CnnPolicy, vec_env, verbose=1) model.learn(total_timesteps=timesteps) model.save(model_name) else: - model = DQN.load(model_name) + model = DDPG.load(model_name) obv = env.reset() for t in range(10000): action, _states = model.predict(obv) # drive straight with small speed