In this tutorial, we will introduce the detailed steps of deploying PaddleClas models on the server side.
Visual Studio 2019 Community
is supported. In addition, you can refer to How to use PaddleDetection to make a complete project to compile by generating the sln solution
.wget https://github.com/opencv/opencv/archive/3.4.7.tar.gz
tar -xf 3.4.7.tar.gz
Finally, you can see the folder of opencv-3.4.7/
in the current directory.
root_path
) and installation path (install_path
) should be set by yourself. Among them, root_path
is the downloaded opencv source code path, and install_path
is the installation path of opencv. In this case, the opencv source is ./opencv-3.4.7
.cd ./opencv-3.4.7
export root_path=$PWD
export install_path=${root_path}/opencv3
rm -rf build
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=${install_path} \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DWITH_IPP=OFF \
-DBUILD_IPP_IW=OFF \
-DWITH_LAPACK=OFF \
-DWITH_EIGEN=OFF \
-DCMAKE_INSTALL_LIBDIR=lib64 \
-DWITH_ZLIB=ON \
-DBUILD_ZLIB=ON \
-DWITH_JPEG=ON \
-DBUILD_JPEG=ON \
-DWITH_PNG=ON \
-DBUILD_PNG=ON \
-DWITH_TIFF=ON \
-DBUILD_TIFF=ON
make -j
make install
make install
is completed, the opencv header file and library file will be generated in this folder for later PaddleClas source code compilation.Take opencv3.4.7 for example, the final file structure under the opencv installation path is as follows. NOTICE:The following file structure may be different for different Versions of Opencv.
opencv3/
|-- bin
|-- include
|-- lib64
|-- share
git clone https://github.com/PaddlePaddle/Paddle.git
rm -rf build
mkdir build
cd build
cmake .. \
-DWITH_CONTRIB=OFF \
-DWITH_MKL=ON \
-DWITH_MKLDNN=ON \
-DWITH_TESTING=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DWITH_INFERENCE_API_TEST=OFF \
-DON_INFER=ON \
-DWITH_PYTHON=ON
make -j
make inference_lib_dist
For more compilation parameter options, please refer to the official website of the Paddle C++ inference library:https://www.paddlepaddle.org.cn/documentation/docs/en/advanced_guide/inference_deployment/inference/build_and_install_lib_en.html.
build/fluid_inference_install_dir/
.build/fluid_inference_install_dir/
|-- CMakeCache.txt
|-- paddle
|-- third_party
|-- version.txt
Among them, paddle
is the Paddle library required for C++ prediction later, and version.txt
contains the version information of the current inference library.
Different cuda versions of the Linux inference library (based on GCC 4.8.2) are provided on the Paddle Inference Library official website. You can view and select the appropriate version of the inference library on the official website.
After downloading, use the following method to uncompress.
tar -xf fluid_inference.tgz
Finally you can see the following files in the folder of fluid_inference/
.
inference
directory, the directory structure is as follows.inference/
|--model
|--params
NOTICE: Among them, model
file stores the model structure information and the params
file stores the model parameter information.Therefore, you could rename the files name exported by Model inference.
sh tools/build.sh
Specifically, the content in tools/build.sh
is as follows.
OPENCV_DIR=your_opencv_dir
LIB_DIR=your_paddle_inference_dir
CUDA_LIB_DIR=your_cuda_lib_dir
CUDNN_LIB_DIR=your_cudnn_lib_dir
BUILD_DIR=build
rm -rf ${BUILD_DIR}
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
cmake .. \
-DPADDLE_LIB=${LIB_DIR} \
-DWITH_MKL=ON \
-DDEMO_NAME=ocr_system \
-DWITH_GPU=OFF \
-DWITH_STATIC_LIB=OFF \
-DUSE_TENSORRT=OFF \
-DOPENCV_DIR=${OPENCV_DIR} \
-DCUDNN_LIB=${CUDNN_LIB_DIR} \
-DCUDA_LIB=${CUDA_LIB_DIR} \
make -j
In the above parameters of command:
OPENCV_DIR
is the opencv installation path;
LIB_DIR
is the download (fluid_inference
folder) or the generated Paddle Inference Library path (build/fluid_inference_install_dir
folder);
CUDA_LIB_DIR
is the cuda library file path, in docker; it is /usr/local/cuda/lib64
;
CUDNN_LIB_DIR
is the cudnn library file path, in docker it is /usr/lib/x86_64-linux-gnu/
.
After the compilation is completed, an executable file named ocr_system
will be generated in the build
folder.
sh tools/run.sh
class id
represents the id corresponding to the category with the highest confidence, and score
represents the probability that the image belongs to that category.此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。