zuoqing1988 / ZQCNN

一款推理框架,同时有很多有用的demo,觉得好用请点星啊
MIT License
2.22k stars 508 forks source link

内存泄漏 #112

Open j201111100523 opened 5 years ago

j201111100523 commented 5 years ago
for (int i = 0; i < 100; i++)
{
    //******************** 识别初始化*******************************************************
    ZQ_FaceRecognizer* recognizer[1] = { 0 };
    std::string prototxt_file = "model/mobilefacenet-res2-6-10-2-dim128.zqparams";
    std::string caffemodel_file = "model/mobilefacenet-res2-6-10-2-dim128-emore.nchwbin";
    std::string out_blob_name = "fc5";

    bool fail_flag = false;
    recognizer[0] = new ZQ_FaceRecognizerArcFaceZQCNN();
    if (!recognizer[0]->Init("", prototxt_file, caffemodel_file, out_blob_name))
    {
        cout << "failed to init arcface\n";
        fail_flag = true;
    }

    if (fail_flag)
    {
        if (recognizer[0]) delete recognizer[0];
        return EXIT_FAILURE;
    }
    //***********************************************************************************************
        //***************************add face detect******************************
    Mat image0 = cv::imread("data/14.png", 1);
    if (image0.empty())
    {
        cout << "empty image\n";
        return EXIT_FAILURE;
    }
    std::vector<ZQ_CNN_BBox> thirdBbox;
    std::vector<ZQ_CNN_BBox106> thirdBbox106;
    ZQ_CNN_MTCNN mtcnn;
    int thread_num = 0;
    bool special_handle_very_big_face = false;
    if (!mtcnn.Init("model/det1-dw20-fast.zqparams", "model/det1-dw20-fast.nchwbin",
        "model/det2-dw24-fast.zqparams", "model/det2-dw24-fast.nchwbin",
        //"model/det2.zqparams", "model/det2_bgr.nchwbin",
        "model/det3-dw48-fast.zqparams", "model/det3-dw48-fast.nchwbin",
        thread_num, true, "model/det5-dw112.zqparams", "model/det5-dw112.nchwbin"))
    {
        cout << "failed to init!\n";
        return EXIT_FAILURE;
    }
    mtcnn.SetPara(image0.cols, image0.rows, 60, 0.5, 0.6, 0.8, 0.4, 0.5, 0.5, 0.709, 3, 20, 4, special_handle_very_big_face);
    if (!mtcnn.Find106(image0.data, image0.cols, image0.rows, image0.step[0], thirdBbox106))
    {
        cout << "failed to find face!\n";
    }

    int FeatureLength = recognizer[0]->GetFeatDim();
    //  float * outFeature = new float[FeatureLength];
    Mat NormFace = Mat(recognizer[0]->GetCropHeight(), recognizer[0]->GetCropWidth(), CV_8UC3);
    float face5point_x[5] = { 0 };
    float face5point_y[5] = { 0 };
    std::vector<float> feat0(FeatureLength), feat1(FeatureLength);

ZQ_PIXEL_FMT_BGR, face5point_x, face5point_y, (unsigned char)(NormFace.data), NormFace.step[0]); recognizer[0]->ExtractFeature((unsigned char)NormFace.data, NormFace.step[0], ZQ_PIXEL_FMT_BGR, &feat0[0], true);//提取特征 // recognizer[0]->ExtractFeature((unsigned char*)NormFace.data, NormFace.step[0], ZQ_PIXEL_FMT_BGR, &feat1[0], true);//提取特征 float score = recognizer[0]->CalSimilarity(&feat0[0], &feat0[0]);//计算相似度 // cout << "gets score " << score << "\n"; } double t2 = omp_get_wtime(); cout << "time cost:" << t2 - t1 << "s"; if (recognizer[0]) delete recognizer[0]; } 上述代码,运行出现内存泄漏

j201111100523 commented 5 years ago

检测部分没出现内存泄漏,泄漏在识别部分

zuoqing1988 commented 5 years ago

析构函数的问题,已解决

j201111100523 commented 5 years ago
class ZQ_FaceRecognizer
{
public:
    virtual ~ZQ_FaceRecognizer() {}
    virtual bool Init(const std::string model_name

添加析构函数,问题依旧存在 image

zuoqing1988 commented 5 years ago

image image

j201111100523 commented 5 years ago

好了,是我这边的问题,感谢左博