forked from drozzy/ode_agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_ppo2.py
54 lines (38 loc) · 1.22 KB
/
run_ppo2.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
51
52
53
import gym
import odeworldgym
from stable_baselines.common.policies import MlpPolicy
from stable_baselines.common.vec_env import DummyVecEnv
from stable_baselines import PPO2
from itertools import count
from stable_baselines.common.atari_wrappers import FrameStack
from stable_baselines.common.vec_env import VecFrameStack
import os
env_name = os.environ['ENV']
env = gym.make(env_name)
# env = FrameStack(env, n_frames=3)
env = DummyVecEnv([lambda: env]) # The algorithms require a vectorized environment to run
env = VecFrameStack(env, n_stack=3)
model = PPO2.load(env_name)
# model = PPO2(CnnPolicy, env, verbose=1, tensorboard_log="./ppo_tensorboard/")
obs = env.reset()
done = False
r_total = 0.0
for i in count():
action, _states = model.predict(obs)
print(action)
obs, [reward], [done], info = env.step(action)
print(reward)
r_total += reward
env.render(mode='full')
if done:
print("Game over. Total Reward: {}".format(r_total))
r_total = 0.0
print("Enter:")
print("ENTER to quit.")
print("C to continue.")
press = input('>> ')
if press != "C":
break
print("HERE")
obs = env.reset()
env.close()