"The size of byte buffer and the shape do not match" erro in android studio with TensorFlow lite model

31 views Asked by At

I have tensorflow lite modell for image classification. So I was importing that model to android studio for image classification.

So while I'm running the code below runtime error occurred,

java.lang.IllegalArgumentException: The size of byte buffer and the shape do not match.

After long periods of trubelshoting I suspect erro may be in below code snipet in my main activity file.

`predictBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View View) {

           try {
               TfliteModelAnother model = TfliteModelAnother.newInstance(MainActivity.this);

               // Creates inputs for reference.
               TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 256, 256, 3}, DataType.FLOAT32);
               bitmap = Bitmap.createScaledBitmap(bitmap, 256,256, true);
               inputFeature0.loadBuffer(TensorImage.fromBitmap(bitmap).getBuffer());

               // Runs model inference and gets result.
               TfliteModelAnother.Outputs outputs = model.process(inputFeature0);
               TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
               result.setText(labels[getMax(outputFeature0.getFloatArray())]+"");


               // Releases model resources if no longer used.
               model.close();
           } catch (IOException e) {
               // TODO Handle the exception
           }`  

I am new to machine learning so I'm stuck on here. Please assist regarding this matter. Thank you...

0

There are 0 answers