add yapf style and apply yapf to format all Python files
This recreates pull request #2192
This commit is contained in:
@@ -7,4 +7,3 @@ from . import train_kuka_grasping
|
||||
from . import train_pybullet_cartpole
|
||||
from . import train_pybullet_racecar
|
||||
from . import train_pybullet_zed_racecar
|
||||
|
||||
|
||||
@@ -6,17 +6,17 @@ import numpy as np
|
||||
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.kuka_diverse_object_gym_env import KukaDiverseObjectEnv
|
||||
from gym import spaces
|
||||
|
||||
|
||||
|
||||
class ContinuousDownwardBiasPolicy(object):
|
||||
"""Policy which takes continuous actions, and is biased to move down.
|
||||
"""
|
||||
|
||||
def __init__(self, height_hack_prob=0.9):
|
||||
"""Initializes the DownwardBiasPolicy.
|
||||
|
||||
@@ -36,25 +36,25 @@ class ContinuousDownwardBiasPolicy(object):
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = KukaDiverseObjectEnv(renders=True, isDiscrete=False)
|
||||
policy = ContinuousDownwardBiasPolicy()
|
||||
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("===================================")
|
||||
print("obs")
|
||||
print(obs)
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render(mode='human')
|
||||
act = policy.sample_action(obs, .1)
|
||||
print("Action")
|
||||
print(act)
|
||||
obs, rew, done, _ = env.step([0, 0, 0, 0, 0])
|
||||
episode_rew += rew
|
||||
print("Episode reward", episode_rew)
|
||||
env = KukaDiverseObjectEnv(renders=True, isDiscrete=False)
|
||||
policy = ContinuousDownwardBiasPolicy()
|
||||
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("===================================")
|
||||
print("obs")
|
||||
print(obs)
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render(mode='human')
|
||||
act = policy.sample_action(obs, .1)
|
||||
print("Action")
|
||||
print(act)
|
||||
obs, rew, done, _ = env.step([0, 0, 0, 0, 0])
|
||||
episode_rew += rew
|
||||
print("Episode reward", episode_rew)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.kukaGymEnv import KukaGymEnv
|
||||
@@ -11,22 +11,22 @@ from baselines import deepq
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = KukaGymEnv(renders=True, isDiscrete=True)
|
||||
act = deepq.load("kuka_model.pkl")
|
||||
print(act)
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("===================================")
|
||||
print("obs")
|
||||
print(obs)
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render()
|
||||
obs, rew, done, _ = env.step(act(obs[None])[0])
|
||||
episode_rew += rew
|
||||
print("Episode reward", episode_rew)
|
||||
|
||||
env = KukaGymEnv(renders=True, isDiscrete=True)
|
||||
act = deepq.load("kuka_model.pkl")
|
||||
print(act)
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("===================================")
|
||||
print("obs")
|
||||
print(obs)
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render()
|
||||
obs, rew, done, _ = env.step(act(obs[None])[0])
|
||||
episode_rew += rew
|
||||
print("Episode reward", episode_rew)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
import time
|
||||
@@ -10,28 +10,29 @@ import time
|
||||
from baselines import deepq
|
||||
from pybullet_envs.bullet.cartpole_bullet import CartPoleBulletEnv
|
||||
|
||||
def main():
|
||||
env = gym.make('CartPoleBulletEnv-v1')
|
||||
act = deepq.load("cartpole_model.pkl")
|
||||
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("obs")
|
||||
print(obs)
|
||||
print("type(obs)")
|
||||
print(type(obs))
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render()
|
||||
|
||||
o = obs[None]
|
||||
aa = act(o)
|
||||
a = aa[0]
|
||||
obs, rew, done, _ = env.step(a)
|
||||
episode_rew += rew
|
||||
time.sleep(1./240.)
|
||||
print("Episode reward", episode_rew)
|
||||
def main():
|
||||
env = gym.make('CartPoleBulletEnv-v1')
|
||||
act = deepq.load("cartpole_model.pkl")
|
||||
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("obs")
|
||||
print(obs)
|
||||
print("type(obs)")
|
||||
print(type(obs))
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render()
|
||||
|
||||
o = obs[None]
|
||||
aa = act(o)
|
||||
a = aa[0]
|
||||
obs, rew, done, _ = env.step(a)
|
||||
episode_rew += rew
|
||||
time.sleep(1. / 240.)
|
||||
print("Episode reward", episode_rew)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.racecarGymEnv import RacecarGymEnv
|
||||
@@ -11,22 +11,22 @@ from baselines import deepq
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = RacecarGymEnv(renders=True,isDiscrete=True)
|
||||
act = deepq.load("racecar_model.pkl")
|
||||
print(act)
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("===================================")
|
||||
print("obs")
|
||||
print(obs)
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render()
|
||||
obs, rew, done, _ = env.step(act(obs[None])[0])
|
||||
episode_rew += rew
|
||||
print("Episode reward", episode_rew)
|
||||
|
||||
env = RacecarGymEnv(renders=True, isDiscrete=True)
|
||||
act = deepq.load("racecar_model.pkl")
|
||||
print(act)
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("===================================")
|
||||
print("obs")
|
||||
print(obs)
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render()
|
||||
obs, rew, done, _ = env.step(act(obs[None])[0])
|
||||
episode_rew += rew
|
||||
print("Episode reward", episode_rew)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.racecarZEDGymEnv import RacecarZEDGymEnv
|
||||
@@ -11,22 +11,22 @@ from baselines import deepq
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = RacecarZEDGymEnv(renders=True)
|
||||
act = deepq.load("racecar_zed_model.pkl")
|
||||
print(act)
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("===================================")
|
||||
print("obs")
|
||||
print(obs)
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render()
|
||||
obs, rew, done, _ = env.step(act(obs[None])[0])
|
||||
episode_rew += rew
|
||||
print("Episode reward", episode_rew)
|
||||
|
||||
env = RacecarZEDGymEnv(renders=True)
|
||||
act = deepq.load("racecar_zed_model.pkl")
|
||||
print(act)
|
||||
while True:
|
||||
obs, done = env.reset(), False
|
||||
print("===================================")
|
||||
print("obs")
|
||||
print(obs)
|
||||
episode_rew = 0
|
||||
while not done:
|
||||
env.render()
|
||||
obs, rew, done, _ = env.step(act(obs[None])[0])
|
||||
episode_rew += rew
|
||||
print("Episode reward", episode_rew)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.kukaCamGymEnv import KukaCamGymEnv
|
||||
@@ -12,39 +12,34 @@ from baselines import deepq
|
||||
import datetime
|
||||
|
||||
|
||||
|
||||
def callback(lcl, glb):
|
||||
# stop training if reward exceeds 199
|
||||
total = sum(lcl['episode_rewards'][-101:-1]) / 100
|
||||
totalt = lcl['t']
|
||||
#print("totalt")
|
||||
#print(totalt)
|
||||
is_solved = totalt > 2000 and total >= 10
|
||||
return is_solved
|
||||
# stop training if reward exceeds 199
|
||||
total = sum(lcl['episode_rewards'][-101:-1]) / 100
|
||||
totalt = lcl['t']
|
||||
#print("totalt")
|
||||
#print(totalt)
|
||||
is_solved = totalt > 2000 and total >= 10
|
||||
return is_solved
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = KukaCamGymEnv(renders=False, isDiscrete=True)
|
||||
model = deepq.models.cnn_to_mlp(
|
||||
convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)],
|
||||
hiddens=[256],
|
||||
dueling=False
|
||||
)
|
||||
act = deepq.learn(
|
||||
env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=10000000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback
|
||||
)
|
||||
print("Saving model to kuka_cam_model.pkl")
|
||||
act.save("kuka_cam_model.pkl")
|
||||
|
||||
env = KukaCamGymEnv(renders=False, isDiscrete=True)
|
||||
model = deepq.models.cnn_to_mlp(convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)],
|
||||
hiddens=[256],
|
||||
dueling=False)
|
||||
act = deepq.learn(env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=10000000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback)
|
||||
print("Saving model to kuka_cam_model.pkl")
|
||||
act.save("kuka_cam_model.pkl")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.kukaGymEnv import KukaGymEnv
|
||||
@@ -12,35 +12,32 @@ from baselines import deepq
|
||||
import datetime
|
||||
|
||||
|
||||
|
||||
def callback(lcl, glb):
|
||||
# stop training if reward exceeds 199
|
||||
total = sum(lcl['episode_rewards'][-101:-1]) / 100
|
||||
totalt = lcl['t']
|
||||
#print("totalt")
|
||||
#print(totalt)
|
||||
is_solved = totalt > 2000 and total >= 10
|
||||
return is_solved
|
||||
# stop training if reward exceeds 199
|
||||
total = sum(lcl['episode_rewards'][-101:-1]) / 100
|
||||
totalt = lcl['t']
|
||||
#print("totalt")
|
||||
#print(totalt)
|
||||
is_solved = totalt > 2000 and total >= 10
|
||||
return is_solved
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = KukaGymEnv(renders=False, isDiscrete=True)
|
||||
model = deepq.models.mlp([64])
|
||||
act = deepq.learn(
|
||||
env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=10000000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback
|
||||
)
|
||||
print("Saving model to kuka_model.pkl")
|
||||
act.save("kuka_model.pkl")
|
||||
|
||||
env = KukaGymEnv(renders=False, isDiscrete=True)
|
||||
model = deepq.models.mlp([64])
|
||||
act = deepq.learn(env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=10000000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback)
|
||||
print("Saving model to kuka_model.pkl")
|
||||
act.save("kuka_model.pkl")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.cartpole_bullet import CartPoleBulletEnv
|
||||
@@ -11,29 +11,27 @@ from baselines import deepq
|
||||
|
||||
|
||||
def callback(lcl, glb):
|
||||
# stop training if reward exceeds 199
|
||||
is_solved = lcl['t'] > 100 and sum(lcl['episode_rewards'][-101:-1]) / 100 >= 199
|
||||
return is_solved
|
||||
# stop training if reward exceeds 199
|
||||
is_solved = lcl['t'] > 100 and sum(lcl['episode_rewards'][-101:-1]) / 100 >= 199
|
||||
return is_solved
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = CartPoleBulletEnv(renders=False)
|
||||
model = deepq.models.mlp([64])
|
||||
act = deepq.learn(
|
||||
env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=100000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback
|
||||
)
|
||||
print("Saving model to cartpole_model.pkl")
|
||||
act.save("cartpole_model.pkl")
|
||||
|
||||
env = CartPoleBulletEnv(renders=False)
|
||||
model = deepq.models.mlp([64])
|
||||
act = deepq.learn(env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=100000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback)
|
||||
print("Saving model to cartpole_model.pkl")
|
||||
act.save("cartpole_model.pkl")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.racecarGymEnv import RacecarGymEnv
|
||||
@@ -12,33 +12,30 @@ from baselines import deepq
|
||||
import datetime
|
||||
|
||||
|
||||
|
||||
def callback(lcl, glb):
|
||||
# stop training if reward exceeds 199
|
||||
total = sum(lcl['episode_rewards'][-101:-1]) / 100
|
||||
totalt = lcl['t']
|
||||
is_solved = totalt > 2000 and total >= -50
|
||||
return is_solved
|
||||
# stop training if reward exceeds 199
|
||||
total = sum(lcl['episode_rewards'][-101:-1]) / 100
|
||||
totalt = lcl['t']
|
||||
is_solved = totalt > 2000 and total >= -50
|
||||
return is_solved
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = RacecarGymEnv(renders=False,isDiscrete=True)
|
||||
model = deepq.models.mlp([64])
|
||||
act = deepq.learn(
|
||||
env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=10000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback
|
||||
)
|
||||
print("Saving model to racecar_model.pkl")
|
||||
act.save("racecar_model.pkl")
|
||||
|
||||
env = RacecarGymEnv(renders=False, isDiscrete=True)
|
||||
model = deepq.models.mlp([64])
|
||||
act = deepq.learn(env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=10000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback)
|
||||
print("Saving model to racecar_model.pkl")
|
||||
act.save("racecar_model.pkl")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import os, inspect
|
||||
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
|
||||
parentdir = os.path.dirname(os.path.dirname(currentdir))
|
||||
os.sys.path.insert(0,parentdir)
|
||||
os.sys.path.insert(0, parentdir)
|
||||
|
||||
import gym
|
||||
from pybullet_envs.bullet.racecarZEDGymEnv import RacecarZEDGymEnv
|
||||
@@ -12,36 +12,32 @@ from baselines import deepq
|
||||
import datetime
|
||||
|
||||
|
||||
|
||||
def callback(lcl, glb):
|
||||
# stop training if reward exceeds 199
|
||||
total = sum(lcl['episode_rewards'][-101:-1]) / 100
|
||||
totalt = lcl['t']
|
||||
is_solved = totalt > 2000 and total >= -50
|
||||
return is_solved
|
||||
# stop training if reward exceeds 199
|
||||
total = sum(lcl['episode_rewards'][-101:-1]) / 100
|
||||
totalt = lcl['t']
|
||||
is_solved = totalt > 2000 and total >= -50
|
||||
return is_solved
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
env = RacecarZEDGymEnv(renders=False, isDiscrete=True)
|
||||
model = deepq.models.cnn_to_mlp(
|
||||
convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)],
|
||||
hiddens=[256],
|
||||
dueling=False
|
||||
)
|
||||
act = deepq.learn(
|
||||
env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=10000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback
|
||||
)
|
||||
print("Saving model to racecar_zed_model.pkl")
|
||||
act.save("racecar_zed_model.pkl")
|
||||
|
||||
env = RacecarZEDGymEnv(renders=False, isDiscrete=True)
|
||||
model = deepq.models.cnn_to_mlp(convs=[(32, 8, 4), (64, 4, 2), (64, 3, 1)],
|
||||
hiddens=[256],
|
||||
dueling=False)
|
||||
act = deepq.learn(env,
|
||||
q_func=model,
|
||||
lr=1e-3,
|
||||
max_timesteps=10000,
|
||||
buffer_size=50000,
|
||||
exploration_fraction=0.1,
|
||||
exploration_final_eps=0.02,
|
||||
print_freq=10,
|
||||
callback=callback)
|
||||
print("Saving model to racecar_zed_model.pkl")
|
||||
act.save("racecar_zed_model.pkl")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user