-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_test.py
39 lines (33 loc) · 1.27 KB
/
model_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
36
37
38
39
import picamera
import numpy as np
import io
import time
from edgetpu.detection.engine import DetectionEngine
from edgetpu.utils import dataset_utils
# https://coral.ai/docs/reference/edgetpu.detection.engine/
# engine = DetectionEngine('/home/pi/k9-assistant/model.tflite')
def main():
with picamera.PiCamera() as camera:
camera.resolution = (640, 480)
camera.framerate = 30
# _, height, width, _ = engine.get_input_tensor_shape()
height = 224
width = 224
camera.start_preview()
try:
stream = io.BytesIO()
for _ in camera.capture_continuous(
stream, format='rgb', use_video_port=True, resize=(width, height)):
stream.truncate()
stream.seek(0)
input_tensor = np.frombuffer(stream.getvalue(), dtype=np.uint8)
start_ms = time.time()
# results = engine.classify_with_input_tensor(input_tensor, top_k=1)
elapsed_ms = time.time() - start_ms
#if results:
# camera.annotate_text = '%s %.2f\n%.2fms' % (
# labels[results[0][0]], results[0][1], elapsed_ms * 1000.0)
finally:
camera.stop_preview()
if __name__ == '__main__':
main()