FastDeploy
FastDeploy copied to clipboard
二次开发,使用FastDeploy作为依赖库,封装dll后,很多接口都没法使用问题,麻烦跟踪排查一下。
- 环境:
windwos10 VS2019 3060 6G笔记本显卡
-
问题: 调用ppyoloe,yolov7和maskrcnn,ocr,均是在example下正常,但是封装dll后均报错 yolov7和ppyoloe是模型无法生成trt文件,maskrcnn是,cpu gpu和trt都崩溃,cpu和gpu模式初始化成功,predict崩溃; 以ppyoloe为例: 封装dll代码:
-
.h文件:
__declspec(dllexport) int __stdcall fastdeploy_model_trt_convert(const char* _modeldir, int _trtmodeltype = 1, int _gpu_id = 0);
- .cpp文件
#include "fastdeploy/vision.h"
#ifdef WIN32
const char sep = '\\';
#else
const char sep = '/';
#endif
#ifdef WIN32
#define ACCESS(fileName,accessMode) _access(fileName,accessMode)
#else
#define ACCESS(fileName,accessMode) access(fileName,accessMode)
#endif
__declspec(dllexport) int __stdcall fastdeploy_model_trt_convert(const char* _modeldir, int _trtmodeltype /*= 1*/, int _gpu_id /*= 0*/)
{
int gpuid = 0;
if (_gpu_id < 0)
{
gpuid = 0;
}
else {
gpuid = _gpu_id;
}
auto option = fastdeploy::RuntimeOption();
option.UseGpu(gpuid);
option.UseTrtBackend();
auto model_file = (std::string)_modeldir + sep + "model.pdmodel";
auto params_file = (std::string)_modeldir + sep + "model.pdiparams";
auto config_file = (std::string)_modeldir + sep + "infer_cfg.yml";
std::string trtpath_file = "";
if (_trtmodeltype == 1)
{
trtpath_file = (std::string)_modeldir + sep + "deploy_fp16.trt";
option.EnableTrtFP16();
}
else if (_trtmodeltype == 0) {
trtpath_file = (std::string)_modeldir + sep + "deploy_fp32.trt";
}
else {
trtpath_file = (std::string)_modeldir + sep + "deploy_fp8.trt";
}
option.SetTrtCacheFile(trtpath_file);
auto model = fastdeploy::vision::detection::PPYOLOE(model_file, params_file, config_file, option);
if (!model.Initialized()) {
return -2;
}
if (ACCESS(trtpath_file.c_str(),0) == -1)
{
return -3;
}
return 0;
}
控制台调用程序:
int main()
{
std::string modeldir = ".\\ppyoloe";
fastdeploy_model_trt_convert(modeldir.c_str());
std::cout << "Hello World!\n";
}
接口设置了SetTrtCacheFile(trtpath_file);,并且模型初始化成功了fastdeploy::vision::detection::PPYOLOE和model.Initialized()均返回正常,但是没有生成trt文件:
if (ACCESS(trtpath_file.c_str(),0) == -1)
{
return -3;
}
返回了-3
好的,已经收到您的问题,我们节后会安排同学跟进这个问题哈 ~
您好,根据您提供的代码,我这边的测试情况如下:
- 测试环境:windows 11, vs2019, 3080 Ti 16G
- 测试方式:基于FD二次开发新的DLL,基于二次开发的DLL再次开发新的应用程序
- 测试模型:ppyoloe, yolov7, ocr v3, maskrcnn
- 测试描述:基于 @xinsuinizhuan 提供的sln工程,直接打开编译新的DLL,修改了部分有问题的代码;基于新的DLL,编译可执行文件;
- 模型文件:所有模型及图片均从FD仓库下载,视频文件为刘先生提供
- 测试结果:
-
- ppyoloe, yolov7, ocr v3 在TRT+FP16下均正常推理
-
- maskrcnn在GPU+Paddle模式下视频推理正常跑,显存占用约13G,和视频分辨率有关
-
- 发现一个bug: ocr v3 system的Initialed()接口返回结果错误,已经初始化成功,但依然返回false
-
对于ocr中初始化判断的逻辑的问题,我们会尽快修复哈 ~
此ISSUE由于一年未更新,将会关闭处理,如有需要,可再次更新打开。