java.lang.IllegalStateException: Internal error: Unexpected failure when preparing tensor allocations: tensorflow/lite/kernels/pad.cc:79 SizeOfDimension(op_context->paddings, 0) != op_context->dims (4 != 1) Node number 0 (PAD) failed to prepare. at org.tensorflow.lite.NativeInterpreterWrapper.allocateTensors(Native Method) at org.tensorflow.lite.NativeInterpreterWrapper.allocateTensorsIfNeeded(NativeInterpreterWrapper.java:308) at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:248) at org.tensorflow.lite.InterpreterImpl.runForMultipleInputsOutputs(InterpreterImpl.java:101) at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:77) at org.tensorflow.lite.InterpreterImpl.run(InterpreterImpl.java:94) at org.tensorflow.lite.Interpreter.run(Interpreter.java:77) at com.example.appleleafdiseasedetection.DiseaseDetector$2.onClick(DiseaseDetector.java:72) at android.view.View.performClick(View.java:7743) at android.view.View.performClickInternal(View.java:7720) at android.view.View.access$3700(View.java:854) at android.view.View$PerformClick.run(View.java:29111) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:210) at android.os.Looper.loop(Looper.java:299) at android.app.ActivityThread.main(ActivityThread.java:8309) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1038)
private float[] preprocessImage(Bitmap image) { // Convert the image to a float array or apply any necessary transformations // Assuming the model expects a specific input shape [1, 224, 224] int inputWidth = 224; int inputHeight = 224; Bitmap resizedImage = Bitmap.createScaledBitmap(image, inputWidth, inputHeight, true); // Convert the resized image to a float array int[] intValues = new int[inputWidth * inputHeight]; float[] floatValues = new float[1 * inputWidth * inputHeight]; resizedImage.getPixels(intValues, 0, inputWidth, 0, 0, inputWidth, inputHeight); for (int i = 0; i < intValues.length; i++) { final int val = intValues[i]; floatValues[i] = ((val >> 16) & 0xFF) / 255.0f; // Red component } return floatValues; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)