I was doing my android project. Basically the user enters a text and the model predicts whether it is offensive or not. This was done by training a deep learning model LSTM on python. Then I deployed it to the cloud (Firebase). And downloaded it in my android phone and created an interpreter from the remote model if it's been downloaded. Now when I try to run the application, the model gets downloaded from the cloud but it gives an error. PFA screenshot of the error message. Let me know what am I am doing wrong and why such an error occurred?
This is the log I get when I run the application,
$ adb shell am start -n "com.example.fyp_screens/com.example.fyp_screens.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 32675 on device 'infinix-infinix_hot_4_pro-02576117BM001236'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/skia: SkJpegCodec::onGetPixels +
D/skia: SkJpegCodec::onGetPixels -
I/art: Enter while loop.
I/art: Enter while loop.
I/art: Enter while loop.
I/art: Enter while loop.
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView@c10efc6[]
D/WindowClient: Add to mViews: DecorView@c10efc6[MainActivity], this = android.view.WindowManagerGlobal@94c3ad1
D/OpenGLRenderer: Dumper init 2 threads <0x74c0298880>
<com.example.fyp_screens> is running.
D/OpenGLRenderer: CanvasContext() 0x74c4eda000
D/GraphicBuffer: register, handle(0x74c0305540) (w:896 h:1024 s:896 f:0x1 u:0x000100)
D/ViewRootImpl[MainActivity]: hardware acceleration is enabled, this = ViewRoot{e06e936 com.example.fyp_screens/com.example.fyp_screens.MainActivity,ident = 0}
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = ViewRoot{e06e936 com.example.fyp_screens/com.example.fyp_screens.MainActivity,ident = 0}, this = DecorView@c10efc6[MainActivity]
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = ViewRoot{e06e936 com.example.fyp_screens/com.example.fyp_screens.MainActivity,ident = 0}, this = DecorView@c10efc6[MainActivity]
D/statusbar color: isDarkStatusBar======false
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView@a5f9058[]
D/WindowClient: Add to mViews: DecorView@a5f9058[HomeScreen], this = android.view.WindowManagerGlobal@94c3ad1
D/OpenGLRenderer: CanvasContext() 0x74c4edd800
D/ViewRootImpl[HomeScreen]: hardware acceleration is enabled, this = ViewRoot{592f1d7 com.example.fyp_screens/com.example.fyp_screens.HomeScreen,ident = 1}
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = ViewRoot{592f1d7 com.example.fyp_screens/com.example.fyp_screens.HomeScreen,ident = 1}, this = DecorView@a5f9058[HomeScreen]
D/Surface: Surface::allocateBuffers(this=0x74cb854e00)
D/OpenGLRenderer: CanvasContext() 0x74c4edd800 initialize window=0x74cb854e00, title=com.example.fyp_screens/com.example.fyp_screens.HomeScreen
I/OpenGLRenderer: Initialized EGL, version 1.4
D/OpenGLRenderer: Swap behavior 1
D/OpenGLRenderer: Created EGL context (0x74c4eb1280)
D/OpenGLRenderer: ProgramCache.init: enable enhancement 1
I/OpenGLRenderer: Get disable program binary service property (0)
Initializing program atlas...
I/ProgramBinary/Service: ProgramBinaryService client side disable debugging.
ProgramBinaryService client side disable binary content debugging.
D/ProgramBinary/Service: BpProgramBinaryService.getReady
D/ProgramBinary/Service: BpProgramBinaryService.getProgramBinaryData
I/OpenGLRenderer: Program binary detail: Binary length is 182828, program map length is 124.
I/OpenGLRenderer: Succeeded to mmap program binaries. File descriptor is 66, and path is /dev/ashmem.
No need to use file discriptor anymore, close fd(66).
D/OpenGLRenderer: Initializing program cache from 0x0, size = -1
D/MALI: eglCreateImageKHR:513: [Crop] 0 0 896 1024 img[896 1024]
D/Surface: Surface::connect(this=0x74cb854e00,api=1)
W/libEGL: [ANDROID_RECORDABLE] format: 1
D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
D/OpenGLRenderer: CacheTexture 5 upload: x, y, width height = 0, 0, 109, 388
ProgramCache.generateProgram: 0
D/GraphicBuffer: register, handle(0x74afeb0680) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
D/OpenGLRenderer: ProgramCache.generateProgram: 1
D/OpenGLRenderer: ProgramCache.generateProgram: 34359738368
D/OpenGLRenderer: ProgramCache.generateProgram: 5242944
D/OpenGLRenderer: ProgramCache.generateProgram: 34359738371
D/OpenGLRenderer: ProgramCache.generateProgram: 240518168576
D/OpenGLRenderer: ProgramCache.generateProgram: 68719476736
D/GraphicBuffer: register, handle(0x74affbbd40) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
V/InputMethodManager: onWindowFocus: androidx.appcompat.widget.AppCompatEditText{e3bbf6 VFED..CL. .F....ID 60,364-660,455 #7f07003d app:id/editText} softInputMode=288 first=true flags=#81810100
I/Choreographer: Skipped 58 frames! The application may be doing too much work on its main thread.
D/GraphicBuffer: register, handle(0x74affbc940) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
D/ContentValues: Created a Custom Image Classifier.
D/ContentValues: Configured input & output data for the custom image classifier.
D/statusbar color: isDarkStatusBar======false
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = null, this = DecorView@d37e0bb[]
D/WindowClient: Add to mViews: DecorView@d37e0bb[result1], this = android.view.WindowManagerGlobal@94c3ad1
D/OpenGLRenderer: CanvasContext() 0x74c4ee1000
D/ViewRootImpl[result1]: hardware acceleration is enabled, this = ViewRoot{251037f com.example.fyp_screens/com.example.fyp_screens.result1,ident = 2}
V/PhoneWindow: DecorView setVisiblity: visibility = 0, Parent = ViewRoot{251037f com.example.fyp_screens/com.example.fyp_screens.result1,ident = 2}, this = DecorView@d37e0bb[result1]
D/OpenGLRenderer: CanvasContext() 0x74c4ee1000 initialize window=0x74cb855c00, title=com.example.fyp_screens/com.example.fyp_screens.result1
D/Surface: Surface::allocateBuffers(this=0x74cb855c00)
D/Surface: Surface::connect(this=0x74cb855c00,api=1)
W/libEGL: [ANDROID_RECORDABLE] format: 1
D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000
D/OpenGLRenderer: CacheTexture 5 upload: x, y, width height = 0, 0, 176, 452
D/GraphicBuffer: register, handle(0x74affdc440) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
D/OpenGLRenderer: ProgramCache.generateProgram: 8899172237312
D/OpenGLRenderer: ProgramCache.generateProgram: 8830452760576
D/OpenGLRenderer: ProgramCache.generateProgram: 8796093022211
D/OpenGLRenderer: ProgramCache.generateProgram: 8830452760579
I/art: Enter while loop.
I/art: Do partial code cache collection, code=15KB, data=25KB
I/art: After code cache collection, code=15KB, data=25KB
Increasing code cache capacity to 128KB
D/GraphicBuffer: register, handle(0x74c4e16980) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
V/InputMethodManager: onWindowFocus: null softInputMode=288 first=true flags=#81810100
D/GraphicBuffer: register, handle(0x74af4a7cc0) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
W/IInputConnectionWrapper: finishComposingText on inactive InputConnection
D/Surface: Surface::disconnect(this=0x74cb854e00,api=1)
D/GraphicBuffer: unregister, handle(0x74affbbd40) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
unregister, handle(0x74affbc940) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
D/GraphicBuffer: unregister, handle(0x74afeb0680) (w:720 h:1280 s:720 f:0x1 u:0x000b00)
D/Surface: Surface::disconnect(this=0x74cb854e00,api=1)
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
V/PhoneWindow: DecorView setVisiblity: visibility = 4, Parent = ViewRoot{592f1d7 com.example.fyp_screens/com.example.fyp_screens.HomeScreen,ident = 1}, this = DecorView@a5f9058[HomeScreen]
D/libc-netbsd: getaddrinfo: mlkit.googleapis.com get result from proxy gai_error = 0
I/System.out: [socket][0] connection mlkit.googleapis.com/172.217.19.170:443;LocalPort=-1(2000)
D/: [Posix_connect Debug]Process com.example.fyp_screens :443
I/System.out: [socket][/192.168.1.5:55721] connected
D/NativeCrypto: ssl=0x74c4e52480 NativeCrypto_SSL_do_handshake fd=0x74b1903a28 shc=0x74b1903a2c timeout_millis=0 client_mode=1 npn=0x0
D/NativeCrypto: ssl=0x74c4e52480 info_callback calling handshakeCompleted
D/NativeCrypto: ssl=0x74c4e52480 cert_verify_callback => 1
D/NativeCrypto: ssl=0x74c4e52480 NativeCrypto_SSL_get_certificate => NULL
I/System.out: [OkHttp] sendRequest>>
I/System.out: [OkHttp] sendRequest<<
D/NativeCrypto: ssl=0x74c4e52480 info_callback calling handshakeCompleted
I/ModelDownloadManager: Didn't schedule download for the updated model
E/ContentValues: succed to build FirebaseModelInterpreter.
I/art: Enter while loop.
I/tflite: Initialized TensorFlow Lite runtime.
***A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x70 in tid 349 (FirebaseMLHandl)***
This is the code for lstm-classifier,
public lstmClassifier(final Context context) throws FirebaseMLException {
final FirebaseCustomRemoteModel remoteModel =
new FirebaseCustomRemoteModel.Builder("offense-detector").build();
final FirebaseModelManager firebaseModelManager = FirebaseModelManager.getInstance();
firebaseModelManager
.isModelDownloaded(remoteModel)
.continueWithTask(
new Continuation<Boolean, Task<Void>>() {
@Override
public Task<Void> then(@NonNull Task<Boolean> task) throws Exception {
// Create update condition if model is already downloaded,
// otherwise create download
// condition.
FirebaseModelDownloadConditions conditions =
task.getResult()
? new FirebaseModelDownloadConditions.Builder()
.requireWifi()
.build() // Update condition that requires wifi.
: new FirebaseModelDownloadConditions.Builder()
.build(); // Download condition.
return firebaseModelManager.download(remoteModel, conditions);
}
})
.addOnSuccessListener(
new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void ignored) {
FirebaseModelInterpreterOptions interpreterOptions =
new FirebaseModelInterpreterOptions.Builder(
new FirebaseCustomRemoteModel.Builder("offense-detector").build())
.build();
try {
interpreter =
FirebaseModelInterpreter.getInstance(interpreterOptions);
Log.e(TAG, "succed to build FirebaseModelInterpreter. ");
} catch (FirebaseMLException e) {
Log.e(TAG, "Failed to build FirebaseModelInterpreter. ", e);
}
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception ignored) {
Toast.makeText(
context,
"Model download failed for image classifier, please check" +
" your connection.",
Toast.LENGTH_LONG)
.show();
}
});
Log.d(TAG, "Created a Custom Image Classifier.");
int[] inputDims = {1, 200};
int[] outputDims = {1,1};
dataOptions =
new FirebaseModelInputOutputOptions.Builder()
.setInputFormat(0, FirebaseModelDataType.INT32, inputDims)
.setOutputFormat(0, FirebaseModelDataType.FLOAT32, outputDims)
.build();
Log.d(TAG, "Configured input & output data for the custom image classifier.");
}//constructor
It seems to be a tensorflow-lite library internal problem. Your code seems to work fine as the following statement is recorded in the log: "succed to build FirebaseModelInterpreter", which means that onSuccessListener has worked fine. The problem occurs afterwards when tensorflow lite runtime is being initialized and the error is a libc error, which seems to have originated at the OS level, apparently due to some illegal memory access. In my assessment, this can only be due to tensorflow-lite library itself. You may try with a different version of the library or a different device, but I can't say anything for sure.
In gradle file:
Try changing
implementation 'org.tensorflow:tensorflow-lite:2.0.0'
to
implementation 'org.tensorflow:tensorflow-lite:+'