我正在开发一个 Android 应用程序,该应用程序使用经过训练的 TensorFlow Lite 模型执行分类。模型已使用 getModelByteBuffer 函数加载,输入特征正在使用加载的模型进行分类。但是,当我尝试使用加载的模型初始化 TensorFlow Lite 解释器时,应用程序崩溃了。执行此代码时,应用程序崩溃,没有特定的错误消息。我试过在网上寻找解决方案,但我一直找不到任何有效的方法。
任何人都可以帮助我确定应用程序崩溃的原因并提出可能的解决方案吗?对于一个 uni 项目,如果你们中的任何人能帮助我,我将非常感激谢谢。
我在初始化解释器后写的日志没有显示所以我认为问题就在那里 这是相关的代码片段:
private fun classification(uid: String) {
val password = findViewById<EditText>(R.id.passET)
val mdw = moyenne(dwelltime)
val mft2= moyenne(flight_time2)
val mft3= moyenne(flight_time3)
val Moyenne = arrayListOf(mdw,mft2,mft3)
Log.d("tflite", "interpreter before initilizing ")
tflite = Interpreter(getModelByteBuffer())
Log.d("tflite", "interpreter afterinitilizing ")
try {
val input = getInputTensor(Moyenne)
val output = Array(1) { LongArray(NUM_CLASSES) }
tflite?.run(input, output)
// Get predicted class index
val predictedClassIndex = output[0].indices.maxByOrNull { output[0][it] } ?: -1
val predictedClassName = getClassNames()[predictedClassIndex]
store.collection("users").document(uid).get().addOnSuccessListener {user->
val nom = user.getString("nom")
if (predictedClassName == nom){
startActivity(Intent(this, Activity_expert::class.java))
}else{
password.error = "Try Again"
password.text = null
tentative++
onResume()
if (tentative==3){
store.collection("users").document(uid).update("blacklist",true)
warning.blacklist(uid)
val builder = AlertDialog.Builder(this)
builder.setMessage("you are blocked !!!")
builder.setNeutralButton("ok",{ dialogInterface: DialogInterface, i: Int ->
finish()
})
builder.show()
}
warning.dynamic(nom, predictedClassName, algo!!)
}
}
} catch (e: Exception) {
e.printStackTrace()
Log.d("tflite", "error")
Log.e("tflite", "Exception caught: ${e.message}")
}
我尝试在 gradle 应用程序文件中升级我的 tensorflow lite depedencies 但没有运气