args = parser.parse_args() if args.resume is None: args.output = get_output_folder(args.output, args.env) else: args.output = args.resume bullet = ("Bullet" in args.env) if bullet: import pybullet import pybullet_envs if args.env == "Paint": from env import CanvasEnv env = CanvasEnv() writer.add_image('circle.png', env.target) elif args.env == "KukaGym": env = KukaGymEnv(renders=False, isDiscrete=True) elif args.env == "LTR": from osim.env import RunEnv env = RunEnv(visualize=False) elif args.discrete: env = gym.make(args.env) env = env.unwrapped else: env = NormalizedEnv(gym.make(args.env)) # input random seed if args.seed > 0: np.random.seed(args.seed)
def save_weights(self): networks = ['actor', 'critic', 'actor_target', 'critic_target'] for name in networks: network = getattr(self, name) network.save_weights('ddpg_' + name + '.npz') def load_weights(self): networks = ['actor', 'critic', 'actor_target', 'critic_target'] for name in networks: network = getattr(self, name) network.load_weights('ddpg_' + name + '.npz') if __name__ == '__main__': from env import CanvasEnv e = CanvasEnv() agent = nnagent( e.action_space, discount_factor=.96, ) noise_level = 0.5 def r(ep): global noise_level, e # agent.render = True for i in range(ep): noise_level *= .995 noise_level = max(1e-3, noise_level) print('ep', i, '/', ep, 'noise_level', noise_level)