Reputation: 21
I just trained a single-label image classification model using Google AutoML, but fail to use it in the Android phone. I modified the code and replaced my custom model into the example TensorFlow model from https://github.com/tensorflow/examples/tree/master/lite/examples/image_classification/android according to https://cloud.google.com/vision/automl/docs/tflite-android-tutorial. However, the app continue to crash and show that it is out of date.
Here are the errors in the 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)
Upvotes: 2
Views: 1055
Reputation: 506
To fix the BufferOverflowException
error you also have to change how you put values in the imgData
buffer.
Since we changed imgData
to contain bytes instead of floats, we also need to replace putFloat
with put
in the method 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));
Upvotes: 2