1 year ago

#388130

test-img

Ayush Singh

Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:0) with 10368 bytes to a Java Buffer with 324 bytes

I'm trying to make a handwritten text recognition android application on android studio. I converted my model into tensorflow lite and then uploaded that file in my application. Below Im sharing the code for the same... There are many log statements in the code. to check till where it is getting executed.

    public void classifyImage(Bitmap image){
        try {

            Ocr mdl = Ocr.newInstance(getApplicationContext());
            TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 128, 32, 1}, DataType.FLOAT32);
            ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4*128*32*1);

            int[] intValues = new int[128 * imageSize];
            image.getPixels(intValues, 0, image.getWidth(), 0, 0, image.getWidth(), image.getHeight());
            Log.d("TAG Model", " get pixels ");
            int pixel = 0;

            for (int i=0; i<4096; i++){
                int val = intValues[pixel++];
                byteBuffer.putFloat(val);
            }
            Log.d("TAG Model", " bytebuffer putfloat com ");

            inputFeature0.loadBuffer(byteBuffer);

            Ocr.Outputs outputs = mdl.process(inputFeature0);
            Log.d("TAG Model", " Model process ");
            TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
            Log.d("TAG Model", " Model output");

            float[] confidences = outputFeature0.getFloatArray();
            mdl.close();
        } catch (Exception e) {
            // TODO Handle the exception
            Log.d("TAG Model", "classifyImage: "+e.getMessage());
        }
    }

On running my application Im getting an error : D/TAG Model: classifyImage: Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:0) with 10368 bytes to a Java Buffer with 324 bytes.

screenshot of the error

Can you please help we with this, as i'm struck on this error and cannot proceed further.

android-studio

tensorflow

tensorflow-lite

bytebuffer

text-recognition

0 Answers

Your Answer

Accepted video resources