Skip to content

Commit

Permalink
Handle edgetpu model inference (#5372)
Browse files Browse the repository at this point in the history
* 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 <nam@glodonusa.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
  • Loading branch information
4 people committed Nov 4, 2021
1 parent 5866646 commit ac2c49a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import argparse
import os
import platform
import sys
from pathlib import Path

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

0 comments on commit ac2c49a

Please sign in to comment.