Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c#部署fastdeploy时fastdeploy.vision.segmentation.PaddleSegModel model读取config文件时报错 Unexcepted preprocess operator: LoadImages. #2441

Closed
gunh4mmer opened this issue Apr 24, 2024 · 5 comments
Assignees

Comments

@gunh4mmer
Copy link


温馨提示:根据社区不完全统计,按照模板提问,可以加快回复和解决问题的速度


环境

  • 【编译命令】
    git clone https://github.com/PaddlePaddle/FastDeploy.git
    cd FastDeploy
    mkdir build && cd build
    cmake .. -G "Visual Studio 16 2019" -A x64 ^
    -DENABLE_ORT_BACKEND=ON ^
    -DENABLE_PADDLE_BACKEND=ON ^
    -DENABLE_OPENVINO_BACKEND=ON ^
    -DENABLE_TRT_BACKEND=ON ^
    -DENABLE_VISION=ON ^
    -DENABLE_TEXT=ON ^
    -DWITH_GPU=ON ^
    -DWITH_CAPI=ON ^
    -DWITH_CSHARPAPI=ON ^
    -DTRT_DIRECTORY="D:\TensorRT-8.5.2.2" ^
    -DCUDA_DIRECTORY="D:\cuda\v112" ^
    -DCMAKE_INSTALL_PREFIX="D:\paddle_fastdeploy"
    nuget restore
    msbuild fastdeploy.sln /m /p:Configuration=Release /p:Platform=x64
    msbuild INSTALL.vcxproj /m /p:Configuration=Release /p:Platform=x64
  • 【系统平台】: Windows x64(Windows10)
  • 【硬件】: Nvidia GPU 3060TI, CUDA 11.2 CUDNN 8.4.1.50 tensorRT8.5.2.2
  • 【编译语言】: C

我将在下方详细地将编译部署过程解释
(1):clone fastdeploy代码
(2):在build文件夹中按照上方cmake,结果如下,无报错
1
(3):进行nuget restore,报错如下
2
原因是opencvsharp版本过高,与项目.net framework4.0不适配,要么将.net framework升至4.8,要么指定低版本opencvsharp,因为之前已经尝试过升级framework,这次尝试指定opencvsharp版本。更改FastDeploy\csharp中的cmakelist.txt的内容,将PROPERTY VS_PACKAGE_REFERENCES "OpenCvSharp4_4.7.0.20230115"中的版本更改为“OpenCvSharp4_4.2.0.20200108”,重新cmake,并nuget restore,无报错。
(4):进行msbuild fastdeploy.sln /m /p:Configuration=Release /p:Platform=x64操作,报错如下图
3
原因是该项目与默认的c#10.0版本并不适配,因此修改FastDeploy\build\csharp\fastdeploy_csharp.csproj,将其中的LangVersion版本均改为9.0(因为改为7.3时会报错部分语句仅在高于c#8.0时才存在,因此改为的9.0),重新进行上述语句操作,无报错如下图
4
(5):进行msbuild INSTALL.vcxproj /m /p:Configuration=Release /p:Platform=x64操作,无报错,如下图
5
(6)进入paddle_fastdeploy文件夹,新建bin文件夹,并在cmd中执行fastdeploy_init.bat install %cd% bin语句,将dll全部打包到bin文件夹,完成,结果如下图,总共44个文件,2.19g大小
6
(7)使用语句python tools/export.py --config configs/ppmattingv2/ppmattingv2-stdc1-human_512.yml --model_path pretrained_models/ppmattingv2-stdc1-human_512.pdparams --save_dir output/inference_model --input_shape 1 3 1374 918
对已训练的paddle模型进行动转静操作,该模型转换后的deploy.yaml信息如下图

7
使用netron可视化查看模型输入输出结果如下
8
(8)新建vs工程文件,将工程修改为release且x64,添加如图所示的相关引用,并将bin文件夹中所有dll复制到项目文件夹下的bin\x64\Release中,并写下如下测试代码,测试后得知箭头处为报错点,似乎为不识别配置文件中的loadimage
9
10

@heliqi
Copy link
Collaborator

heliqi commented Apr 24, 2024

目前是不支持这个预处理(所有支持的预处理可以看这个目录:https://github.com/PaddlePaddle/FastDeploy/tree/develop/fastdeploy/vision/common/processors)

  1. 可以把配置中不支持的预处理删掉,先自行手动处理
  2. 回退下模型训练时的paddleseg版本,应该是新版本出现了新的预处理

@gunh4mmer
Copy link
Author

目前是不支持这个预处理(所有支持的预处理可以看这个目录:https://github.com/PaddlePaddle/FastDeploy/tree/develop/fastdeploy/vision/common/processors)

  1. 可以把配置中不支持的预处理删掉,先自行手动处理
  2. 回退下模型训练时的paddleseg版本,应该是新版本出现了新的预处理

我去查看matting关于loadimage预处理代码时发现,这是一个区分图像类型的代码,所有matting模型都拥有,我在paddleseg2.3版本的模型里同样找到了这个处理,说明并非新增的,但是在https://github.com/PaddlePaddle/FastDeploy/tree/develop/examples/vision/segmentation/paddleseg/matting/cpu-gpu中明确指出适配了matting模型,且提供的预导出模型也有loadimage这个处理,且给出了cpp下部署的案例,但是所给的所有支持的预处理目录里使用load关键字搜索了所有.cc文件,发现并没有相关的申明,有些迷惑

@gunh4mmer
Copy link
Author

目前是不支持这个预处理(所有支持的预处理可以看这个目录:https://github.com/PaddlePaddle/FastDeploy/tree/develop/fastdeploy/vision/common/processors)

  1. 可以把配置中不支持的预处理删掉,先自行手动处理
  2. 回退下模型训练时的paddleseg版本,应该是新版本出现了新的预处理

我去查看matting关于loadimage预处理代码时发现,这是一个区分图像类型的代码,所有matting模型都拥有,我在paddleseg2.3版本的模型里同样找到了这个处理,说明并非新增的,但是在https://github.com/PaddlePaddle/FastDeploy/tree/develop/examples/vision/segmentation/paddleseg/matting/cpu-gpu中明确指出适配了matting模型,且提供的预导出模型也有loadimage这个处理,且给出了cpp下部署的案例,但是所给的所有支持的预处理目录里使用load关键字搜索了所有.cc文件,发现并没有相关的申明,有些迷惑

拿上面编译的c++库以及example中的infer.cc去部署了一个项目,发现程序会报错,似乎c++也无法部署matting模型

@heliqi
Copy link
Collaborator

heliqi commented Apr 28, 2024

@heliqi
Copy link
Collaborator

heliqi commented Apr 28, 2024

如果可以,那可能是导出问题

@heliqi heliqi closed this as completed May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants