I am using https://github.com/anupamchugh/AndroidTfLiteCameraX source code to learn about integrating the TFLite model with Android. I have labels.txt with all the classes in the Assets folder as well.
Currently, this project returns only the prediction class. I want to retrieve the bounding box along with it.
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
}
This is where the classification occurs. I don't think it returns the bounding box information, but I'm not sure. I don't have much knowledge of tflite model. To get the bounding box, do I need to use a different model? What do I do?