-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.py
More file actions
30 lines (22 loc) · 726 Bytes
/
render.py
File metadata and controls
30 lines (22 loc) · 726 Bytes
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
''' To test out the DQN implementation by rendering the environment.
'''
from keras.models import model_from_json
import numpy as np
import gym
json_file = open('./ModelFiles/model.json', 'r')
model_json = json_file.read()
json_file.close()
model = model_from_json(model_json)
model.load_weights('./ModelFiles/model.h5')
env = gym.envs.make('CartPole-v1')
def test_run(env, model):
''' Testing the model on the environment with a greedy policy function.
'''
state = env.reset()
done = False
while not done:
env.render()
action = np.argmax(model.predict(state.reshape(1, -1))[0])
next_state, reward, done, _ = env.step(action)
state = next_state
test_run(env, model)