当我通过运行决定手的模型时,我在决定手的过程中会遇到缓慢的工作!更准确地说,它是interpreter.invoke()帧速率从40急剧下降到4!如何将帧率提高到20或25?
# ...
# Called before the loop
def start(self):
self._interpreter = tf.lite.Interpreter(model_path = path_to_model)
self._interpreter.allocate_tensors()
self._input_details = self._interpreter.get_input_details()
self._output_details = self._interpreter.get_output_details()
# ...
# Called in a loop
def generate(self, img):
if img.size == 0:
return False
img_resize = cv2.resize(img, (256, 256))
img_resize_expanded = np.expand_dims(img_resize, axis = 0)
image_np_expanded = (np.float32(img_resize_expanded) - 0) / 255
self._interpreter.set_tensor(self._input_details[0]['index'], image_np_expanded)
self._interpreter.invoke() # Slow !!!!!!!!!!!!!!!!!!!!!!
output_data = self._interpreter.get_tensor(self._output_details[0]['index'])
return output_data发布于 2019-09-14 00:20:09
更多的信息将使这一问题更容易得到回应:
1)你是在桌面还是手机上运行这个程序?TFLite是针对移动设备进行优化的(例如,对arm进行了优化),支持在桌面上快速运行(例如x86)仍在进行中。
2) MediaPipe在Android上运行时很可能使用GPU委托API。看看tensorflow.org. on /lite文档中的GPU运行情况。看看他们利用了哪些加速器,并找到了如何在上面的文档中启用它。如果它们在CPU上运行并使用量化,这是值得研究的问题。
https://stackoverflow.com/questions/57866547
复制相似问题