-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
test-setup.py
36 lines (29 loc) · 1020 Bytes
/
test-setup.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
import os
import pathlib
from pycoral.utils import edgetpu
from pycoral.utils import dataset
from pycoral.adapters import common
from pycoral.adapters import classify
from PIL import Image
model_file = os.path.join(
"models", "ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite"
)
print(os.path.isfile(model_file))
label_file = os.path.join("models", "coco_labels.txt")
print(os.path.isfile(label_file))
image_file = os.path.join("images", "parrot.jpg")
print(os.path.isfile(image_file))
# Initialize the TF interpreter
interpreter = edgetpu.make_interpreter(model_file)
interpreter.allocate_tensors()
# Resize the image
size = common.input_size(interpreter)
image = Image.open(image_file).convert("RGB").resize(size, Image.ANTIALIAS)
# Run an inference
common.set_input(interpreter, image)
interpreter.invoke()
classes = classify.get_classes(interpreter, top_k=1)
# Print the result
labels = dataset.read_label_file(label_file)
for c in classes:
print("%s: %.5f" % (labels.get(c.id, c.id), c.score))