Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YOLO crashes during operation, and the prompt is related to the libomp.so library #1325

Open
caiyongrt opened this issue Jan 19, 2025 · 11 comments

Comments

@caiyongrt
Copy link

caiyongrt commented Jan 19, 2025

error reporting:

Softversion: PD1806_A_9.8.22
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  Time: 2025-01-19 16:13:30
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  Build fingerprint: 'vivo/PD1806/PD1806:10/QP1A.190711.020/compiler10141718:user/release-keys'
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  Revision: '0'
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  ABI: 'arm64'
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  Timestamp: 2025-01-19 16:13:30+0800
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  pid: 28933, tid: 28999, name: pool-2-thread-1  >>> com.tencent.yolov8ncnn <<<
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  uid: 11292
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A  signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      x0  0000000000000000  x1  0000000000007147  x2  0000000000000006  x3  0000007222b81dd0
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      x4  74616d726f666e69  x5  74616d726f666e69  x6  74616d726f666e69  x7  656c70202c6e6f69
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      x8  00000000000000f0  x9  b2c581c1c8f245ec  x10 0000000000000001  x11 0000000000000000
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      x12 fffffff0fffffbdf  x13 6f6d20726f46202e  x14 2065726f6d20726f  x15 0000007222b81690
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      x16 00000073253ab738  x17 0000007325389f20  x18 000000721185d0e8  x19 0000000000007105
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      x20 0000000000007147  x21 00000000ffffffff  x22 00000071f7ea9a48  x23 00000071f16d99b6
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      x24 00000071f7ea7e4f  x25 00000071f7f2f000  x26 00000071f16d99b6  x27 0000000000000000
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      x28 00000072889c6810  x29 0000007222b81e70
2025-01-19 16:13:30.459 29030-29030 DEBUG                   pid-29030                            A      sp  0000007222b81db0  lr  000000732533b86c  pc  000000732533b898
2025-01-19 16:13:30.460 29030-29030 DEBUG                   pid-29030                            A  
                                                                                                    backtrace:
2025-01-19 16:13:30.460 29030-29030 DEBUG                   pid-29030                            A      NOTE: Function names and BuildId information is missing for some frames due
2025-01-19 16:13:30.460 29030-29030 DEBUG                   pid-29030                            A      NOTE: to unreadable libraries. For unwinds of apps, only shared libraries
2025-01-19 16:13:30.460 29030-29030 DEBUG                   pid-29030                            A      NOTE: found under the lib/ directory are readable.
2025-01-19 16:13:30.460 29030-29030 DEBUG                   pid-29030                            A        #00 pc 0000000000073898  /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: 6aaa192fa70426ea767b3bcf55b19a30)
2025-01-19 16:13:30.460 29030-29030 DEBUG                   pid-29030                            A        #01 pc 000000000003cae4  /data/data/com.tencent.yolov8ncnn/files/chaquopy/AssetFinder/requirements/chaquopy/lib/libomp.so

The problem still exists after the Chaquopy interface is simplified. The interface code is as follows:

	public void PythonDetectRun(Bitmap curbitmap){
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		curbitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
		byte[] imageData = stream.toByteArray();
		PyObject module = mPython.getModule("cy");
}

Chaquopy version

Devices or emulators where the issue happens

Relevant parts of your code

Describe your issue

@mhsmith mhsmith changed the title Android Development: When the NDK calls YOLO and then uses Chaquopy to call the Python interface, the program crashes during operation, and the prompt is related to the libomp.so library YOLO crashes during operation, and the prompt is related to the libomp.so library Jan 19, 2025
@mhsmith
Copy link
Member

mhsmith commented Jan 19, 2025

Please do not ignore issue templates, they are there to save your time as well as mine.

To help you I would need to know the following information:

  • Chaquopy version – The version of com.chaquo.python in your app's top-level build.gradle file.
  • Relevant parts of your code – including the "cy" module, and the "python" or "chaquopy" sections of your build.gradle file.

@caiyongrt
Copy link
Author

caiyongrt commented Jan 20, 2025

1.app's top-level build.gradle file:

plugins {
    id("com.chaquo.python") version "16.0.0" apply false
}

Or it could be...

plugins {
    id("com.chaquo.python") version "15.0.1" apply false
}

2.Python code for testing:

import torch
def fun():
    return

Or it could be...

import torch
import torchvision.transforms as transforms
import torchvision.models as models

def fun():
    return

Explanation: An error will occur as long as import torch is added!

@mhsmith
Copy link
Member

mhsmith commented Jan 20, 2025

Please also provide:

  • The "python" or "chaquopy" sections of your app-level build.gradle file
  • Which devices or emulators does the issue happen on, and what are their Android versions? If you have any devices or emulators where the issue does NOT occur, please list them too.

@caiyongrt
Copy link
Author

caiyongrt commented Jan 21, 2025

1、app-level build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.chaquo.python'
android {
    compileSdkVersion 33
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.tencent.yolov8ncnn"
        archivesBaseName = "$applicationId"

        minSdkVersion 29
        ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
    }
    ndkVersion '28.0.12433566'

2、project-level build.gradle:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
    }
}
plugins {
    id("com.chaquo.python") version "16.0.0" apply false
}
allprojects {
    repositories {
        jcenter()
        google()
    }
}

3、Android Studio Device File Explorer:vivo vivo NEX A Android 10.0 (Q)

@mhsmith
Copy link
Member

mhsmith commented Jan 23, 2025

For the third time, please post the the "python" or "chaquopy" sections of your app-level build.gradle file. If you've added torch to your app, then you must have one.

@mhsmith
Copy link
Member

mhsmith commented Feb 1, 2025

If you still need help, then post the requested information, and I'll reopen the issue.

@mhsmith mhsmith closed this as completed Feb 1, 2025
@caiyongrt
Copy link
Author

caiyongrt commented Feb 4, 2025

app-level build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'com.chaquo.python'
android {
    compileSdkVersion 33
    buildToolsVersion "29.0.2"

    defaultConfig {
        applicationId "com.tencent.yolov8ncnn"
        archivesBaseName = "$applicationId"

        minSdkVersion 29
        ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
    }

    ndkVersion '28.0.12433566'
    externalNativeBuild {
        cmake {
            version "3.10.2"
            path file('src/main/jni/CMakeLists.txt')
        }
    }

    dependencies {
        implementation 'androidx.appcompat:appcompat:1.4.1'
        implementation 'androidx.recyclerview:recyclerview:1.3.0'

        implementation 'androidx.core:core:1.6.0'

        implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
        def camerax_version = "1.0.0-alpha05"
        implementation "androidx.camera:camera-core:$camerax_version"
        implementation "androidx.camera:camera-camera2:$camerax_version"

        implementation 'com.arthenica:ffmpeg-kit-full:5.1.LTS'
    }
}
chaquopy {
    defaultConfig {
        pip {
            install "opencv-python>=4.5.0.00"
            install "numpy"
            install "torch"
            install "torchvision"
        }
    }
}
dependencies {
    //implementation project(path: ':opencv460')
}

@caiyongrt
Copy link
Author

caiyongrt commented Feb 4, 2025 via email

@mhsmith mhsmith reopened this Feb 11, 2025
@caiyongrt
Copy link
Author

I've already sent the code of the app-level build.gradle file. Can you spot any issues in it?

@caiyongrt
Copy link
Author

It seems that there might be conflicts with some C++ shared object (SO) libraries called by other NDK modules in Chaquopy.
Is it possible to resolve this issue by having each module call its own C++ SO libraries? If so, how can we make separate calls? Please provide a code example.

@mhsmith
Copy link
Member

mhsmith commented Feb 24, 2025

This build.gradle file looks fine to me. And I can confirm that with those packages installed, import torch doesn't cause a crash for me either on an Android 10 emulator or a Pixel 7.

Why do you think it might be caused by a conflict between libraries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants