-
Notifications
You must be signed in to change notification settings - Fork 4
/
CIFAR10_Inference_EdgeTPU.py
41 lines (30 loc) · 1.09 KB
/
CIFAR10_Inference_EdgeTPU.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
import argparse
import io
import time
from datetime import datetime
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from edgetpu.classification.engine import ClassificationEngine
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
'--model', help='File path of Tflite model.', required=True)
parser.add_argument(
'--image', help='File path of file.', required=True)
args = parser.parse_args()
label_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
img = Image.open(args.image)
#np_image = np.array(img)
# Load Engine
engine = ClassificationEngine(args.model)
lap_time = time.time()
# Run inference.
for result in engine.ClassifyWithImage(img, top_k=3):
print ('---------------------------')
print (label_names[result[0]])
print ('Score : ', result[1])
previous_time = lap_time
lap_time = time.time()
print("Elapsed time for the last inference: ", lap_time - previous_time)
if __name__ == '__main__':
main()