首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Python运行tensorflow-lite手动检测模型

通过Python运行tensorflow-lite手动检测模型
EN

Stack Overflow用户
提问于 2019-09-10 08:10:12
回答 1查看 876关注 0票数 1

当我通过运行决定手的模型时,我在决定手的过程中会遇到缓慢的工作!更准确地说,它是interpreter.invoke()帧速率从40急剧下降到4!如何将帧率提高到20或25?

代码语言:javascript
复制
    # ...

    # 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
EN

回答 1

Stack Overflow用户

发布于 2019-09-14 00:20:09

更多的信息将使这一问题更容易得到回应:

1)你是在桌面还是手机上运行这个程序?TFLite是针对移动设备进行优化的(例如,对arm进行了优化),支持在桌面上快速运行(例如x86)仍在进行中。

2) MediaPipe在Android上运行时很可能使用GPU委托API。看看tensorflow.org. on /lite文档中的GPU运行情况。看看他们利用了哪些加速器,并找到了如何在上面的文档中启用它。如果它们在CPU上运行并使用量化,这是值得研究的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57866547

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档