Android:mobilenet_v1_1.0_224.tflite模型未返回边界框信息

问题描述

我正在使用https://github.com/anupamchugh/AndroidTfLiteCameraX代码来学习有关将TFLite模型与Android集成的信息。我在Assets文件夹中也包含了所有类的labels.txt。

当前,该项目仅返回预测类。我想同时检索边界框。

   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模型不了解。要获取边界框,是否需要使用其他模型?我该怎么办?

解决方法

您链接的源代码和模型用于PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL:)。因此没有边界框协调/信息。

这是我的CameraX和对象检测Image Classification not Object Detection

的示例代码

但这是java。对于Kotlin,您应该搜索用于对象检测和Tensorflow或MLKit的漏洞利用程序(以某种方式更容易实现,也可以使用分类模型进行检测,因为api可以自行搜索图像中的对象。请检查https://github.com/FelixAhrens/CameraX-ImageAnalysis-Beta06-Java-TFLite-ObjectDetection https://developers.google.com/ml-kit/vision/object-detection是一个教程,可能会有所帮助。)