Tencent / ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform
Other
20.42k stars 4.16k forks source link

20220812最新代码下编译ncnn so库替换原有库后模型推理报错 #4168

Open bestpower opened 2 years ago

bestpower commented 2 years ago

error log | 日志或报错信息 | ログ

08-22 11:03:52.112  6946  6990 F libc    : Fatal signal 11 (SIGSEGV), code 1, fault addr 0xf300 in tid 6990 (Ocr_Detect_Work), pid 6946 (***)
08-22 11:03:52.205  7002  7002 I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
08-22 11:03:52.206   455   455 I /system/bin/tombstoned: received crash request for pid 6946
08-22 11:03:52.207  7002  7002 I crash_dump32: performing dump of process 6946 (target tid = 6990)
08-22 11:03:52.208  7002  7002 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-22 11:03:52.208  7002  7002 F DEBUG   : Native Crash TIME: 1549911
08-22 11:03:52.208  7002  7002 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
08-22 11:03:52.209  7002  7002 F DEBUG   : Build fingerprint: '***'
08-22 11:03:52.209  7002  7002 F DEBUG   : Revision: '0'
08-22 11:03:52.209  7002  7002 F DEBUG   : ABI: 'arm'
08-22 11:03:52.209  7002  7002 F DEBUG   : pid: 6946, tid: 6990, name: ***  >>> *** <<<
08-22 11:03:52.210  7002  7002 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xf300
08-22 11:03:52.210  7002  7002 F DEBUG   :     r0 0000f300  r1 00000000  r2 00000060  r3 95bfddd8
08-22 11:03:52.210  7002  7002 F DEBUG   :     r4 00000100  r5 942fb724  r6 0000f300  r7 942fb7b0
08-22 11:03:52.210  7002  7002 F DEBUG   :     r8 924ec010  r9 00000000  sl 00000017  fp 00000012
08-22 11:03:52.210  7002  7002 F DEBUG   :     ip 924ec010  sp 942fb6f0  lr 95944e14  pc 957795a8  cpsr 60000030
08-22 11:03:52.212  7002  7002 F DEBUG   : 
08-22 11:03:52.212  7002  7002 F DEBUG   : backtrace:
08-22 11:03:52.212  7002  7002 F DEBUG   :     #00 pc 000745a8  /data/app/***-GDMYVnFavzhHs_uLSGm5nQ==/lib/arm/libncnn.so
08-22 11:03:52.212  7002  7002 F DEBUG   :     #01 pc 00247f68  /data/app/***-GDMYVnFavzhHs_uLSGm5nQ==/lib/arm/libncnn.so (__kmp_invoke_microtask+1004)
08-22 11:03:52.592   471   471 W ADB_SERVICES: service_to_fd name ==== shell:dumpsys iphonesubinfo
08-22 11:03:53.678   471   471 W ADB_SERVICES: service_to_fd name ==== shell:dumpsys iphonesubinfo
08-22 11:03:54.069   455   455 E /system/bin/tombstoned: Tombstone written to: /data/tombstones/tombstone_02
08-22 11:03:54.071   650  7009 W ActivityManager:   Force finishing activity ***/.MainActivity

context | 编译/运行环境 | バックグラウンド

ncnn commit: 9af349cad8ff99ec0da5ef525a2463acc8999be4 Android Studio version: 2020.3.1 gradle version: 7.0.0 Cmake version: 3.10.2.4988404 Ndk version: 21.1.6352462 Android Os Version:8.1(27)

how to reproduce | 复现步骤 | 再現方法

1.更ncnn代码库至最新 2.编译ncnn so库,命令如下:

export ANDROID_NDK=/home/wangyu/sdk/android-ndk-r21e
mkdir -p $OUTPUT_NCNN_LID_DIR
cd $WORK_DIR/ncnn
mkdir -p build-android-armv7
cd build-android-armv7
rm -rf *
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI="armeabi-v7a" -DANDROID_ARM_NEON=ON -DANDROID_PLATFORM=android-16 ..
make -j8
make install

3.替换安卓应用工程内ncnn旧版本库为当前编译库 4.清理原AS工程后重新编译 5.运行应用并加载JNI库 6.选择图片进行推理过程中应用崩溃退出

more | 其他 | その他

另外,我还将推理模型的onnx版本通过最新ncnn编译的转换工具进行重新转换并替换原模型文件后执行以上步骤仍报相同错误 编译及转换命令如下

cd $WORK_DIR/ncnn
mkdir -p build
cd build
rm -rf *
cmake ..
make -j8
cd $ONNX_MODEL_DIR
$WORK_DIR/ncnn/build/tools/onnx/onnx2ncnn $ONNX_MODEL_DIR/${onnx_model} $OUTPUT_NCNN_MODEL_DIR/${onnx_model}.param $OUTPUT_NCNN_MODEL_DIR/${onnx_model}.bin

麻烦帮忙看看是什么原因,模型文件详见附件: ncnn_model.zip

bestpower commented 2 years ago

另外,这个问题在最近几个大版本更新中都出现了: 20220701 20220721 20220729 并非之前说的NDK版本问题,我都是基于较低版本的NDK重新编译的

bestpower commented 2 years ago

经排查,发现是在模型加载之后,正式推理之前的这段代码报了错:

    ncnn::Layer* layer = nullptr;
    for (size_t i = 0; i < net->mutable_layers().size(); i++)
    {
        if (net->mutable_layers()[i]->name == name)
        {
            layer = net->mutable_layers()[i];
            break;
        }
    }

    if (!layer)
    {
        fprintf(stderr, "no such layer %s\n", name);
        return;
    }

    layer->destroy_pipeline(net->opt);

    layer->support_fp16_storage = false;

    ncnn::Option opt2 = net->opt;
    opt2.use_fp16_packed = false;
    opt2.use_fp16_storage = false;
    opt2.use_fp16_arithmetic = false;
    layer->create_pipeline(opt2);

该段代码的作用是针对特定网络层进行特定配置,之前一直是没有问题的,请问是否是更新后相关接口发生了改变?

bestpower commented 3 months ago

目前的新版本库,仍存在执行layer->create_pipeline方法时crash的问题,导致无法使用fp16精度进行推理,请问有解决办法吗?