forked from ChintanTrivedi/rl-bot-football
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
29 lines (22 loc) · 883 Bytes
/
test.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
import gfootball.env as football_env
from keras.models import load_model
import numpy as np
import keras.backend as K
import tensorflow as tf
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
env = football_env.create_environment(env_name='academy_empty_goal', representation='simple115', render=True)
n_actions = env.action_space.n
dummy_n = np.zeros((1, 1, n_actions))
dummy_1 = np.zeros((1, 1, 1))
model_actor = load_model('model_actor_3_1.0.hdf5', custom_objects={'loss': 'categorical_hinge'})
state = env.reset()
done = False
while True:
state_input = K.expand_dims(state, 0)
action_probs = model_actor.predict(state_input, steps=1)
action = np.argmax(action_probs)
next_state, _, done, _ = env.step(action)
state = next_state
if done:
state = env.reset()