I have a flutter code to integrate with tflite. I’m sure that I’ve added my model in assests.
Future<void> performAudioDetection(List<List<double>> audioData) async {
InterpreterOptions options = InterpreterOptions();
options.threads=0;
final interpreter = await Interpreter.fromAsset('models/cry tflite models/cnn_with_trans_model_1.tflite', options: options);
print(interpreter);
final batchSize = 1; // Assuming a batch size of 1
final timeSteps = audioData.length; // Number of time steps (frames)
final numFeatures = audioData.first.length; // Number of features per frame
final input = audioData.expand((frame) => frame).toList(); // Flatten the input data
List<dynamic> inputList = [input];
var inputTensor = interpreter.getInputTensor(0);
print('Input shape: ${inputTensor.shape}');
inputList=inputList.reshape([32,16,8,1]);
final output = [inputList];// Adjust output shape for binary classification
print(output.shape);
// Run inference
interpreter.runForMultipleInputs(output.cast<Object>(), {0: output}); // Pass input data as a list
// Extract the output values (assuming two output values)
final detectionResults = [output[0][0]].map((value) => value[0][0].toDouble()).toList();
print(detectionResults);
}
Output:
Initialized TensorFlow Lite runtime.
I/flutter (15078): Instance of 'Interpreter'
I/flutter (15078): Input shape: [1, 16, 8, 1]
W/com.example.ap(15078): Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (unsupported, reflection, allowed)
I/flutter (15078): [1, 32, 16, 8, 1]
W/libc (15078): Access denied finding property "ro.hardware.chipname"
F/libc (15078): Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 15138 (1.ui), pid 15078 (com.example.app)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'Redmi/sunny_in/sunny:12/SKQ1.210908.001/V14.0.5.0.SKGINXM:user/release-keys'
Revision: '0'
ABI: 'arm64'
Timestamp: 2024-05-05 16:00:34.915786943+0530
Process uptime: 0s
Cmdline: com.example.app
pid: 15078, tid: 15138, name: 1.ui >>> com.example.app <<<
uid: 10444
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
x0 0000000000000000 x1 0000000000003b22 x2 0000000000000006 x3 0000007945334500
x4 b40000791f051c80 x5 b40000791f051c80 x6 b40000791f051c80 x7 0000000200000004
x8 00000000000000f0 x9 677eec34c4a7b777 x10 0000000000000000 x11 ffffff80fffffbdf
x12 0000000000000001 x13 0000000200000004 x14 0000000000000080 x15 0000000000000004
x16 0000007a65b26d30 x17 0000007a65b00870 x18 0000007944f68000 x19 0000000000003ae6
x20 0000000000003b22 x21 00000000ffffffff x22 0000007945336000 x23 00000079453348f8
x24 0000007945336000 x25 b40000792d927100 x26 0000000000000098 x27 0000000000000070
x28 0000000000004b40 x29 0000007945334580
lr 0000007a65ab0c1c sp 00000079453344e0 pc 0000007a65ab0c48 pst 0000000000000000
backtrace:
#00 pc 000000000008bc48 /apex/com.android.runtime/lib64/bionic/libc.so (abort+168) (BuildId: e1f31041be009cf8613d6678cdccd160)
#01 pc 000000000011dc60 /data/app/~~8fOZw8yJdQcMSjchfOYTOA==/com.example.app-7i4nH-RT5c2FHkSDj1ZcrQ==/base.apk!libtensorflowlite_jni.so
#02 pc 00000000001d9b8c /data/app/~~8fOZw8yJdQcMSjchfOYTOA==/com.example.app-7i4nH-RT5c2FHkSDj1ZcrQ==/base.apk!libtensorflowlite_jni.so
#03 pc 00000000001debf8 /data/app/~~8fOZw8yJdQcMSjchfOYTOA==/com.example.app-7i4nH-RT5c2FHkSDj1ZcrQ==/base.apk!libtensorflowlite_jni.so
#04 pc 00000000001d9498 /data/app/~~8fOZw8yJdQcMSjchfOYTOA==/com.example.app-7i4nH-RT5c2FHkSDj1ZcrQ==/base.apk!libtensorflowlite_jni.so
#05 pc 00000000002f81b8 /data/app/~~8fOZw8yJdQcMSjchfOYTOA==/com.example.app-7i4nH-RT5c2FHkSDj1ZcrQ==/base.apk!libtensorflowlite_jni.so
#06 pc 00000000002f7ba0 /data/app/~~8fOZw8yJdQcMSjchfOYTOA==/com.example.app-7i4nH-RT5c2FHkSDj1ZcrQ==/base.apk!libtensorflowlite_jni.so
#07 pc 00000000002e5584 /data/app/~~8fOZw8yJdQcMSjchfOYTOA==/com.example.app-7i4nH-RT5c2FHkSDj1ZcrQ==/base.apk!libtensorflowlite_jni.so
#08 pc 0000000000007bc4 [anon:dart-code]
Lost connection to device.
My Build.gradle in app:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation "org.tensorflow:tensorflow-lite:2.4.0"
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0-rc2'
implementation('org.tensorflow:tensorflow-lite:0.0.0-nightly') { changing = true }
implementation('org.tensorflow:tensorflow-lite-select-tf-ops:0.0.0-nightly') { changing = true }
}
android {
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
minifyEnabled false
shrinkResources false
}
}
}
My app crashes when tflite model runs. I tried executing this code in multiple devices. I ran on physical device rather than emulator. Still the same crash persists
I tried solutions of various SO questions and Git issues. But nothing worked for me.
Kindly help