-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_model.py
76 lines (65 loc) · 1.86 KB
/
test_model.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import numpy as np
import tensorflow as ts
from screen import screen_cap
import win32gui, win32ui, win32con, win32api
import cv2
import time
import keyboard as kb
from data import data_prog
from tqdm import tqdm
from key_worker import drive_worker
from screen import screen_cap
from model import cnn_model
WIDTH = 480
HEIGHT = 270
GAME_WIDTH = 800
GAME_HEIGHT = 600
#(left, top, res, res)
size=(0,40,GAME_WIDTH, GAME_HEIGHT)
LR = 0.01
MODEL_NAME = 'Pete_600gb_0_001'
model = cnn_model.googlenet(WIDTH, HEIGHT, 3, LR, output=8)
model.load('model_data/'+MODEL_NAME)
def main():
agent = drive_worker()
#agent.steering_acc="forward"
while True:
img = cv2.resize(screen_cap.grab_frame(size), (WIDTH,HEIGHT))
model_prediction = model.predict([img.reshape(WIDTH, HEIGHT, 3)])[0]
pred = np.array(model_prediction, dtype=float)
#0: W
#1: WA
#2: WD
#3: S
#4: SA
#5: SD
#6: A
#7: D
print(pred)
choice = np.argmax(pred)
if choice == 0:
agent.steering_acc="forward"
print('forward')
if choice == 1:
agent.steering_acc="forward_left"
print('forward_left')
if choice == 2:
agent.steering_acc="forward_right"
print('forward_right')
if choice == 3:
agent.steering_acc="backwards"
print('backwards')
if choice == 4:
agent.steering_acc="backwards_left"
print('backwards_left')
if choice == 5:
agent.steering_acc="backwards_right"
print('backwards_right')
if choice == 6:
agent.steering_acc="forward_left"
print('forward_left')
if choice == 7:
agent.steering_acc="forward_right"
print('forward_right')
if __name__ == "__main__":
main()