-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaze_load_model.py
More file actions
50 lines (41 loc) · 1.3 KB
/
Copy pathmaze_load_model.py
File metadata and controls
50 lines (41 loc) · 1.3 KB
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
import os
from mazeenv2 import MazeEnv2
import time
from datetime import datetime
import numpy as np
# Following lines of code taken from website
now = datetime.now()
print("now =", now)
# dd/mm/YY H:M:S
dt_string = now.strftime("%b-%d-%Y-%H-%M")
# Original code:
## models_dir = f"models/{int(time.time())}/"
## logdir = f"logs/{int(time.time())}" + "_" + dt_string + "/"
# New code to run the model with "id" 1704253737:
models_dir = f"models/1704253737_3/40000.zip"
logdir = f"logs/1704253737_3 Test/"
# Checks to see if the paths exist, otherwise makes the path
#region
if not os.path.exists(models_dir):
os.makedirs(models_dir)
if not os.path.exists(logdir):
os.makedirs(logdir)
#endregion
env = MazeEnv2()
env.reset()
# Changed this so it can load thing. Originally was:
# model = PPO('MlpPolicy', env, verbose=1, tensorboard_log=logdir)
model = PPO.load(models_dir, env=env)
# This below has changed too, but I'm not too sure what it actually does.
episodes = 5
for ep in range(episodes):
obs, info = env.reset()
print(obs)
done = False
while not done:
# for some reason obs has to be a numpy
action, _states = model.predict(obs)
obs, rewards, done, end_early, info = env.step(action)
# env.render()
print(rewards)