1

I'm creating my first ML Android App. But I got this error

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

This is the code that I run on android studio.

 predictBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            try {
                Yolov4Tiny416 model = Yolov4Tiny416.newInstance(MainActivity.this);

                // Creates inputs for reference.
                TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 416, 416, 3}, DataType.FLOAT32);

                bitmap = Bitmap.createScaledBitmap(bitmap,416,416,true);

                inputFeature0.loadBuffer(TensorImage.fromBitmap(bitmap).getBuffer());

                // Runs model inference and gets result.
                Yolov4Tiny416.Outputs outputs = model.process(inputFeature0);
                TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
                TensorBuffer outputFeature1 = outputs.getOutputFeature1AsTensorBuffer();

                result.setText(getmax(outputFeature0.getFloatArray())+"");

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

        }

I looked in to other answers for the same question. But nothing worked. What can be the problem and the solution for this?

desertnaut
  • 57,590
  • 26
  • 140
  • 166

0 Answers0