flutter_tflite icon indicating copy to clipboard operation
flutter_tflite copied to clipboard

Attempt to invoke virtual method 'int java.util.Vector.size()' on a null object reference

Open LuginiAndrea opened this issue 3 years ago • 3 comments

Hello, I sent a tf lite model I made to my frontend developer, who's using your flutter package. We get the picture from the camera and we ran the data through the code you provided: Uint8List imageToByteListFloat32( img.Image image, int inputSize, double mean, double std) { var convertedBytes = Float32List(1 * inputSize * inputSize * 3); var buffer = Float32List.view(convertedBytes.buffer); int pixelIndex = 0; for (var i = 0; i < inputSize; i++) { for (var j = 0; j < inputSize; j++) { var pixel = image.getPixel(j, i); buffer[pixelIndex++] = (img.getRed(pixel) - mean) / std; buffer[pixelIndex++] = (img.getGreen(pixel) - mean) / std; buffer[pixelIndex++] = (img.getBlue(pixel) - mean) / std; } } return convertedBytes.buffer.asUint8List(); } and then into the method runModelOnBinary(). Here, we get the error I wrote in the title, and we have no idea what's causing it. Do you may know the answer?

LuginiAndrea avatar Jul 03 '22 22:07 LuginiAndrea

Facing the same but with runModelOnFrame method. The package was last updated 15 moths ago and very less support is given here. Do we have any other option to use Tflite in flutter

IronHeartDan avatar Jul 17 '22 20:07 IronHeartDan

Hello, I sent a tf lite model I made to my frontend developer, who's using your flutter package. We get the picture from the camera and we ran the data through the code you provided: Uint8List imageToByteListFloat32( img.Image image, int inputSize, double mean, double std) { var convertedBytes = Float32List(1 * inputSize * inputSize * 3); var buffer = Float32List.view(convertedBytes.buffer); int pixelIndex = 0; for (var i = 0; i < inputSize; i++) { for (var j = 0; j < inputSize; j++) { var pixel = image.getPixel(j, i); buffer[pixelIndex++] = (img.getRed(pixel) - mean) / std; buffer[pixelIndex++] = (img.getGreen(pixel) - mean) / std; buffer[pixelIndex++] = (img.getBlue(pixel) - mean) / std; } } return convertedBytes.buffer.asUint8List(); } and then into the method runModelOnBinary(). Here, we get the error I wrote in the title, and we have no idea what's causing it. Do you may know the answer?

I solved this problem, it seems it is mandatory to pass labels while loading the model and boom it works

IronHeartDan avatar Jul 18 '22 10:07 IronHeartDan

@IronHeartDan @LuginiAndrea Am facing same issue in Gesture Classification in flutter and am using loadModel(model:"Model_path") without any label file So what you think this will cause error for me ava.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.Vector.size()' on a null object reference

vikas-shrma avatar Dec 20 '22 14:12 vikas-shrma