Skip to content

Commit ac2c49a

Browse files
NamburgerNam Vupre-commit-ci[bot]glenn-jocher
authored
Handle edgetpu model inference (#5372)
* Handle edgetpu model inference * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Cleanup Rename `tflite_runtime.interpreter as tflite` to `tflite_runtime.interpreter as tflri` to avoid conflict with existing `tflite` boolean Co-authored-by: Nam Vu <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Glenn Jocher <[email protected]>
1 parent 5866646 commit ac2c49a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

detect.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import argparse
1010
import os
11+
import platform
1112
import sys
1213
from pathlib import Path
1314

@@ -107,7 +108,14 @@ def wrap_frozen_graph(gd, inputs, outputs):
107108
elif saved_model:
108109
model = tf.keras.models.load_model(w)
109110
elif tflite:
110-
interpreter = tf.lite.Interpreter(model_path=w) # load TFLite model
111+
if "edgetpu" in w: # https://www.tensorflow.org/lite/guide/python#install_tensorflow_lite_for_python
112+
import tflite_runtime.interpreter as tflri
113+
delegate = {'Linux': 'libedgetpu.so.1', # install libedgetpu https://coral.ai/software/#edgetpu-runtime
114+
'Darwin': 'libedgetpu.1.dylib',
115+
'Windows': 'edgetpu.dll'}[platform.system()]
116+
interpreter = tflri.Interpreter(model_path=w, experimental_delegates=[tflri.load_delegate(delegate)])
117+
else:
118+
interpreter = tf.lite.Interpreter(model_path=w) # load TFLite model
111119
interpreter.allocate_tensors() # allocate
112120
input_details = interpreter.get_input_details() # inputs
113121
output_details = interpreter.get_output_details() # outputs

0 commit comments

Comments
 (0)