【发布时间】:2021-03-18 17:57:57
【问题描述】:
我有一个期望输入形状为 (1, 1000, 12) 的 tflite 模型。只是为了测试它,我打算加载一个 CSV 文件并对其进行推理。下面是我的代码和运行它时得到的错误消息的相关部分。
我认为我在正确加载或读取 CSV 文件时出错了。我对 Android 比较陌生,如果能在这件事上提供任何帮助,我将不胜感激!
val testModel = myModel.newInstance(context)
// Creates inputs for reference.
val inputFeature0 = TensorBuffer.createFixedSize(intArrayOf(1, 1000, 12), DataType.FLOAT32)
val openRawResource = resources.openRawResource(R.raw.inputdata).readBytes()
val byteBuffer = ByteBuffer.wrap(openRawResource)
// inputFeature0.loadBuffer(byteBuffer)
inputFeature0.loadBuffer(byteBuffer)
// Runs model inference and gets result.
val outputs = testModel.process(inputFeature0)
val outputFeature0 = outputs.outputFeature0AsTensorBuffer
// Releases model resources if no longer used.
model.close()
Caused by: java.lang.IllegalArgumentException: The size of byte buffer and the shape do not match.
at org.tensorflow.lite.support.common.SupportPreconditions.checkArgument(SupportPreconditions.java:104)
at org.tensorflow.lite.support.tensorbuffer.TensorBuffer.loadBuffer(TensorBuffer.java:296)
at org.tensorflow.lite.support.tensorbuffer.TensorBuffer.loadBuffer(TensorBuffer.java:323)
at com.example.ecgclassifier.MainActivity.analyze(MainActivity.kt:47)
at com.example.ecgclassifier.MainActivity.onCreate(MainActivity.kt:23)
【问题讨论】:
标签: android csv tensorflow kotlin tensorflow-lite