Skip to content

GroundDino模型导出后,无法在C++上推理。 #321

Closed

Description

@TinyQi

模型是导出来了,使用predict.py文件是可以成功推理的,但是当我使用C++(paddle_inference)进行推理的时候,在模型初始化的时候就报错,报错信息为以下:
image

Activity

  1. TinyQi commented on Nov 23, 2023

    @TinyQi
    Author

    image

  2. TinyQi commented on Nov 23, 2023

    @TinyQi
    Author

    主要报错信息:InvalidArgumentError: Failed to parse program_desc from binary string.
    [Hint: Expected desc_.ParseFromString(binary_str) == true, but received desc_.ParseFromString(binary_str):0 != true:1.] (at /paddle/paddle/fluid/framework/program_desc.cc:103)

  3. LokeZhou commented on Nov 24, 2023

    @LokeZhou
    Collaborator

    提供一下最小复现代码

  4. TinyQi commented on Nov 24, 2023

    @TinyQi
    Author

    提供一下最小复现代码

    就在这个引擎初始化的函数里面报错的:

    `
    bool PaddleInferenceEngine::Init(const InferenceConfig& infer_config)
    {
    const PaddleEngineConfig& engine_config = *(infer_config.paddle_config);
    paddle_infer::Config config;

    config.SetModel(engine_config.model_filename,
                    engine_config.params_filename);
    
    // 使用cpu推理时可以使用mkl进行加速
    if (engine_config.use_mkl && !engine_config.use_gpu)
    {
        config.EnableMKLDNN();
    
        config.SetMkldnnCacheCapacity(10);
    }
    
    config.SetCpuMathLibraryNumThreads(engine_config.mkl_thread_num);
    
    if (engine_config.use_gpu)
    {
        config.EnableUseGpu(100, engine_config.gpu_id);
    }
    else
    {
        config.DisableGpu();
    }
    config.SwitchUseFeedFetchOps(false);
    config.SwitchSpecifyInputNames(true);
    config.SwitchIrOptim(engine_config.use_ir_optim);
    config.EnableMemoryOptim();
    config.DisableGlogInfo();
    if (engine_config.use_trt && engine_config.use_gpu)
    {
        paddle_infer::PrecisionType precision;
        if (engine_config.precision == 0)
        {
            precision = paddle_infer::PrecisionType::kFloat32;
        }
        else if (engine_config.precision == 1)
        {
            precision = paddle_infer::PrecisionType::kHalf;
        }
        else if (engine_config.precision == 2)
        {
            precision = paddle_infer::PrecisionType::kInt8;
        }
        else
        {
            std::cerr << "Can not support the set precision" << std::endl;
            return false;
        }
        config.EnableTensorRtEngine(
            engine_config.max_workspace_size, /* workspace_size*/
            engine_config.max_batch_size,     /* max_batch_size*/
            engine_config.min_subgraph_size,  /* min_subgraph_size*/
            precision,                        /* precision*/
            engine_config.use_static,         /* use_static*/
            engine_config.use_calib_mode);    /* use_calib_mode*/
    
        if (engine_config.min_input_shape.size() != 0) {
        config.SetTRTDynamicShapeInfo(engine_config.min_input_shape,
                                        engine_config.max_input_shape,
                                        engine_config.optim_input_shape);
        }
    }
    
    HLOG_INFO_Analyzer("begin to create paddle infference Predictor.");
    predictor_ = std::move(paddle_infer::CreatePredictor(config));
    HLOG_INFO_Analyzer("end of create paddle infference Predictor.");
    

    return true;
    }
    `

  5. zhoutianzi666 commented on Nov 27, 2023

    @zhoutianzi666
    Contributor

    使用CPU推理还是GPU推理报错的呢?

  6. TinyQi commented on Nov 27, 2023

    @TinyQi
    Author

    使用CPU推理还是GPU推理报错的呢?

    你好,我CPU和GPU都试过,根本还没到推理,就初始化预测引擎的时候就报错了,报错就发生在我上面发的这个初始化函数里

  7. zhoutianzi666 commented on Nov 27, 2023

    @zhoutianzi666
    Contributor

    使用CPU推理还是GPU推理报错的呢?

    你好,我CPU和GPU都试过,根本还没到推理,就初始化预测引擎的时候就报错了,报错就发生在我上面发的这个初始化函数里
    先加上这句话试试呢config.SwitchIrOptim(false);

  8. TinyQi commented on Nov 27, 2023

    @TinyQi
    Author

    使用CPU推理还是GPU推理报错的呢?

    你好,我CPU和GPU都试过,根本还没到推理,就初始化预测引擎的时候就报错了,报错就发生在我上面发的这个初始化函数里
    先加上这句话试试呢config.SwitchIrOptim(false);

    刚刚试过了,不行,还是一样的错误。我导出的这个模型中,好像是需要重新编译C++扩展,会不会是模型中有一些模块无法被paddle_inference解析呢?

  9. zhoutianzi666 commented on Nov 27, 2023

    @zhoutianzi666
    Contributor

    使用CPU推理还是GPU推理报错的呢?

    你好,我CPU和GPU都试过,根本还没到推理,就初始化预测引擎的时候就报错了,报错就发生在我上面发的这个初始化函数里
    先加上这句话试试呢config.SwitchIrOptim(false);

    刚刚试过了,不行,还是一样的错误。我导出的这个模型中,好像是需要重新编译C++扩展,会不会是模型中有一些模块无法被paddle_inference解析呢?

    试试python能推理吗?

  10. TinyQi commented on Nov 27, 2023

    @TinyQi
    Author

    使用CPU推理还是GPU推理报错的呢?

    你好,我CPU和GPU都试过,根本还没到推理,就初始化预测引擎的时候就报错了,报错就发生在我上面发的这个初始化函数里
    先加上这句话试试呢config.SwitchIrOptim(false);

    刚刚试过了,不行,还是一样的错误。我导出的这个模型中,好像是需要重新编译C++扩展,会不会是模型中有一些模块无法被paddle_inference解析呢?

    试试python能推理吗?

    python是可以使用https://github.com/PaddlePaddle/PaddleMIX/blob/develop/deploy/groundingdino/predict.py这个脚本进行推理的,现在就是C++下不行

  11. zhoutianzi666 commented on Nov 27, 2023

    @zhoutianzi666
    Contributor

    C++的话,应该要编译自定义算子呢

  12. TinyQi commented on Nov 27, 2023

    @TinyQi
    Author

    C++的话,应该要编译自定义算子呢

    就是说要把新加的算子,编译到paddle_inference.so中,才能实现推理是不?如果是的话,请问有相关的指导文档嘛?

  13. LokeZhou commented on Nov 28, 2023

    @LokeZhou
    Collaborator

    可以试试去掉deformable_detr_ops这个算子,排除这个自定义算子带来的影响。具体:
    1.如果环境里面安装了deformable_detr_ops,可以先pip uninstall 删掉;
    2.去除后,重新导出,试试python能不能正常跑;
    3.如果python正常,再试试c++

  14. TinyQi commented on Dec 1, 2023

    @TinyQi
    Author

    可以试试去掉deformable_detr_ops这个算子,排除这个自定义算子带来的影响。具体: 1.如果环境里面安装了deformable_detr_ops,可以先pip uninstall 删掉; 2.去除后,重新导出,试试python能不能正常跑; 3.如果python正常,再试试c++

    hello,我试过了,还是不行。请问您那边有在C++推理成功推理过不?

  15. TinyQi commented on Dec 6, 2023

    @TinyQi
    Author

    可以试试去掉deformable_detr_ops这个算子,排除这个自定义算子带来的影响。具体: 1.如果环境里面安装了deformable_detr_ops,可以先pip uninstall 删掉; 2.去除后,重新导出,试试python能不能正常跑; 3.如果python正常,再试试c++

    请问,你们内部有成功过的例子不?还是说正在兼容当中啊

  16. LokeZhou commented on Dec 6, 2023

    @LokeZhou
    Collaborator

    可以试试去掉deformable_detr_ops这个算子,排除这个自定义算子带来的影响。具体: 1.如果环境里面安装了deformable_detr_ops,可以先pip uninstall 删掉; 2.去除后,重新导出,试试python能不能正常跑; 3.如果python正常,再试试c++

    请问,你们内部有成功过的例子不?还是说正在兼容当中啊

    这个模型暂没做过c++推理,可以参考https://github.com/PaddlePaddle/Paddle-Inference-Demo/tree/master 里面的其他模型demo;若报错,可在这里面提issue https://github.com/PaddlePaddle/Paddle-Inference-Demo/issues?q=is%3Aopen+is%3Aissue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions