android - 不同的 .tflite 文件和 .txt 文件用于在 App 中实现 tensorflow
问题描述
我从 MLKit 创建了 .tflite 文件并在张量应用程序中使用,但应用程序崩溃并出现以下错误。
java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite buffer with 150528 bytes and a ByteBuffer with 786432 bytes.
at org.tensorflow.lite.Tensor.throwIfShapeIsIncompatible(Tensor.java:281)
at org.tensorflow.lite.Tensor.throwIfDataIsIncompatible(Tensor.java:258)
at org.tensorflow.lite.Tensor.setTo(Tensor.java:119)
at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:167)
at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:275)
at org.tensorflow.lite.examples.detection.tflite.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:193)
at org.tensorflow.lite.examples.detection.DetectorActivity$2.run(DetectorActivity.java:181)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)
以下是 tensorFlow App 的代码。
if (isQuantized) {
numBytesPerChannel = 1; // Quantized
} else {
numBytesPerChannel = 4; // Floating point
}
d.imgData = ByteBuffer.allocateDirect(1 * d.inputSize * d.inputSize * 3 * numBytesPerChannel);
d.imgData.order(ByteOrder.nativeOrder());
解决方案
这是因为您的 INPUT_SHAPE/INPUT_DATA 与模型的 INPUT_SHAPE/INPUT DATA 不同。以本机顺序将输入数据转换为 ByteBuffer,并具有确切的形状和大小,模型正在接受输入。
推荐阅读
- reactjs - 在反应中渲染选定的对象字段
- regex - 使用 htaccess 从 url 中删除查询字符串
- python - 如何使用时尚 MNIST 数据集进行逻辑回归
- javascript - GMT uncaughtException:无法读取未定义节点 js 的属性“发送”
- oracle - 如何在 Oracle SQL Developer 中删除 SQL 历史记录?
- windows - AutoHotKey :: 功能键无法正常工作
- python - 如何在 matplotlib 中为交互式绘图的 onclick(event) 函数创建类?
- java - scala-maven-plugin 在提到时无法找到源目录
- java - 使用 Safari 浏览器使用 Selenium 进行自动化测试
- python - 将 Python 类实例保存为 Maya 场景对象