-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpi_demo.py
33 lines (26 loc) · 861 Bytes
/
pi_demo.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
import subprocess
from PIL import Image
import numpy as np
import tensorflow as tf
import cv2
import time
interpreter = tf.lite.Interpreter(model_path='/home/pi/the_tflite.tflite')
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
input_shape = input_details[0]['shape']
while True:
subprocess.call("fswebcam -D 0.01 --no-banner --quiet img.jpeg", shell=True)
img = Image.open("img.jpeg")
input_data = np.expand_dims(np.array(img.resize((224, 224)), dtype=np.float32), 0)
interpreter.set_tensor(input_details[0]['index'], input_data)
toc = time.time()
interpreter.invoke()
tic = time.time()
the_time = tic - toc
output_data = interpreter.get_tensor(output_details[0]['index'])
answer = np.argmax(output_data)
if output == 1:
print('one')
else:
print('five')