Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr

目录

[jni ncnn 推理报错:](#jni ncnn 推理报错:)

[Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr](#Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr)


jni ncnn 推理报错:

Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr

代码调用正常,所以是析构时报错,解决方法:

jni/cls_mobilenet.cpp

cpp 复制代码
MobileNetInference::~MobileNetInference() {
    net_.clear(); // <-- 必须先 clear
    #if NCNN_VULKAN
        ncnn::destroy_gpu_instance();
    #endif
}

// 加载模型
bool MobileNetInference::load_model(AAssetManager* mgr,const std::string& param_path,
                                    const std::string& bin_path) {

    ncnn::set_cpu_powersave(2);
    net_.opt = ncnn::Option();

#if NCNN_VULKAN
    if (use_gpu_) {
        // 创建 GPU 实例 --- 注意:最好在全局只创建一次(这里示例化创建)
        ncnn::create_gpu_instance();
        net_.opt.use_vulkan_compute = true;
    } else {
        net_.opt.use_vulkan_compute = false;
    }
#endif

    // 使用你设置的线程数而不是 get_big_cpu_count()(或至少赋值)
    net_.opt.num_threads = num_threads_;

    net_.opt.num_threads = ncnn::get_big_cpu_count();

    // 1. 加载参数文件
    int ret = net_.load_param(mgr, param_path.c_str());
    if (ret != 0) {
        return false;
    }

    // 2. 加载模型权重
    ret = net_.load_model(mgr, bin_path.c_str());
    if (ret != 0) {
        return false;
    }

    model_loaded_ = true;

    const std::vector<const char*>& input_names = net_.input_names();
    const std::vector<const char*>& output_names = net_.output_names();

    std::cout << "Input names: ";
    for (auto name : input_names) {
        std::cout << name << " ";
    }

    std::cout << "Output names: ";
    for (auto name : output_names) {
        std::cout << name << " ";
    }

    std::cout << "Model loaded successfully from:" << std::endl;
    std::cout << "  - " << param_path << std::endl;
    std::cout << "  - " << bin_path << std::endl;
    std::cout << "Using " << (use_gpu_ ? "GPU (Vulkan)" : "CPU")
              << " with " << num_threads_ << " threads." << std::endl;

    return true;
}
相关推荐
Yzzz-F5 小时前
牛客小白月赛127 E
算法
大锦终5 小时前
递归回溯综合练习
c++·算法·深度优先
AI即插即用5 小时前
即插即用系列(代码实践)专栏介绍
开发语言·人工智能·深度学习·计算机视觉
Keep__Fighting5 小时前
【神经网络的训练策略选取】
人工智能·深度学习·神经网络·算法
码农水水5 小时前
蚂蚁Java面试被问:混沌工程在分布式系统中的应用
java·linux·开发语言·面试·职场和发展·php
喵了meme5 小时前
c语言经验分享
c语言·开发语言
晚风吹长发5 小时前
初步了解Linux中的动静态库及其制作和使用
linux·运维·服务器·数据结构·c++·后端·算法
sin_hielo5 小时前
leetcode 3453(二分法)
算法
Knight_AL5 小时前
用 JOL 验证 synchronized 的锁升级过程(偏向锁 → 轻量级锁 → 重量级锁)
开发语言·jvm·c#
啊阿狸不会拉杆6 小时前
《数字图像处理》第 4 章 - 频域滤波
开发语言·python·数字信号处理·数字图像处理·频率域滤波