-
Notifications
You must be signed in to change notification settings - Fork 5
/
ppo_RL_pretrained.py
37 lines (29 loc) · 1.05 KB
/
ppo_RL_pretrained.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
#based on stable baselines implementation https://stable-baselines.readthedocs.io/en/master/modules/ppo2.html
import gym
from stable_baselines.common.policies import MlpPolicy
from stable_baselines import PPO2
from stable_baselines.common.policies import MlpPolicy
from stable_baselines.common.vec_env import DummyVecEnv
from gym.envs.registration import registry, register, make, spec
#registering custom environment
register(
id='RocketLander-v0',
entry_point='rocketlander.rocket_lander:RocketLander',#gym.envs.box2d:
max_episode_steps=1000,
reward_threshold=0,
)
# Create and wrap the environment
env = gym.make('RocketLander-v0')
env = gym.wrappers.Monitor(env, "./video", force=True)
env = DummyVecEnv([lambda: env])
# Load the trained agent
#ppo2_RocketLander-v0_20000000_2019-05-05 03/26/38.pkl
model = PPO2.load("./model/ppo2_RocketLander_15000000.pkl")
#Trained agent in action
obs = env.reset()
while True:
action, _states = model.predict(obs)
obs, rewards, dones, info = env.step(action)
env.render()
if dones:
break