hello world of FastDeploy (C++)

Environmental preparation

  • CUDA >= 11.2
  • cuDNN >= 8.0
  • python >= 3.6
  • Linux(x64)

Download FastDeploy C++ SDK

wget https://bj.bcebos.com/fastdeploy/release/cpp/fastdeploy-linux-x64-gpu-1.0.6.tgz
tar -xzvf fastdeploy-linux-x64-gpu-1.0.6.tgz

Get model and test images

wget https://bj.bcebos.com/paddlehub/fastdeploy/ppyoloe_crn_l_300e_coco.tgz
wget https://bj.bcebos.com/fastdeploy/tests/test_det.jpg
tar xvf ppyoloe_crn_l_300e_coco.tgz

Prepare CMakeList.txt

cmake_minimum_required(VERSION 3.0.0)
project(ppyoloe VERSION 0.1.0)

include(CTest)
enable_testing()

include(/mnt/c/yp/lib/fastdeploy_cpp_sdk/FastDeploy.cmake)
# 添加FastDeploy依赖头文件
include_directories(${FASTDEPLOY_INCS})

# opencv
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(ppyoloe main.cpp)

target_link_libraries(ppyoloe ${FASTDEPLOY_LIBS} ${OpenCV_LIBS})

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

Prepare C++ inference code

main.cpp

#include <stdio.h>
#include <iostream>
#include <string>

#include "fastdeploy/vision.h"
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main() {
    
    
  std::string model_file = "/mnt/c/yp/fastDeploy/ppyoloe/ppyoloe_crn_l_300e_coco/model.pdmodel";
  std::string params_file = "/mnt/c/yp/fastDeploy/ppyoloe/ppyoloe_crn_l_300e_coco/model.pdiparams";
  std::string infer_cfg_file = "/mnt/c/yp/fastDeploy/ppyoloe/ppyoloe_crn_l_300e_coco/infer_cfg.yml";
  // 模型推理的配置信息
  fastdeploy::RuntimeOption option;
  auto model = fastdeploy::vision::detection::PPYOLOE(model_file, params_file, infer_cfg_file, option);

  assert(model.Initialized()); // 判断模型是否初始化成功

  cv::Mat im = cv::imread("/mnt/c/yp/fastDeploy/ppyoloe/test_det.jpg");
  fastdeploy::vision::DetectionResult result;
  
  assert(model.Predict(&im, &result)); // 判断是否预测成功

  std::cout << result.Str() << std::endl;

  cv::Mat vis_im = fastdeploy::vision::Visualize::VisDetection(im, result, 0.5);
  // 可视化结果保存到本地
  cv::imwrite("vis_result.jpg", vis_im);
  std::cout << "Visualized result save in vis_result.jpg" << std::endl;
  return 0;
}

compile executable program

mkdir build && cd build && cmake .. && make -j8

run executable

./ppyoloe 

PS: If error while loading shared libraries: libxxx.so: cannot open shared object file: No such file... is displayed during execution, it means that the library path of FastDeploy was not found during program execution. You can add the library path of FastDeploy by executing the following command After entering the environment variable, re-execute the binary program.

source /Path/to/fastdeploy_cpp_sdk/fastdeploy_init.sh

insert image description here
insert image description here

possible problems

/usr/bin/ld: warning: libcudnn.so.8, needed by
/mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so,
not found (try using -rpath or -rpath-link)
/usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]' /usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]
/usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]' /usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]
/usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]' /usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]
/usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]' /usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]
/usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]' /usr/bin/ld: /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib/libnvinfer_plugin.so: undefined reference to [email protected]

Solution
Find libcudnn.so.8 find / -name libcudnn.so.8
and copy it to /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib
cp /xxx/ libcudnn.so.8 /mnt/c/yp/lib/fastdeploy_cpp_sdk/third_libs/install/tensorrt/lib

reference

https://github.com/PaddlePaddle/FastDeploy/blob/develop/docs/cn/quick_start/models/cpp.md

Guess you like

Origin blog.csdn.net/weixin_42990464/article/details/130724432