-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
35 lines (29 loc) · 849 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
30
31
32
33
34
35
import numpy as np
import requests
from keras.models import load_model
from watch_gst_stream import watch_stream
model = load_model('trained.h5')
url = 'http://192.168.1.120:5000/run/'
def predict(image_arr):
image_arr = np.expand_dims(image_arr, axis=0)
preds = model.predict(image_arr)
drive = np.argmax(preds[0])
if drive == 0:
requests.get(url + 'back')
elif drive == 1:
requests.get(url + 'stop_drive')
elif drive == 2:
requests.get(url + 'go')
else:
raise ValueError()
steer = np.argmax(preds[1])
if steer == 0:
requests.get(url + 'left')
elif steer == 1:
requests.get(url + 'stop_turn')
elif steer == 2:
requests.get(url + 'right')
else:
raise ValueError()
print(drive, steer)
watch_stream(predict, fps=10, n_frames=-1)