Open mmortazavi opened 4 years ago
Hi! It's a bit late, but I have just faced the same problem trying to replicate the instruction.
I am not a Java programmer, but I have found that the size of the array allocated for imgData
is reduced, but in convertBitmapToByteBuffer()
it is still packing floats into the array.
I have changed the function as shown below and it works now. I am not yet sure whether just replacing the putFloat
to put
(the latter puts byte
s) and just trimming float
s to byte
s in its argument is correct, but solves the main problem.
private void convertBitmapToByteBuffer(Bitmap bitmap) {
if (imgData == null) {
return;
}
imgData.rewind();
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
// Convert the image to floating point.
int pixel = 0;
long startTime = SystemClock.uptimeMillis();
for (int i = 0; i < DIM_IMG_SIZE_X; ++i) {
for (int j = 0; j < DIM_IMG_SIZE_Y; ++j) {
final int val = intValues[pixel++];
imgData.put((byte)((val >> 16) & 0xFF));
imgData.put((byte)((val >> 8) & 0xFF));
imgData.put((byte)((val) & 0xFF));
}
}
long endTime = SystemClock.uptimeMillis();
Log.d(TAG, "Timecost to put values into ByteBuffer: " + Long.toString(endTime - startTime));
}
I have a feeling there is a way of just copying the buffers (or even reusing the Bitmap data array) without looping through x and y.
It is really frustrating to see that the official documentation is not working. I followed the step by step to deploy a TensorFlow Lite model created using AutoML Vision Edge. As usual it works for the provided graph.lite and labels.txt files. However it fails when a custom object detector model exported from AutoML Vision Edge is used. Necessary recommended changes were made. Here is the metadata about the model that was exported from AutoML:
Quantization is there, so the change from INT to Float should be carried out as app uses a float model and I have done those changes as instructed. The gradle were synced and app seems to be built as well. But it crashes momentarily with the following error:
I am not an Android developer, so I am having hard time what causes the crash. I think though that the input image by the camera is not the right input for the model.