你好,我有这个tensorflow函数的问题,它最初是在flutter写的,如果有人谁做了一段时间的Tensorflow可以帮我翻译原始函数,因为我的实现糟透了lol:(.
fun getCount(interpreter: Interpreter): Int {
val strides = listOf(1, 2, 3, 4)
for (stride in strides) {
val numBatches = 1
for (batchNum in 0 until numBatches) {
val inputShape = interpreter.getInputTensor(0).shape()
val inputType = interpreter.getInputTensor(0).dataType()
val outputShape = interpreter.getOutputTensor(0).shape()
Log.d("Output tensor",outputShape.get(0).toString())
val rawScores : Any = emptyArray<Any>()
val withinPeriodScores : Any = emptyArray<Any>()
val periodScores : Any = emptyArray<Any>()
val outputBuffer = TensorBuffer.createFixedSize(,DataType.FLOAT32)
val inShape2 = interpreter.getInputTensor(0).shape()
val inType2 = interpreter.getInputTensor(0).dataType()
val inputBuffer = TensorBuffer.createFixedSize(inShape2, inType2)
interpreter.run(inputBuffer, outputBuffer)
Log.d("Output buffer", outputBuffer.toString())
}
}
return 0;
}
谢谢你的帮助,我很感激。
1条答案
按热度按时间sdnqo3pr1#
如果向run方法传递错误类型的值,则会发生此错误。您不能传递TensorBufferFloat,而需要传递ByteBuffer。
试着换一条线
interpreter.run输入缓冲区、输出缓冲区)
至
interpreter.run输入缓冲区.获取缓冲区(),输出缓冲区.获取缓冲区())