-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathagent_load.py
44 lines (34 loc) · 1.12 KB
/
agent_load.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
# Import required libraries
import gym_tanks
import gymnasium as gym
from stable_baselines3 import PPO
from multiprocessing import freeze_support
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
if __name__ == "__main__":
# Avoid multiprocessing issues
freeze_support()
# Load and reset the environment
env = gym.make('gym_tanks/tanks-v0')
env.reset()
TIMESTEPS = 10000
# Set the models folder and path
models_dir = "models/PPO/Test_Bot"
model_path = f"{models_dir}/model_2064384_steps.zip" # Put here the weights file you want to read
# Load the model
model = PPO.load(model_path, env = env, n_steps = TIMESTEPS)
# Vectorize the environment
env = model.get_env()
episodes = 10
for ep in range(episodes):
obs = env.reset()
done = False
while not done:
# Render the environment
env.render()
# Predict the action
action, _state = model.predict(obs, deterministic = False)
# Step the environment
obs, reward, done, info = env.step(action)
print(reward)
env.close()