Android: mobilenet_v1_1.0_224.tflite 模型没有 return 边界框信息
Android: mobilenet_v1_1.0_224.tflite model doesn't return bounding box information
我正在使用 https://github.com/anupamchugh/AndroidTfLiteCameraX 源代码来了解如何将 TFLite 模型与 Android 集成。我还有 labels.txt 以及 Assets
文件夹中的所有 classes。
目前,这个项目returns只有预测class。我想连同它一起检索边界框。
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
}
这是 class化发生的地方。我不认为它 returns 边界框信息,但我不确定。我对 tflite
模型了解不多。要获取边界框,我是否需要使用不同的模型?我该怎么办?
您链接的源代码和模型适用于 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 and here 是一个可能有用的教程)。
我正在使用 https://github.com/anupamchugh/AndroidTfLiteCameraX 源代码来了解如何将 TFLite 模型与 Android 集成。我还有 labels.txt 以及 Assets
文件夹中的所有 classes。
目前,这个项目returns只有预测class。我想连同它一起检索边界框。
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
}
这是 class化发生的地方。我不认为它 returns 边界框信息,但我不确定。我对 tflite
模型了解不多。要获取边界框,我是否需要使用不同的模型?我该怎么办?
您链接的源代码和模型适用于 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 and here 是一个可能有用的教程)。