diff --git a/deploy/cpp/CMakeLists.txt b/deploy/cpp/CMakeLists.txt index 42777fb75d168bf88bddf094ccd42b897585be13..a6b7d3fe5e35b648a2ac5c43b4ce290bd3db9d14 100644 --- a/deploy/cpp/CMakeLists.txt +++ b/deploy/cpp/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -project(PaddleObjectDetector CXX C) +project(PaddleX CXX C) option(WITH_MKL "Compile demo with MKL/OpenBlas support,defaultuseMKL." ON) option(WITH_GPU "Compile demo with GPU/CPU, default use CPU." ON) @@ -74,7 +74,7 @@ if (WIN32) include_directories("${PADDLE_DIR}/paddle/include") link_directories("${PADDLE_DIR}/paddle/fluid/inference") find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/build/ NO_DEFAULT_PATH) - + unset(OpenCV_DIR CACHE) else () find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/share/OpenCV NO_DEFAULT_PATH) include_directories("${PADDLE_DIR}/paddle/include") diff --git a/deploy/cpp/scripts/build.sh b/deploy/cpp/scripts/build.sh index 3dcf908884702303dcc197840bea5e42a2a6844a..f1dac0409a252dd68ee83fa44dce1a4171801f16 100644 --- a/deploy/cpp/scripts/build.sh +++ b/deploy/cpp/scripts/build.sh @@ -2,14 +2,14 @@ WITH_GPU=ON # 是否集成 TensorRT(仅WITH_GPU=ON 有效) WITH_TENSORRT=OFF -# 上一步下载的 Paddle 预测库路径 -PADDLE_DIR=/root/projects/deps/fluid_inference/ +# Paddle 预测库路径 +PADDLE_DIR=/path/to/fluid_inference/ # CUDA 的 lib 路径 -CUDA_LIB=/usr/local/cuda/lib64/ +CUDA_LIB=/path/to/cuda/lib/ # CUDNN 的 lib 路径 -CUDNN_LIB=/usr/local/cudnn/lib64/ +CUDNN_LIB=/path/to/cudnn/lib/ -# OPENCV 路径, 如果使用自带预编译版本可不设置 +# OPENCV 路径, 如果使用自带预编译版本可不修改 OPENCV_DIR=$(pwd)/deps/opencv3gcc4.8/ sh $(pwd)/scripts/bootstrap.sh diff --git a/docs/deploy.md b/docs/deploy/deploy.md similarity index 100% rename from docs/deploy.md rename to docs/deploy/deploy.md diff --git a/docs/deploy_cpp_linux.md b/docs/deploy/deploy_cpp_linux.md similarity index 79% rename from docs/deploy_cpp_linux.md rename to docs/deploy/deploy_cpp_linux.md index 187426fb9cf428cedd061097bb33ded657bc2d81..5e6a594b70fedf3d88e9566e45f8b3f8e82d2109 100644 --- a/docs/deploy_cpp_linux.md +++ b/docs/deploy/deploy_cpp_linux.md @@ -1,7 +1,7 @@ # Linux平台编译指南 ## 说明 -本文档在 `Linux`平台使用`GCC 4.8.5` 和 `GCC 4.9.4`测试过,如果需要使用更高G++版本编译使用,则需要重新编译Paddle预测库,请参考: [从源码编译Paddle预测库](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/advanced_usage/deploy/inference/build_and_install_lib_cn.html#id15)。 +本文档在 `Linux`平台使用`GCC 4.8.5` 和 `GCC 4.9.4`测试过,如果需要使用更高G++版本编译使用,则需要重新编译Paddle预测库,请参考: [从源码编译Paddle预测库](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/advanced_guide/inference_deployment/inference/build_and_install_lib_cn.html#id12)。 ## 前置条件 * G++ 4.8.2 ~ 4.9.4 @@ -19,7 +19,7 @@ ### Step2: 下载PaddlePaddle C++ 预测库 fluid_inference -PaddlePaddle C++ 预测库针对不同的`CPU`,`CUDA`,以及是否支持TensorRT,提供了不同的预编译版本,请根据实际情况下载: [C++预测库下载列表](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/advanced_usage/deploy/inference/build_and_install_lib_cn.html) +PaddlePaddle C++ 预测库针对不同的`CPU`,`CUDA`,以及是否支持TensorRT,提供了不同的预编译版本,请根据实际情况下载: [C++预测库下载列表](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/advanced_guide/inference_deployment/inference/build_and_install_lib_cn.html#id1) 下载并解压后`/root/projects/fluid_inference`目录包含内容为: @@ -32,7 +32,7 @@ fluid_inference └── version.txt # 版本和编译信息 ``` -**注意:** 预编译版本除`nv-jetson-cuda10-cudnn7.5-trt5` 以外其它包都是基于`GCC 4.8.5`编译,使用高版本`GCC`可能存在 `ABI`兼容性问题,建议降级或[自行编译预测库](https://www.paddlepaddle.org.cn/documentation/docs/zh/advanced_guide/inference_deployment/inference/build_and_install_lib_cn.html)。 +**注意:** 预编译版本除`nv-jetson-cuda10-cudnn7.5-trt5` 以外其它包都是基于`GCC 4.8.5`编译,使用高版本`GCC`可能存在 `ABI`兼容性问题,建议降级或[自行编译预测库](https://www.paddlepaddle.org.cn/documentation/docs/zh/advanced_guide/inference_deployment/inference/build_and_install_lib_cn.html#id12)。 ### Step4: 编译 @@ -74,7 +74,6 @@ make sh ./scripts/build.sh ``` - ### Step5: 预测及可视化 编译成功后,预测demo的可执行程序分别为`build/detector`,`build/classifer`,`build/segmenter`,用户可根据自己的模型类型选择,其主要命令参数说明如下: @@ -87,28 +86,31 @@ make | gpu_id | GPU 设备ID, 默认值为0 | | save_dir | 保存可视化结果的路径, 默认值为"output",classfier无该参数 | +## 样例 + +可使用[垃圾检测模型](deploy.md#导出inference模型)中生成的`inference_model`模型和测试图片进行预测。 `样例一`: -不使用`GPU`测试图片 `/root/projects/images/test.jpeg` +不使用`GPU`测试图片 `/path/to/garbage.bmp` ```shell -./build/detector --model_dir=/root/projects/models/yolov3_darknet --image=/root/projects/images/test.jpeg +./build/detector --model_dir=/path/to/inference_model --image=/path/to/garbage.bmp --save_dir=output ``` 图片文件`可视化预测结果`会保存在`save_dir`参数设置的目录下。 `样例二`: -使用`GPU`预测多个图片`/root/projects/image_list.txt`,image_list.txt内容的格式如下: +使用`GPU`预测多个图片`/path/to/image_list.txt`,image_list.txt内容的格式如下: ``` -/root/projects/images/test.jpeg -/root/projects/images/test1.jpeg +/path/to/images/garbage1.jpeg +/path/to/images/garbage2.jpeg ... -/root/projects/images/testn.jpeg +/path/to/images/garbagen.jpeg ``` ```shell -./build/detector --model_dir=/root/projects/models/yolov3_darknet --image_list=/root/projects/images_list.txt --use_gpu=1 +./build/detector --model_dir=/path/to/models/inference_model --image_list=/root/projects/images_list.txt --use_gpu=1 --save_dir=output ``` 图片文件`可视化预测结果`会保存在`save_dir`参数设置的目录下。 diff --git a/docs/deploy_cpp_win_vs2019.md b/docs/deploy/deploy_cpp_win_vs2019.md similarity index 67% rename from docs/deploy_cpp_win_vs2019.md rename to docs/deploy/deploy_cpp_win_vs2019.md index a3ea6ee63954eb681de932716e5a44cb0fc40721..762e1bc1acd042a5b411fba96748eef28d28a0b1 100644 --- a/docs/deploy_cpp_win_vs2019.md +++ b/docs/deploy/deploy_cpp_win_vs2019.md @@ -1,8 +1,8 @@ # Visual Studio 2019 Community CMake 编译指南 +## 说明 Windows 平台下,我们使用`Visual Studio 2019 Community` 进行了测试。微软从`Visual Studio 2017`开始即支持直接管理`CMake`跨平台编译项目,但是直到`2019`才提供了稳定和完全的支持,所以如果你想使用CMake管理项目编译构建,我们推荐你使用`Visual Studio 2019`环境下构建。 - ## 前置条件 * Visual Studio 2019 * CUDA 9.0 / CUDA 10.0, CUDNN 7+ (仅在使用GPU版本的预测库时需要) @@ -16,6 +16,9 @@ Windows 平台下,我们使用`Visual Studio 2019 Community` 进行了测试 下载源代码 ```shell +d: +mkdir projects +cd projects git clone https://github.com/PaddlePaddle/PaddleX.git ``` @@ -26,14 +29,13 @@ git clone https://github.com/PaddlePaddle/PaddleX.git PaddlePaddle C++ 预测库针对不同的`CPU`和`CUDA`版本提供了不同的预编译版本,请根据实际情况下载: [C++预测库下载列表](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/advanced_guide/inference_deployment/inference/windows_cpp_inference.html) -解压后`D:\projects\fluid_inference`目录包含内容为: +解压后`D:\projects\fluid_inference*\`目录下主要包含的内容为: ``` -fluid_inference -├── paddle # paddle核心库和头文件 +├── \paddle\ # paddle核心库和头文件 | -├── third_party # 第三方依赖库和头文件 +├── \third_party\ # 第三方依赖库和头文件 | -└── version.txt # 版本和编译信息 +└── \version.txt # 版本和编译信息 ``` ### Step3: 安装配置OpenCV @@ -48,36 +50,40 @@ fluid_inference ### Step4: 使用Visual Studio 2019直接编译CMake 1. 打开Visual Studio 2019 Community,点击`继续但无需代码` -![step2](https://paddleseg.bj.bcebos.com/inference/vs2019_step1.png) + +![step2](images/vs2019_step1.png) + 2. 点击: `文件`->`打开`->`CMake` -![step2.1](https://paddleseg.bj.bcebos.com/inference/vs2019_step2.png) + +![step2.1](images/vs2019_step2.png) 选择项目代码所在路径,并打开`CMakeList.txt`: -![step2.2](https://paddleseg.bj.bcebos.com/inference/vs2019_step3.png) +![step2.2](images/vs2019_step3.png) -3. 点击:`项目`->`cpp_inference_demo的CMake设置` +3. 点击:`项目`->`PADDLEX_INFERENCE的CMake设置` -![step3](https://paddleseg.bj.bcebos.com/inference/vs2019_step4.png) +![step3](images/vs2019_step4.png) 4. 点击`浏览`,分别设置编译选项指定`CUDA`、`OpenCV`、`Paddle预测库`的路径 -三个编译参数的含义说明如下(带*表示仅在使用**GPU版本**预测库时指定, 其中CUDA库版本尽量对齐,**使用9.0、10.0版本,不使用9.2、10.1等版本CUDA库**): +依赖库路径的含义说明如下(带*表示仅在使用**GPU版本**预测库时指定, 其中CUDA库版本尽量对齐,**使用9.0、10.0版本,不使用9.2、10.1等版本CUDA库**): | 参数名 | 含义 | | ---- | ---- | -| *CUDA_LIB | CUDA的库路径 | +| *CUDA_LIB | CUDA的库路径, 注:请将CUDNN的cudnn.lib文件拷贝到CUDA_LIB路径下 | | OPENCV_DIR | OpenCV的安装路径, | -| PADDLE_DIR | Paddle预测库的路径 | +| PADDLE_DIR | Paddle c++预测库的路径 | -**注意:** 1. 使用`CPU`版预测库,请把`WITH_GPU`的勾去掉 2. 如果使用的是`openblas`版本,请把`WITH_MKL`勾去掉 -![step4](https://paddleseg.bj.bcebos.com/inference/vs2019_step5.png) +**注意:** 1. 使用`CPU`版预测库,请把`WITH_GPU`的`值`去掉勾 2. 如果使用的是`openblas`版本,请把`WITH_MKL`的`值`去掉勾 + +![step4](images/vs2019_step5.png) **设置完成后**, 点击上图中`保存并生成CMake缓存以加载变量`。 5. 点击`生成`->`全部生成` -![step6](https://paddleseg.bj.bcebos.com/inference/vs2019_step6.png) +![step6](images/vs2019_step6.png) ### Step5: 预测及可视化 @@ -85,7 +91,8 @@ fluid_inference 上述`Visual Studio 2019`编译产出的可执行文件在`out\build\x64-Release`目录下,打开`cmd`,并切换到该目录: ``` -cd D:\projects\PaddleX\inference\out\build\x64-Release +d: +cd D:\projects\PaddleX\deploy\cpp\out\build\x64-Release ``` 编译成功后,预测demo的入口程序为`detector`,`classifer`,`segmenter`,用户可根据自己的模型类型选择,其主要命令参数说明如下: @@ -100,12 +107,16 @@ cd D:\projects\PaddleX\inference\out\build\x64-Release | save_dir | 保存可视化结果的路径, 默认值为"output",classfier无该参数 | +## 样例 + +可使用[垃圾检测模型](deploy.md#导出inference模型)中生成的`inference_model`模型和测试图片进行预测。 + `样例一`: -不使用`GPU`测试图片 `D:\\images\\test.jpeg` +不使用`GPU`测试图片 `\\path\\to\\garbage.bmp` ```shell -.\detector --model_dir=D:\\models\\yolov3_darknet --image=D:\\images\\test.jpeg +.\detector --model_dir=\\path\\to\\inference_model --image=D:\\images\\garbage.bmp --save_dir=output ``` 图片文件`可视化预测结果`会保存在`save_dir`参数设置的目录下。 @@ -113,15 +124,15 @@ cd D:\projects\PaddleX\inference\out\build\x64-Release `样例二`: -使用`GPU`预测多个图片`D:\\images\\image_list.txt`,image_list.txt内容的格式如下: +使用`GPU`预测多个图片`\\path\\to\\image_list.txt`,image_list.txt内容的格式如下: ``` -D:\\images\\test.jpeg -D:\\images\\test1.jpeg +\\path\\to\\images\\garbage1.jpeg +\\path\\to\\images\\garbage2.jpeg ... -D:\\images\\testn.jpeg +\\path\\to\\images\\garbagen.jpeg ``` ```shell -.\detector --model_dir=D:\\models\\yolov3_darknet --image_list=D:\\images\\images_list.txt --use_gpu=1 +.\detector --model_dir=\\path\\to\\inference_model --image_list=\\path\\to\\images_list.txt --use_gpu=1 --save_dir=output ``` 图片文件`可视化预测结果`会保存在`save_dir`参数设置的目录下。 diff --git a/docs/deploy/images/vs2019_step1.png b/docs/deploy/images/vs2019_step1.png new file mode 100644 index 0000000000000000000000000000000000000000..58fdf2fd624f3c2d26f7c78814c4a67cc323e495 Binary files /dev/null and b/docs/deploy/images/vs2019_step1.png differ diff --git a/docs/deploy/images/vs2019_step2.png b/docs/deploy/images/vs2019_step2.png new file mode 100644 index 0000000000000000000000000000000000000000..f1b5fd0a1c83c3008e2953a84164932140b104bf Binary files /dev/null and b/docs/deploy/images/vs2019_step2.png differ diff --git a/docs/deploy/images/vs2019_step3.png b/docs/deploy/images/vs2019_step3.png new file mode 100644 index 0000000000000000000000000000000000000000..943e861aaa1496cdb6693fb973cce13600122985 Binary files /dev/null and b/docs/deploy/images/vs2019_step3.png differ diff --git a/docs/deploy/images/vs2019_step4.png b/docs/deploy/images/vs2019_step4.png new file mode 100644 index 0000000000000000000000000000000000000000..102cb81ac911c810bdf24e86b42ece307ffd1f8a Binary files /dev/null and b/docs/deploy/images/vs2019_step4.png differ diff --git a/docs/deploy/images/vs2019_step5.png b/docs/deploy/images/vs2019_step5.png new file mode 100644 index 0000000000000000000000000000000000000000..0986e823812e2316c4fd0f2e6cb260a1204fda40 Binary files /dev/null and b/docs/deploy/images/vs2019_step5.png differ diff --git a/docs/deploy/images/vs2019_step6.png b/docs/deploy/images/vs2019_step6.png new file mode 100644 index 0000000000000000000000000000000000000000..86a8039cbd2a9f8fb499ed72d386b5c02b30c86c Binary files /dev/null and b/docs/deploy/images/vs2019_step6.png differ