我已经从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());
答案 0 :(得分:0)
这是因为您的INPUT_SHAPE / INPUT_DATA与模型的INPUT_SHAPE / INPUT DATA不同。以本机顺序将输入数据转换为ByteBuffer,其形状和大小与输入模型的方式完全相同。