【发布时间】:2021-02-22 15:50:46
【问题描述】:
我有一个在珊瑚 USB 中运行的 tflite 模型,但我也可以在 CPU 中运行(作为在珊瑚 USB 不可用时通过一些测试的替代方法)。
我找到了this very similar question,但给出的答案没有用。
我的代码如下所示:
class CoralObjectDetector(object):
def __init__(self, model_path: str, label_path: str):
"""
CoralObjectDetector, this object allows to pre-process images and perform object detection.
:param model_path: path to the .tflite file with the model
:param label_path: path to the file with labels
"""
self.label_path = label_path
self.model_path = model_path
self.labels = dict() # type: Dict[int, str]
self.load_labels()
self.interpreter = tflite.Interpreter(model_path),
experimental_delegates=[tflite.load_delegate('libedgetpu.so.1')])
# more code and operations
模型和标签从here下载。
我想加载相同模型的替代版本,让我不使用珊瑚 USB 加速器(即仅在 CPU 中)执行。我的目标如下:
class CoralObjectDetector(object):
def __init__(self, model_path: str, label_path: str, run_in_coral: bool):
"""
CoralObjectDetector, this object allows to pre-process images and perform object detection.
:param model_path: path to the .tflite file with the model
:param label_path: path to the file with labels
:param run_in_coral: whether or not to run it on coral (use CPU otherwise)
"""
self.label_path = label_path
self.model_path = model_path
self.labels = dict() # type: Dict[int, str]
self.load_labels()
if run_in_coral:
self.interpreter = tflite.Interpreter(model_path),
experimental_delegates=[tflite.load_delegate('libedgetpu.so.1')])
else:
# I expect somethig like this
self.interpreter = tflite.CPUInterpreter(model_path)
# more code and operations
我不确定在推理/预测方法中是否只需要这个或其他东西。
【问题讨论】:
标签: python google-coral