【问题标题】:Standard TFlite object detection model not working in MLKit标准 TFlite 对象检测模型在 MLKit 中不起作用
【发布时间】:2021-01-09 19:45:24
【问题描述】:

如果我在 MLKit 中使用 Pre-Trained TFLite Object detection model,我会收到以下错误:

 CalculatorGraph::Run() failed in Run: 
    Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unexpected number of dimensions for output index 0: got 3D, expected either 2D (BxN with B=1) or 4D (BxHxWxN with B=1, W=1, H=1).

知道我可能做错了什么吗?

【问题讨论】:

    标签: tensorflow tensorflow-lite google-mlkit


    【解决方案1】:

    ML Kit 目前还不支持自定义对象检测模型。 ML Kit 目前只允许开发人员使用自定义图像分类模型。此处列出了与 ML Kit 兼容的所有 TFLite 模型:

    https://tfhub.dev/ml-kit/collections/image-classification/1

    如果你想做物体检测,可以试试ML Kit的物体检测API:https://developers.google.com/ml-kit/vision/object-detection

    如果你想使用自定义对象检测模型,可以试试 TFLite 任务库:

    https://www.tensorflow.org/lite/inference_with_metadata/task_library/overview.

    【讨论】:

    【解决方案2】:

    好吧,因为我是通过这篇关于 SO 的帖子发现的,所以我继续寻找其他选择。 此处发布的教程:Tensor Flow Lite OBJ detection 做得很好。

    首先添加

    implementation 'org.tensorflow:tensorflow-lite-task-vision:0.2.0'
    

    构建.gradle,这个简单的代码就像一个魅力。显然,我必须进行一些更改以反映我的特定需求,但它的检测没有错误。

    val image = TensorImage.fromBitmap(bitmap)
    val options = ObjectDetector.ObjectDetectorOptions.builder()
        .setMaxResults(5)
        .setScoreThreshold(0.5f)
        .build()
    val detector = ObjectDetector.createFromFileAndOptions(
        this, // the application context
        "model.tflite", // must be same as the filename in assets folder
        options
    )
    

    该链接中给出了更深入的解释,这里就不多说了。 希望这对其他人有帮助。

    【讨论】:

      猜你喜欢
      • 2020-10-17
      • 2018-05-04
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-19
      • 2021-01-15
      • 2020-10-18
      相关资源
      最近更新 更多