【问题标题】:Android: mobilenet_v1_1.0_224.tflite model doesn't return bounding box informationAndroid:mobilenet_v1_1.0_224.tflite 模型不返回边界框信息
【发布时间】:2021-02-12 19:40:43
【问题描述】:

我正在使用https://github.com/anupamchugh/AndroidTfLiteCameraX 源代码来了解如何将 TFLite 模型与 Android 集成。我也有 label.txt 以及 Assets 文件夹中的所有类。

目前,该项目仅返回预测类。我想连同它一起检索边界框。

   private fun getMaxResult(result: FloatArray): Int {
        var probability = result[0]
        var index = 0
        for (i in result.indices) {
            if (probability < result[i]) {
                probability = result[i]
                index = i
            }
        }
        return index
    }


    private fun classify(bitmap: Bitmap): String {

        check(isInitialized) { "TF Lite Interpreter is not initialized yet." }
        val resizedImage =
            Bitmap.createScaledBitmap(bitmap, inputImageWidth, inputImageHeight, true)

        val byteBuffer = convertBitmapToByteBuffer(resizedImage)

        val output = Array(1) { FloatArray(labels.size) }
        val startTime = SystemClock.uptimeMillis()
        interpreter?.run(byteBuffer, output)
        val endTime = SystemClock.uptimeMillis()

        var inferenceTime = endTime - startTime
        var index = getMaxResult(output[0])
        var result = "Prediction is ${labels[index]}\nInference Time ${inferenceTime}\""

        return result
    }

这是分类发生的地方。我认为它不会返回边界框信息,但我不确定。我对tflite 模型了解不多。要获得边界框,我需要使用不同的模型吗?我该怎么办?

【问题讨论】:

    标签: android kotlin classification bounding-box tensorflow-lite


    【解决方案1】:

    您链接的源代码和模型适用于Image Classification not Object Detection。所以没有边界框坐标/信息。

    这是我的 CameraX 和对象检测示例代码https://github.com/FelixAhrens/CameraX-ImageAnalysis-Beta06-Java-TFLite-ObjectDetection

    但它是java。对于 Kotlin,您应该搜索对象检测和 Tensorflow 或者 MLKit 的 explizit(它在某种程度上更容易实现,您也可以使用分类模型进行检测,因为 api 自己搜索图像中的对象。检查 https://developers.google.com/ml-kit/vision/object-detection 和 @ 987654324@ 是一个可能有用的教程。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-16
      • 2013-03-17
      • 2021-10-19
      • 2021-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多