-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
50 lines (30 loc) · 1.24 KB
/
test.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
47
48
49
50
from stable_baselines3 import PPO #PPO
from TrafficEnv import SpeedLimitEnv
import time
import os
from stable_baselines3.common.vec_env import VecNormalize, DummyVecEnv
from stable_baselines3.common.monitor import Monitor
from stable_baselines3.common.evaluation import evaluate_policy
run = '1714040559-autobahn'
logdir = f"logs/{run}/evaluation/"
if not os.path.exists(logdir):
os.makedirs(logdir)
def simulation_loop():
env= SpeedLimitEnv(visuals=True)
env = Monitor(env, logdir)
env = DummyVecEnv([lambda: env])
env = VecNormalize(env)
env.training = False
env.norm_reward = False
model = PPO.load(f"F:/SUMO/OptimalEmission-SUMO-ReinforcementLearning/logs/{run}/rl_model_42500_steps.zip", env=env, print_system_info=True)
mean_reward, std_reward = evaluate_policy(model, model.get_env(), n_eval_episodes=30)
# ==============================================================================
# -- main() --------------------------------------------------------------------
# ==============================================================================
def main():
try:
simulation_loop()
except KeyboardInterrupt:
print('\nCancelled by user. Bye!')
if __name__ == '__main__':
main()