You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I have this problem when I'm trying to use the sample code on my image. Here is the code I have.
Future<bool> _imageIsApproved(File croppedImage) async {
FirebaseModelInterpreter interpreter =FirebaseModelInterpreter.instance;
FirebaseModelManager manager =FirebaseModelManager.instance;
manager.registerLocalModelSource(
FirebaseLocalModelSource(
modelName:'model', assetFilePath:'assets/model.tflite'),
);
Uint8List imageBytes =await_readFileByte(croppedImage.path);
img.Image image = img.decodeJpg(imageBytes);
image = img.copyResize(image, width:224, height:224);
//The app will download the remote model. While the remote model is being downloaded, it will use the local model.var results =await interpreter.run(
localModelName:"model",
inputOutputOptions:FirebaseModelInputOutputOptions([
FirebaseModelIOOption(FirebaseModelDataType.FLOAT32, [1, 224, 224, 3])
], [
FirebaseModelIOOption(FirebaseModelDataType.FLOAT32, [1, 1001])
]),
inputBytes:imageToByteList(image),
);
returnfalse;
}
//float modelUint8ListimageToByteList(img.Image image) {
var _inputSize =224;
var convertedBytes =Float32List(4* _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(i, j);
buffer[pixelIndex] = ((pixel >>16) &0xFF) /255;
pixelIndex +=1;
buffer[pixelIndex] = ((pixel >>8) &0xFF) /255;
pixelIndex +=1;
buffer[pixelIndex] = ((pixel) &0xFF) /255;
pixelIndex +=1;
}
}
return convertedBytes.buffer.asUint8List();
}
Future<Uint8List> _readFileByte(String filePath) async {
try {
Uri myUri =Uri.parse(filePath);
File imageFile =newFile.fromUri(myUri);
final fileAsByte =await imageFile.readAsBytes();
returnUint8List.fromList(fileAsByte);
} catch (e) {
print('Exception Error while reading audio from path:'+ e.toString());
returnnull;
}
}
When intercepter.run() is trying to execute I get this error.
W/System.err(10717): Caused by: java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite buffer with 150528 bytes and a Java Buffer with 602112 bytes.
W/System.err(10717): at org.tensorflow.lite.Tensor.throwIfShapeIsIncompatible(Tensor.java:402)
W/System.err(10717): at org.tensorflow.lite.Tensor.throwIfDataIsIncompatible(Tensor.java:369)
W/System.err(10717): at org.tensorflow.lite.Tensor.setTo(Tensor.java:187)
W/System.err(10717): at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:150)
W/System.err(10717): at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:314)
W/System.err(10717): at com.google.android.gms.internal.firebase_ml.zzpz.runForMultipleInputsOutputs(Unknown Source:4)
W/System.err(10717): at com.google.android.gms.internal.firebase_ml.zzpr.zza(Unknown Source:85)
W/System.err(10717): at com.google.android.gms.internal.firebase_ml.zzpr.zza(Unknown Source:125)
W/System.err(10717): at com.google.android.gms.internal.firebase_ml.zznt.call(Unknown Source:4)
W/System.err(10717): at com.google.android.gms.internal.firebase_ml.zznn.zza(Unknown Source:30)
W/System.err(10717): ... 6 more
Am I doing something wrong. I researched about this issue in flutter but didn't get any answers.
The text was updated successfully, but these errors were encountered:
Hello, I have this problem when I'm trying to use the sample code on my image. Here is the code I have.
When
intercepter.run()
is trying to execute I get this error.Am I doing something wrong. I researched about this issue in flutter but didn't get any answers.
The text was updated successfully, but these errors were encountered: