IncompatibleclassChangeError:找到界面org.tensorflow.lite.tensor,但期望类

发布于 2025-01-30 10:06:23 字数 1656 浏览 4 评论 0原文

error - >错误图片

尝试处理我的模型时有一个错误

“将位图转换为字节布夫的功能和ı尝试处理我的模型,但是我有一个错误,并且无法解决它,您能帮我解决这个问题吗?

错误在此行上是“ Val outputs = model.process(inputfeature0)”

/a> - >您可以单击并查看导致此错误的行


        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函数

       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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白日梦 2025-02-06 10:06:23

就我而言,这与拥有旧版本的支持和元数据API有关。

实现'org.tensorflow:tensorflow-lite-support:0.1.0'
实现'org.tensorflow:TensorFlow-Lite-metadata:0.1.0'

0.1.0更新到0.4.3解决了问题。

通常,当您的运行时类路径与您的编译时类路径不同时,这可能会发生。

In my case, it was related to having an old version of support and metadata apis.

implementation 'org.tensorflow:tensorflow-lite-support:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'

updating from 0.1.0 to 0.4.3 solved the problem.

In general, This could happen when your runtime classpath is different than your compile time classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文