don't fallback to the CPU

fixes #381
This commit is contained in:
Blake Blackshear 2021-01-15 22:43:42 -06:00
parent d1d833ea9a
commit 46c002038b

View File

@ -62,16 +62,15 @@ class LocalObjectDetector(ObjectDetector):
logger.info(f"Attempting to load TPU as {device_config['device']}") logger.info(f"Attempting to load TPU as {device_config['device']}")
edge_tpu_delegate = load_delegate('libedgetpu.so.1.0', device_config) edge_tpu_delegate = load_delegate('libedgetpu.so.1.0', device_config)
logger.info("TPU found") logger.info("TPU found")
self.interpreter = tflite.Interpreter(
model_path='/edgetpu_model.tflite',
experimental_delegates=[edge_tpu_delegate])
except ValueError: except ValueError:
logger.info("No EdgeTPU detected. Falling back to CPU.") logger.info("No EdgeTPU detected.")
raise
if edge_tpu_delegate is None:
self.interpreter = tflite.Interpreter(
model_path='/cpu_model.tflite', num_threads=num_threads)
else: else:
self.interpreter = tflite.Interpreter( self.interpreter = tflite.Interpreter(
model_path='/edgetpu_model.tflite', model_path='/cpu_model.tflite', num_threads=num_threads)
experimental_delegates=[edge_tpu_delegate])
self.interpreter.allocate_tensors() self.interpreter.allocate_tensors()