为什么我从 Interpreter 输出的 tensorflow lite 模型在 Android Studio 中不正确,而在 Python 中是正确的?

问题描述 投票:0回答:0

在 python 中,我运行以下代码并加载保存的 TFLite 模型并在其中一个输出上使用 0.95 正确解释:

interpreter = tf.lite.Interpreter(model_path=model.tflite)
classify_lite = interpreter.get_signature_runner('serving_default')
predictions_lite = classify_lite(sequential_1_input=img_array)['outputs']
score_lite = tf.nn.softmax(predictions_lite)

然后我复制该 tflite 模型并将其按原样粘贴到 Android Studio 中的资产中。然后我运行以下代码尝试在 Android 中复制 python 结果:

val i = Interpreter(loadModelFile("model.tflite") )
val inputs:MutableMap<String, Any>  =  HashMap()
inputs.put   ("sequential_1_input",byteBuffer)
val outputs:MutableMap<String, Any>  = HashMap()
outputs["outputs"] = outputArray
i.runSignature(inputs, outputs)

对于输出,我看到这个数组:[-1.6981508,3.1327155,-0.36703405,-1.129016,-2.947296] 它不包含我在 python 中对同一模型的推断所看到的 ~0.95 值。似乎要在 Android 中使用它还有一个额外的步骤。有人知道那一步吗?

如上所示。看到 python 的数组 [~0, ~0, ~0, 0.95, ~0] 。在 Android Studio 上看到 [-1.6981508,3.1327155,-0.36703405,-1.129016,-2.947296]

python android kotlin tensorflow-lite image-classification
© www.soinside.com 2019 - 2024. All rights reserved.