-
Notifications
You must be signed in to change notification settings - Fork 0
/
inference.py
50 lines (30 loc) · 998 Bytes
/
inference.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
import torch
from dqn_model import DQN, MLP
from utils.gym_dino_run import DinoRunEnv
from utils.extract import get_screen
def infer(env, mlp=False):
action_size = env.action_space.n
if mlp:
policy_net = MLP(num_actions=action_size)
else:
policy_net = DQN()
policy_net.load_state_dict(torch.load('saved_weights/Episode 2078-checkpoint.pth'))
for i in range(3):
env.reset()
state = get_screen(env)
for j in range(200):
action = policy_net(state).max(1)[1].view(1, 1)
env.render()
_, reward, done, _ = env.step(action.item())
state = get_screen(env)
if done:
break
env.close()
if __name__ == '__main__':
# Get chrome dino run game
env = DinoRunEnv()
# initialize browser
init = env.reset()
state, reward, done, info = env.step(0)
# Running Training
infer(env=env)