mirror of
https://github.com/jcreek/Sarpy.git
synced 2026-07-13 03:03:43 +00:00
feat(*): Add a working agent that loads the trained model
This commit is contained in:
+11
-14
@@ -1,20 +1,17 @@
|
|||||||
import os
|
import os
|
||||||
|
from stable_baselines3 import PPO
|
||||||
|
|
||||||
|
models_dir = "../../models/PPO-rl"
|
||||||
|
|
||||||
|
|
||||||
class Agent:
|
class Agent:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# If you need to load your model from a file this is the time to do it
|
# Get the directory of agent.py
|
||||||
# You can do something like:
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
#
|
|
||||||
# self.actor = # your Model
|
|
||||||
#
|
|
||||||
# cur_dir = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
# with open(os.path.join(cur_dir, 'model.p'), 'rb') as file:
|
|
||||||
# model = pickle.load(file)
|
|
||||||
# self.actor.load_state_dict(model)
|
|
||||||
pass
|
|
||||||
|
|
||||||
def act(self, state):
|
model_path = os.path.join(script_dir, "../../models/PPO-rl/280000.zip")
|
||||||
# Evaluate your model here
|
self.model = PPO.load(model_path)
|
||||||
action = [1, 0, 0, 0, 0, 0, 0, 0]
|
|
||||||
return action
|
def act(self, obs):
|
||||||
|
action, _ = self.model.predict(obs)
|
||||||
|
return action.tolist()
|
||||||
|
|||||||
Reference in New Issue
Block a user