java - 如何摆脱错误 "Fatal signal 11 (SIGSEGV), code 1, fault addr 0x70"

标签 java android firebase interpreter custom-model-binder

我正在做我的android项目。基本上,用户输入文本,模型会预测该文本是否具有攻击性。这是通过在 Python 上训练深度学习模型 LSTM 来完成的。然后我将其部署到云(Firebase)。并将其下载到我的 Android 手机中,并从远程模型创建一个解释器(如果已下载)。现在,当我尝试运行该应用程序时,模型会从云端下载,但会出现错误。 PFA 错误消息的屏幕截图。 让我知道我做错了什么以及为什么会发生这样的错误?

这是我运行应用程序时得到的日志,

$ 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)***

这是 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

最佳答案

这似乎是tensorflow-lite库内部问题。您的代码似乎工作正常,因为日志中记录了以下语句:“成功构建 FirebaseModelInterpreter”,这意味着 onSuccessListener 工作正常。当tensorflow lite运行时正在初始化时,问题出现了,并且错误是libc错误,这似乎起源于操作系统级别,显然是由于一些非法内存访问造成的。根据我的评估,这只能归因于tensorflow-lite库本身。您可以尝试使用不同版本的库或不同的设备,但我不能肯定地说。

在gradle文件中:

尝试改变

实现“org.tensorflow:tensorflow-lite:2.0.0”

实现“org.tensorflow:tensorflow-lite:+”

关于java - 如何摆脱错误 "Fatal signal 11 (SIGSEGV), code 1, fault addr 0x70",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62266890/

相关文章:

java - 使用 Executor 框架在 Weblogic SOAP Webservice 中创建后台线程

java - 如何在 Android 中使用 HTTPS 发布

java - 在 Android 中获取 XML 响应

android - 如何在 Android 上实现我自己的 URI 方案

android - 如何正确旋转位图?

firebase - flutter :(24658):PlatformException(network_error,com.google.android.gms.common.api.ApiException:7:,null,null)

swift : My files in Firebase Storage wouldn't be deleted

java - 为 install4j 安装程序创建自定义语言?

java - 如何协调抽屉式导航与底部导航 View

android - Firebase 动态链接未打开应用