我刚刚使用Google AutoML训练了单标签图像分类模型,但是无法在Android手机中使用它。我修改了代码,并根据https://github.com/tensorflow/examples/tree/master/lite/examples/image_classification/android将我的自定义模型替换为https://cloud.google.com/vision/automl/docs/tflite-android-tutorial中的示例TensorFlow模型。但是,该应用程序继续崩溃,并显示它已过时。
以下是logcat中的错误:
8472-8483/? E/flitecameradem: Unable to peek into adb socket due to error. Closing socket.: Connection reset by peer
8472-8472/android.example.com.tflitecamerademo E/libc: Access denied finding property "vendor.camera.aux.packagelist"
8472-8472/android.example.com.tflitecamerademo E/libc: Access denied finding property "vendor.camera.aux.packagelist"
8472-8472/android.example.com.tflitecamerademo E/libc: Access denied finding property "vendor.camera.aux.packagelist"
8472-8496/android.example.com.tflitecamerademo E/libc: Access denied finding property "vendor.camera.aux.packagelist"
8472-8472/android.example.com.tflitecamerademo E/libc: Access denied finding property "persist.vendor.camera.privapp.list"
8472-8714/android.example.com.tflitecamerademo E/libc: Access denied finding property "vendor.camera.hal1.packagelist"
8472-8496/android.example.com.tflitecamerademo E/libc: Access denied finding property "vendor.camera.aux.packagelist"
8472-8496/android.example.com.tflitecamerademo E/libc: Access denied finding property "vendor.camera.aux.packagelist"
8472-8472/android.example.com.tflitecamerademo E/libc: Access denied finding property "vendor.camera.aux.packagelist"
8472-8762/android.example.com.tflitecamerademo E/libc: Access denied finding property "persist.camera.legacy_perf"
8472-8713/android.example.com.tflitecamerademo E/AndroidRuntime: FATAL EXCEPTION: CameraBackground
Process: android.example.com.tflitecamerademo, PID: 8472
java.nio.BufferOverflowException
at java.nio.Buffer.nextPutIndex(Buffer.java:542)
at java.nio.DirectByteBuffer.putFloat(DirectByteBuffer.java:802)
at com.example.android.tflitecamerademo.ImageClassifier.convertBitmapToByteBuffer(ImageClassifier.java:195)
at com.example.android.tflitecamerademo.ImageClassifier.classifyFrame(ImageClassifier.java:113)
at com.example.android.tflitecamerademo.Camera2BasicFragment.classifyFrame(Camera2BasicFragment.java:663)
at com.example.android.tflitecamerademo.Camera2BasicFragment.access$900(Camera2BasicFragment.java:69)
at com.example.android.tflitecamerademo.Camera2BasicFragment$5.run(Camera2BasicFragment.java:558)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:224)
at android.os.HandlerThread.run(HandlerThread.java:65)
答案 0 :(得分:2)
要解决BufferOverflowException
错误,您还必须更改将值放入imgData
缓冲区的方式。
由于我们将imgData
更改为包含字节而不是浮点数,因此我们还需要在方法putFloat
中将put
替换为convertBitmapToByteBuffer(Bitmap bitmap)
:
imgData.put((byte) ((((val >> 16) & 0xFF)-IMAGE_MEAN)/IMAGE_STD));
imgData.put((byte) ((((val >> 8) & 0xFF)-IMAGE_MEAN)/IMAGE_STD));
imgData.put((byte) ((((val) & 0xFF)-IMAGE_MEAN)/IMAGE_STD));