IncompatibleclassChangeError:找到界面org.tensorflow.lite.tensor,但期望类
error - >错误图片
尝试处理我的模型时有一个错误
“将位图转换为字节布夫的功能和ı尝试处理我的模型,但是我有一个错误,并且无法解决它,您能帮我解决这个问题吗?
错误在此行上是“ Val outputs = model.process(inputfeature0)”
val byteBuffer = convertBitmapToByteBuffer(bitmap)
byteBuffer!!.rewind()
bitmap.copyPixelsToBuffer(byteBuffer)
val inputFeature0 =
TensorBuffer.createFixedSize(intArrayOf(1, 224, 224, 3), DataType.FLOAT32)
inputFeature0.loadBuffer(byteBuffer)
val outputs = model.process(inputFeature0)
val outputFeature0 = outputs.outputFeature0AsTensorBuffer
val byteBuffer =
ByteBuffer.allocateDirect( 4 * 1 * 224 * 224 * 3)
byteBuffer.order(ByteOrder.nativeOrder())
val intValues = IntArray(224 * 224 )
bitmap.getPixels(intValues, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
var pixel = 0
for (i in 0 until 224) {
for (j in 0 until 224) {
val `val` = intValues[pixel++]
byteBuffer.putFloat(((`val` shr 16 and 0xFF) - 1) / 255.0f)
byteBuffer.putFloat(((`val` shr 8 and 0xFF) - 1) / 255.0f)
byteBuffer.putFloat(((`val` and 0xFF) - 1) / 255.0f)
}
}
return byteBuffer
}
error --> error picture
When ı try to process my model ı have an error " java.lang.IncompatibleClassChangeError: Found interface org.tensorflow.lite.Tensor, but class was expected"
I have a mobilenet tflite model which is I trained, and I created a function to convert bitmap to bytebuffe and ı try to process my model but ı had this error and ı can't solve it, can you help me to solve this ?
the error is on this line "val outputs = model.process(inputFeature0)"
a part of outputgenerator func code --> you can click and see the line which causes this error
val byteBuffer = convertBitmapToByteBuffer(bitmap)
byteBuffer!!.rewind()
bitmap.copyPixelsToBuffer(byteBuffer)
val inputFeature0 =
TensorBuffer.createFixedSize(intArrayOf(1, 224, 224, 3), DataType.FLOAT32)
inputFeature0.loadBuffer(byteBuffer)
val outputs = model.process(inputFeature0)
val outputFeature0 = outputs.outputFeature0AsTensorBuffer
convertBitmapToByteBuffer function
val byteBuffer =
ByteBuffer.allocateDirect( 4 * 1 * 224 * 224 * 3)
byteBuffer.order(ByteOrder.nativeOrder())
val intValues = IntArray(224 * 224 )
bitmap.getPixels(intValues, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
var pixel = 0
for (i in 0 until 224) {
for (j in 0 until 224) {
val `val` = intValues[pixel++]
byteBuffer.putFloat(((`val` shr 16 and 0xFF) - 1) / 255.0f)
byteBuffer.putFloat(((`val` shr 8 and 0xFF) - 1) / 255.0f)
byteBuffer.putFloat(((`val` and 0xFF) - 1) / 255.0f)
}
}
return byteBuffer
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就我而言,这与拥有旧版本的支持和元数据API有关。
从
0.1.0
更新到0.4.3
解决了问题。通常,当您的运行时类路径与您的编译时类路径不同时,这可能会发生。
In my case, it was related to having an old version of support and metadata apis.
updating from
0.1.0
to0.4.3
solved the problem.In general, This could happen when your runtime classpath is different than your compile time classpath.