首页 > 解决方案 > tflite颤动中detectObjectOnImage和runModelonImage的区别

问题描述

我正在尝试在颤动中制作一个 tflite 多对象检测器,我遇到了两个以图像路径作为输入的函数,这就是这个问题的原因。

这两个函数是detectObjectOnImagerunModelOnImage当我使用runModelOnImage我的代码时,我的代码正在运行,如果我将它与解释器交换detectObjectOnImage确实会初始化,但在调用该函数时,应用程序会自动关闭并显示Lost connection to device

这就是我的代码的运行方式

classifyImage(String imgpath) async {
    var output = await Tflite.runModelOnImage(
        path: imgpath,
        imageMean: 0.0,
        imageStd: 255.0,
        threshold: 0.2,
        numResults: 1,
        asynch: true,
    );
    setState(() {
      _loading = false;
      outputs = output;
    });
    print(outputs);
    print(outputs[0]["label"]);
  }

我想我的假设是正确的,但我不知道为什么它不起作用,除了我从谷歌的 Teachable machine 创建了一个模型,它一次只检测一个对象,所以我的下一个问题是如何让它检测到更多超过 1 个对象

谢谢

标签: flutteradbtensorflow-lite

解决方案


这两个函数的区别在于它们的用法:

对于对象检测,您使用 Tflite.detectObjectOnImage()

对于图像分类(查找对象周围没有打印框),您使用 Tflite.runModelOnImage()

这两种方法返回不同大小的张量。当张量无法映射到预期输出时,应用程序将按照您的描述断开连接。


关于你的第二个问题:

您将限制结果数量的参数 numResults 设置为 1。增加此数字以获得更多结果。(来源:https ://pub.dev/packages/tflite#Example )


推荐阅读