def setUp(self): """setUp""" self.params = load_params("params/test_params.json") # environment without normalization: self.params["env"]["normalize"] = False self.env = gym.make(self.params["env"]["name"], params=self.params) # environment with normaluzation: self.params["env"]["normalize"] = True self.env_norm = gym.make(self.params["env"]["name"], params=self.params)
def setUp(self): """setup""" self.params = load_params('params/test_params.json') self.env = gym.make(self.params["env"]["name"], params=self.params) self.test_env = gym.make(self.params["env"]["name"], params=self.params) self.policy = DDPG(env=self.env, params=self.params) self.cae = CAE(pooling='max', latent_dim=16, input_shape=(32, 32), conv_filters=[4, 8, 16]) self.cae.build(input_shape=(1, 32, 32, 1)) self.cae.load_weights(filepath='../models/cae/model_num_5_size_8.h5')
import sys import glob import shutil import numpy as np import tensorflow as tf import gym import gym_pointrobo from hwr.agents.pointrobo_ddpg import DDPG from hwr.cae.cae import CAE from hwr.training.pointrobot_trainer import PointrobotTrainer from hwr.utils import load_params, get_random_params, export_params # loading params: params = load_params('params/hyperparam_tuning_params.json') # deleting the previous runs logs: logdir_files = glob.glob(os.path.join('results', 'hyperparam_tuning')) for f in logdir_files: if os.path.isdir(f): shutil.rmtree(f) else: os.remove(f) for run in range(params["hyper_tuning"]["num_of_runs"]): # getting random hyperparams according to the ranges and placing them into params. params = get_random_params(params) # setting up logdir for the current hyperparams:
import numpy as np import tensorflow as tf import glob import json import shutil import gym import gym_pointrobo from hwr.agents.pointrobo_ddpg import DDPG from hwr.cae.cae import CAE from hwr.training.pointrobot_trainer import PointrobotTrainer from hwr.utils import load_params, set_up_benchmark_params # loading the params: params = load_params('params/benchmark_trainings_empty.json') benchmark_keys = params["benchmark"].keys() # deleting the previous runs logs: logdir_files = glob.glob(os.path.join(params["trainer"]["logdir"], "*")) for f in logdir_files: if os.path.isdir(f): shutil.rmtree(f) else: os.remove(f) for key in benchmark_keys: # loading original params: params = load_params('params/benchmark_trainings_empty.json') # setting up training run:
import numpy as np import tensorflow as tf import glob import json import shutil import gym import gym_pointrobo from hwr.agents.pointrobo_ddpg import DDPG from hwr.cae.cae import CAE from hwr.training.pointrobot_trainer import PointrobotTrainer from hwr.utils import load_params, set_up_benchmark_params # loading the params: params = load_params('params/benchmark_evaluations.json') benchmark_keys = params["benchmark"].keys() for key in benchmark_keys: print('------ Evaluation {} -------'.format(key)) # loading original params: params = load_params('params/benchmark_evaluations.json') # setting up training run: params = set_up_benchmark_params(params, key) params["trainer"]["logdir"] = os.path.join(params["trainer"]["logdir"], key) #Initialize the environment env = gym.make( params["env"]["name"],
num_of_cases = 100 for _ in range(num_of_cases): _, goal_pos_norm, agent_pos_norm = self.env_norm.reset() # assertions: self.assertTrue( np.isclose(rescale(goal_pos_norm, self.env_norm.pos_bounds), self.env_norm.goal_pos, atol=1e-6).all()) self.assertTrue( np.isclose(rescale(agent_pos_norm, self.env_norm.pos_bounds), self.env_norm.agent_pos, atol=1e-6).all()) if __name__ == '__main__': params = load_params("params/test_params.json") params["env"]["grid_size"] = 20 params["env"]["goal_reward"] = -0.01 params["env"]["collision_reward"] = -1 params["env"]["step_reward"] = -0.01 params["env"]["max_goal_dist"] = 5 test_pointrobot_gym_goal(params) test_pointrobot_gym_obstacle(params) test_pointrobot_gym_boundaries(params) print('All tests have run successfully!') unittest.main()
import os import sys import numpy as np import tensorflow as tf import glob import gym import gym_pointrobo from hwr.agents.pointrobo_ddpg import DDPG from hwr.cae.cae import CAE from hwr.training.pointrobot_trainer import PointrobotTrainer from hwr.utils import load_params # loading params: params = load_params('params/pointrobot_training_params.json') if params["trainer"]["train_from_scratch"] and \ params["trainer"]["mode"] == "train": # deleting the previous checkpoints: ckp_files = glob.glob(os.path.join(params["trainer"]["model_dir"], '*')) for f in ckp_files: os.remove(f) #Initialize the environment env = gym.make( params["env"]["name"], params=params, ) test_env = gym.make(params["env"]["name"], params=params)