本文档介绍使用Paddle Inference的C++接口在Linux服务器端(NV GPU或者X86 CPU)部署分割模型的示例,主要步骤包括:
飞桨针对不同场景,提供了多个预测引擎部署模型(如下图),详细信息请参考文档。
大家可以从链接下载Paddle Inference C++预测库。
注意根据机器的CUDA版本、cudnn版本、使用MKLDNN或者OpenBlas、是否使用TenorRT等信息,选择准确版本。建议选择版本>=2.0.1的预测库。
下载paddle_inference.tgz
压缩文件后进行解压,将解压的paddle_inference文件保存到PaddleSeg/deploy/cpp/
下。
如果大家需要编译Paddle Inference C++预测库,可以参考文档,此处不再赘述。
本示例使用OpenCV读取图片,所以需要准备OpenCV。
执行如下命令下载、编译、安装OpenCV。
wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz
tar -xf 3.4.7.tar.gz
mkdir -p opencv-3.4.7/build
cd opencv-3.4.7/build
install_path=/usr/local/opencv3
cmake .. -DCMAKE_INSTALL_PREFIX=${install_path} -DCMAKE_BUILD_TYPE=Release
make -j
make install
cd ../..
本示例使用Yaml读取配置文件信息。
执行如下命令下载、编译、安装Yaml。
wget https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.7.0.zip
unzip yaml-cpp-0.7.0.zip
mkdir -p yaml-cpp-yaml-cpp-0.7.0/build
cd yaml-cpp-yaml-cpp-0.7.0/build
cmake -DYAML_BUILD_SHARED_LIBS=ON ..
make -j
make install
在PaddleSeg/deploy/cpp/
目录下执行如下命令,下载测试模型用于测试。如果需要测试其他模型,请参考文档导出预测模型。
wget https://paddleseg.bj.bcebos.com/dygraph/demo/bisenet_demo_model.tar.gz
tar xzf bisenet_demo_model.tar.gz
下载cityscapes验证集中的一张图片。
wget https://paddleseg.bj.bcebos.com/dygraph/demo/cityscapes_demo.png
请检查PaddleSeg/deploy/cpp/
下存放了预测库、模型、图片,如下。
PaddleSeg/deploy/cpp
|-- paddle_inference # 预测库
|-- bisenetv2_demo_model # 模型
|-- cityscapes_demo.png # 图片
执行sh run_seg_cpu.sh
,会进行编译,然后在X86 CPU上执行预测。
执行sh run_seg_gpu.sh
,会进行编译,然后在Nvidia GPU上执行预测。
分割结果会保存在当前目录的“out_img.jpg“图片,如下图。注意,该图片是使用了直方图均衡化,便于可视化。
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》