-
Notifications
You must be signed in to change notification settings - Fork 0
/
td3_baseline_demo.py
48 lines (43 loc) · 1.72 KB
/
td3_baseline_demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from main_TD3 import *
seeds = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50]
seed = seed[0]
env = RandomMiniEnv
env_param = EnvParams(iteration_timeout=250,
goal_ang_dist=np.pi/8,
goal_spat_dist=1,
robot_name=StandardRobotExamples.INDUSTRIAL_TRICYCLE_V1)
env = EgocentricCostmap(env(params=env_param,
turn_off_obstacles=False,
draw_new_turn_on_reset=False,
seed=seed))
env = bc_gym_wrapper(env, normalize=True)
state_dim = env.observation_space.shape[0]
action_dim = env.action_space.shape[0]
max_action = float(env.action_space.high[0])
PATH = "./models/TD3_RandomMiniEnv_0_actor"
evaluation_model = Actor(state_dim, action_dim, max_action)
evaluation_model.load_state_dict(torch.load(PATH, map_location='cpu'))
for seed in seeds:
env = RandomMiniEnv
env_param = EnvParams(iteration_timeout=250,
goal_ang_dist=np.pi/8,
goal_spat_dist=1,
robot_name=StandardRobotExamples.INDUSTRIAL_TRICYCLE_V1)
env = EgocentricCostmap(env(params=env_param,
turn_off_obstacles=False,
draw_new_turn_on_reset=False,
seed=seed))
env = bc_gym_wrapper(env, normalize=True)
prev_state = None
state = env.reset()
env.render()
done = False
while not done:
if done:
state = env.reset()
done = False
action = evaluation_model(torch.FloatTensor(state)).detach().numpy()
next_state, r, done, _ = env.step(action)
prev_state = state
state = next_state
env.render()