PaddleOCR cpp_infer demo build failed

uoifb46i  于 2023-02-04  发布在  其他
关注(0)|答案(6)|浏览(259)

environment: ubuntu16.04
compiler: gcc-5.4
command: sh ./tools/build.sh
error log:

-- The CXX compiler identification is GNU 5.4.0
-- The C compiler identification is GNU 5.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found OpenCV: /home/xxx/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/third-party/opencv (found suitable version "4.5.3", minimum required is "4.5.3") 
cmake cxx flags -g -o3 -fopenmp -std=c++11
cp: cannot create regular file '/usr/lib/libmklml_intel.so': Permission denied
-- Found Git: /usr/bin/git (found version "2.7.4") 
default cmake for auto_log, no need to compile
-- Configuring done
-- Generating done
-- Build files have been written to: /home/xxx/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/build
[ 12%] Building CXX object CMakeFiles/ppocr.dir/src/main.cpp.o
/usr/bin/c++ -DUSE_MKL -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/paddle/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/install/protobuf/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/install/glog/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/install/gflags/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/install/xxhash/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/install/zlib/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/boost -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/eigen3 -I/home/xxx/data3_xxx_ln/paddle-paddle-test/PaddleOCR/deploy/cpp_infer -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/install/mklml/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference/third_party/install/mkldnn/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/build/third-party/extern_autolog-src -isystem /data3/xxx/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/third-party/opencv/include/opencv4 -g -o3 -fopenmp -std=c++11 -std=gnu++11 -MD -MT CMakeFiles/ppocr.dir/src/main.cpp.o -MF CMakeFiles/ppocr.dir/src/main.cpp.o.d -o CMakeFiles/ppocr.dir/src/main.cpp.o -c /home/xxx/data3_xxx_ln/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/src/main.cpp
cc1plus: fatal error: CMakeFiles/ppocr.dir/src/main.cpp.d: No such file or directory
compilation terminated.
CMakeFiles/ppocr.dir/build.make:75: recipe for target 'CMakeFiles/ppocr.dir/src/main.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/main.cpp.o] Error 1

hurry, need help.

about CMakeLists.txt
only modified line 46

find_package(OpenCV 4.5.3 REQUIRED PATHS ${PROJECT_SOURCE_DIR}/third-party/opencv NO_DEFAULT_PATH)

about tool/build.sh

OPENCV_DIR=/home/xxx/data3_xxx_ln/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/third-party/opencv
LIB_DIR=/home/xxx/data3_xxx_ln/paddle-paddle-test/paddle_inference
CUDA_LIB_DIR=/home/xxx/data3_xxx_ln/cuda-10.2+cudnn-8.0.3_lib64
CUDNN_LIB_DIR=/home/xxx/data3_xxx_ln/cuda-10.2+cudnn-8.0.3_lib64

BUILD_DIR=build
rm -rf ${BUILD_DIR}
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
cmake .. \
    -DPADDLE_LIB=${LIB_DIR} \
    -DWITH_MKL=ON \
    -DWITH_GPU=OFF \
    -DWITH_STATIC_LIB=OFF \
    -DWITH_TENSORRT=OFF \
    -DOPENCV_DIR=${OPENCV_DIR} \
    -DCUDNN_LIB=${CUDNN_LIB_DIR} \
    -DCUDA_LIB=${CUDA_LIB_DIR} \
    -DTENSORRT_DIR=${TENSORRT_DIR} \

make -j1 VERBOSE=1
soat7uwm

soat7uwm1#

cp: cannot create regular file '/usr/lib/libmklml_intel.so': Permission denied

Maybe you should check the directory permissions.

kqqjbcuj

kqqjbcuj2#

Hi, the default compile mode is debug, when I comment and change code in the line 78 in CMakeLists.txt

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o3 ${FLAG_OPENMP} -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${FLAG_OPENMP} -std=c++11")

old err dispearred, but when I recompiled the code, new err occurs (log below):

[ 12%] Building CXX object CMakeFiles/ppocr.dir/src/main.cpp.o
/usr/bin/x86_64-linux-gnu-g++-5 -DUSE_MKL -I/paddle/include -I/third_party/install/protobuf/include -I/third_party/install/glog/include -I/third_party/install/gflags/include -I/third_party/install/xxhash/include -I/third_party/install/zlib/include -I/third_party/boost -I/third_party/eigen3 -I/home/xxx/data3_xxx_ln/paddle-paddle-test/PaddleOCR/deploy/cpp_infer -I/third_party/install/mklml/include -I/home/xxx/data3_xxx_ln/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/build/third-party/extern_autolog-src -isystem /data3/xxx/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/third-party/opencv/include/opencv4 -g -std=gnu++11 -MD -MT CMakeFiles/ppocr.dir/src/main.cpp.o -MF CMakeFiles/ppocr.dir/src/main.cpp.o.d -o CMakeFiles/ppocr.dir/src/main.cpp.o -c /home/xxx/data3_xxx_ln/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/src/main.cpp
/home/xxx/data3_xxx_ln/paddle-paddle-test/PaddleOCR/deploy/cpp_infer/src/main.cpp:15:26: fatal error: glog/logging.h: No such file or directory
compilation terminated.
CMakeFiles/ppocr.dir/build.make:75: recipe for target 'CMakeFiles/ppocr.dir/src/main.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/main.cpp.o] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/ppocr.dir/all' failed
make[1]: *** [CMakeFiles/ppocr.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

link failed ?

link_directories("${PADDLE_LIB}/third_party/install/glog/lib")

paddle-infer: https://paddle-inference-lib.bj.bcebos.com/2.0.2-gpu-cuda10.2-cudnn8-avx-mkl/paddle_inference.tgz

okay, paddle-infer only support dynamic lib, but I turn off the compilation option WITH_STATIC_LIB , so the err occurred.
And, for opencv4+, ffmpeg lib is needed on Linux platform.

here is my finally CMakeLists.txt and the demo run successfully.

project(ppocr CXX C)
cmake_minimum_required(VERSION 3.14)

option(WITH_MKL        "Compile demo with MKL/OpenBlas support, default use MKL."       ON)
option(WITH_GPU        "Compile demo with GPU/CPU, default use CPU."                    OFF)
option(WITH_STATIC_LIB "Compile demo with static/shared library, default use static."   OFF)
option(WITH_TENSORRT "Compile demo with TensorRT."   OFF)

SET(PADDLE_LIB "" CACHE PATH "Location of libraries")
SET(OPENCV_DIR "" CACHE PATH "Location of libraries")
SET(CUDA_LIB "" CACHE PATH "Location of libraries")
SET(CUDNN_LIB "" CACHE PATH "Location of libraries")
SET(TENSORRT_DIR "" CACHE PATH "Compile demo with TensorRT")

MESSAGE("PADDLE_LIB: "${PADDLE_LIB})
MESSAGE("OPENCV_DIR: "${OPENCV_DIR})
MESSAGE("CUDA_LIB: "${CUDA_LIB})
MESSAGE("CUDNN_LIB: "${CUDNN_LIB})
MESSAGE("TENSORRT_DIR: "${TENSORRT_DIR})

set(DEMO_NAME "ppocr")

macro(safe_set_static_flag)
    foreach(flag_var
        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
      if(${flag_var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
      endif(${flag_var} MATCHES "/MD")
    endforeach(flag_var)
endmacro()

if (WITH_MKL)
    ADD_DEFINITIONS(-DUSE_MKL)
endif()

if(NOT DEFINED PADDLE_LIB)
  message(FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib")
endif()

if(NOT DEFINED OPENCV_DIR)
    message(FATAL_ERROR "please set OPENCV_DIR with -DOPENCV_DIR=/path/opencv")
endif()

if (WIN32)
  include_directories("${PADDLE_LIB}/paddle/include")
  link_directories("${PADDLE_LIB}/paddle/lib")
  find_package(OpenCV REQUIRED PATHS ${OPENCV_DIR}/build/ NO_DEFAULT_PATH)

else ()
  find_package(OpenCV 4.5.3 REQUIRED PATHS ${PROJECT_SOURCE_DIR}/third-party/opencv NO_DEFAULT_PATH)
  include_directories("${PADDLE_LIB}/paddle/include")
  link_directories("${PADDLE_LIB}/paddle/lib")
  MESSAGE(STATUS "OpenCV library status:")
  MESSAGE(STATUS "    config: ${OpenCV_DIR}")
  MESSAGE(STATUS "    version: ${OpenCV_VERSION}")
  MESSAGE(STATUS "    libraries: ${OpenCV_LIBS}")
  MESSAGE(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
endif ()
include_directories(${OpenCV_INCLUDE_DIRS})
SET(FFMPEG ${PROJECT_SOURCE_DIR}/third-party/ffmpeg)
LINK_DIRECTORIES(${FFMPEG}/lib)

if (WIN32)
    add_definitions("/DGOOGLE_GLOG_DLL_DECL=")
    if(WITH_MKL)
        set(FLAG_OPENMP "/openmp")
    endif()
    set(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG} /bigobj /MTd ${FLAG_OPENMP}")
    set(CMAKE_C_FLAGS_RELEASE  "${CMAKE_C_FLAGS_RELEASE} /bigobj /MT ${FLAG_OPENMP}")
    set(CMAKE_CXX_FLAGS_DEBUG  "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MTd ${FLAG_OPENMP}")
    set(CMAKE_CXX_FLAGS_RELEASE   "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MT ${FLAG_OPENMP}")
    if (WITH_STATIC_LIB)
        safe_set_static_flag()
        add_definitions(-DSTATIC_LIB)
    endif()
    message("cmake c debug flags " ${CMAKE_C_FLAGS_DEBUG})
    message("cmake c release flags " ${CMAKE_C_FLAGS_RELEASE})
    message("cmake cxx debug flags " ${CMAKE_CXX_FLAGS_DEBUG})
    message("cmake cxx release flags " ${CMAKE_CXX_FLAGS_RELEASE})
else()
    if(WITH_MKL)
        set(FLAG_OPENMP "-fopenmp")
    endif()
    # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o3 ${FLAG_OPENMP} -std=c++11")
    # set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -o3 ${FLAG_OPENMP} -std=c++11")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${FLAG_OPENMP} -std=c++11")
    set(CMAKE_STATIC_LIBRARY_PREFIX "")
    message("cmake cxx flags" ${CMAKE_CXX_FLAGS})
endif()

if (WITH_GPU)
    if (NOT DEFINED CUDA_LIB OR ${CUDA_LIB} STREQUAL "")
        message(FATAL_ERROR "please set CUDA_LIB with -DCUDA_LIB=/path/cuda-8.0/lib64")
    endif()
    if (NOT WIN32)
        if (NOT DEFINED CUDNN_LIB)
            message(FATAL_ERROR "please set CUDNN_LIB with -DCUDNN_LIB=/path/cudnn_v7.4/cuda/lib64")
        endif()
    endif(NOT WIN32)
endif()

include_directories("${PADDLE_LIB}/third_party/install/protobuf/include ")
include_directories("${PADDLE_LIB}/third_party/install/glog/include ")
include_directories("${PADDLE_LIB}/third_party/install/gflags/include ")
include_directories("${PADDLE_LIB}/third_party/install/xxhash/include ")
include_directories("${PADDLE_LIB}/third_party/install/zlib/include ")
include_directories("${PADDLE_LIB}/third_party/boost ")
include_directories("${PADDLE_LIB}/third_party/eigen3 ")

include_directories("${CMAKE_SOURCE_DIR}/")

if (NOT WIN32)
  if (WITH_TENSORRT AND WITH_GPU)
     include_directories("${TENSORRT_DIR}/include")
     link_directories("${TENSORRT_DIR}/lib")
  endif()
endif(NOT WIN32)

link_directories("${PADDLE_LIB}/third_party/install/zlib/lib")

link_directories("${PADDLE_LIB}/third_party/install/protobuf/lib")
link_directories("${PADDLE_LIB}/third_party/install/glog/lib")
link_directories("${PADDLE_LIB}/third_party/install/gflags/lib")
link_directories("${PADDLE_LIB}/third_party/install/xxhash/lib")
link_directories("${PADDLE_LIB}/paddle/lib")

if(WITH_MKL)
  include_directories("${PADDLE_LIB}/third_party/install/mklml/include")
  if (WIN32)
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.lib
            ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5md.lib)
  else ()
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX}
            ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX})
    # execute_process(COMMAND cp -r ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX} /usr/lib)
    execute_process(COMMAND echo ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX}:$ENV{LD_LIBRARY_PATH})
  endif ()
  set(MKLDNN_PATH "${PADDLE_LIB}/third_party/install/mkldnn")
  if(EXISTS ${MKLDNN_PATH})
    include_directories("${MKLDNN_PATH}/include")
    if (WIN32)
      set(MKLDNN_LIB ${MKLDNN_PATH}/lib/mkldnn.lib)
    else ()
      set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0)
    endif ()
  endif()
else()
  if (WIN32)
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/openblas${CMAKE_STATIC_LIBRARY_SUFFIX})
  else ()
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas${CMAKE_STATIC_LIBRARY_SUFFIX})
  endif ()
endif()

# Note: libpaddle_inference_api.so/a must put before libpaddle_inference.so/a
if(WITH_STATIC_LIB)
  if(WIN32)
    set(DEPS
        ${PADDLE_LIB}/paddle/lib/paddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX})
  else()
    set(DEPS
        ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX})
  endif()
else()
  if(WIN32)
    set(DEPS
        ${PADDLE_LIB}/paddle/lib/paddle_inference${CMAKE_SHARED_LIBRARY_SUFFIX})
  else()
    set(DEPS
        ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_SHARED_LIBRARY_SUFFIX})
  endif()
endif(WITH_STATIC_LIB)

if (NOT WIN32)
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags protobuf z xxhash
        )
    if(EXISTS "${PADDLE_LIB}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
    if (EXISTS "${PADDLE_LIB}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
else()
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags_static libprotobuf xxhash)
    set(DEPS ${DEPS} libcmt shlwapi)
    if (EXISTS "${PADDLE_LIB}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
    if(EXISTS "${PADDLE_LIB}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
endif(NOT WIN32)

if(WITH_GPU)
  if(NOT WIN32)
    if (WITH_TENSORRT)
      set(DEPS ${DEPS} ${TENSORRT_DIR}/lib/libnvinfer${CMAKE_SHARED_LIBRARY_SUFFIX})
      set(DEPS ${DEPS} ${TENSORRT_DIR}/lib/libnvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX})
    endif()
    set(DEPS ${DEPS} ${CUDA_LIB}/libcudart${CMAKE_SHARED_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/libcudnn${CMAKE_SHARED_LIBRARY_SUFFIX})
  else()
    set(DEPS ${DEPS} ${CUDA_LIB}/cudart${CMAKE_STATIC_LIBRARY_SUFFIX} )
    set(DEPS ${DEPS} ${CUDA_LIB}/cublas${CMAKE_STATIC_LIBRARY_SUFFIX} )
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn${CMAKE_STATIC_LIBRARY_SUFFIX})
  endif()
endif()

if (NOT WIN32)
    set(EXTERNAL_LIB "-ldl -lrt -lgomp -lz -lm -lpthread")
    set(DEPS ${DEPS} ${EXTERNAL_LIB})
endif()

set(DEPS ${DEPS} ${OpenCV_LIBS} opencv_world)

include(FetchContent)
include(external-cmake/auto-log.cmake)
include_directories(${FETCHCONTENT_BASE_DIR}/extern_autolog-src)
MESSAGE("auto-log path = "${FETCHCONTENT_BASE_DIR}/extern_autolog-src)

AUX_SOURCE_DIRECTORY(./src SRCS)
add_executable(${DEMO_NAME} ${SRCS})
# target_link_libraries(${DEMO_NAME} ${DEPS})

if (WIN32)
    # opencv
    FILE(GLOB OPENCV_LIBS ${PROJECT_SOURCE_DIR}/third-party/opencv/x64/vc16/lib/*.lib)
    FILE(GLOB OPENCV_DLLS ${PROJECT_SOURCE_DIR}/third-party/opencv/x64/vc16/bin/*.dll)
    # target link libs
    TARGET_LINK_LIBRARIES(${DEMO_NAME} PUBLIC ${OPENCV_LIBS} ${DEPS})
else ()
    # opencv
    FILE(GLOB OPENCV_LIBS ${PROJECT_SOURCE_DIR}/third-party/opencv/*.so*)
    FILE(GLOB FFMPEG_LIBS ${FFMPEG}/lib/*.so*)
    IF(WITH_STATIC_LIB) 
      TARGET_LINK_LIBRARIES(${DEMO_NAME} PUBLIC ${OPENCV_LIBS} ${FFMPEG_LIBS} ${DEPS})
    ELSE()
      TARGET_LINK_LIBRARIES(${DEMO_NAME} PUBLIC opencv_world ${FFMPEG_LIBS} ${DEPS})
    ENDIF()
endif ()

if (WIN32 AND WITH_MKL)
    add_custom_command(TARGET ${DEMO_NAME} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.dll ./mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5md.dll ./libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mkldnn/lib/mkldnn.dll ./mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.dll ./release/mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5md.dll ./release/libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mkldnn/lib/mkldnn.dll ./release/mkldnn.dll
    )
endif()

output log:

You are using Paddle compiled with TensorRT, but TensorRT dynamic library is not found. Ignore this if TensorRT is not needed.
mode: det
total images num: 1
WARNING: Logging before InitGoogleLogging() is written to STDERR
I1119 12:18:18.280086 38939 analysis_predictor.cc:155] Profiler is deactivated, and no profiling report will be generated.
--- Running analysis [ir_graph_build_pass]
--- Running analysis [ir_graph_clean_pass]
--- Running analysis [ir_analysis_pass]
--- Running IR pass [simplify_with_basic_ops_pass]
--- Running IR pass [attention_lstm_fuse_pass]
--- Running IR pass [seqconv_eltadd_relu_fuse_pass]
--- Running IR pass [seqpool_cvm_concat_fuse_pass]
--- Running IR pass [mul_lstm_fuse_pass]
--- Running IR pass [fc_gru_fuse_pass]
--- Running IR pass [mul_gru_fuse_pass]
--- Running IR pass [seq_concat_fc_fuse_pass]
--- Running IR pass [squeeze2_matmul_fuse_pass]
--- Running IR pass [reshape2_matmul_fuse_pass]
--- Running IR pass [flatten2_matmul_fuse_pass]
--- Running IR pass [map_matmul_to_mul_pass]
--- Running IR pass [fc_fuse_pass]
--- Running IR pass [repeated_fc_relu_fuse_pass]
--- Running IR pass [squared_mat_sub_fuse_pass]
--- Running IR pass [conv_bn_fuse_pass]
I1119 12:18:18.825546 38939 graph_pattern_detector.cc:101] ---  detected 24 subgraphs
--- Running IR pass [conv_eltwiseadd_bn_fuse_pass]
--- Running IR pass [conv_transpose_bn_fuse_pass]
--- Running IR pass [conv_transpose_eltwiseadd_bn_fuse_pass]
I1119 12:18:18.839941 38939 graph_pattern_detector.cc:101] ---  detected 1 subgraphs
--- Running IR pass [is_test_pass]
--- Running IR pass [runtime_context_cache_pass]
--- Running analysis [ir_params_sync_among_devices_pass]
--- Running analysis [adjust_cudnn_workspace_size_pass]
--- Running analysis [inference_op_replace_pass]
--- Running analysis [memory_optimize_pass]
I1119 12:18:18.845275 38939 memory_optimize_pass.cc:201] Cluster name : conv2d_55.tmp_0  size: 819200
I1119 12:18:18.845286 38939 memory_optimize_pass.cc:201] Cluster name : conv2d_62.tmp_0  size: 1638400
I1119 12:18:18.845291 38939 memory_optimize_pass.cc:201] Cluster name : x  size: 4915200
I1119 12:18:18.845296 38939 memory_optimize_pass.cc:201] Cluster name : nearest_interp_v2_2.tmp_0  size: 26214400
I1119 12:18:18.845300 38939 memory_optimize_pass.cc:201] Cluster name : conv2d_59.tmp_0  size: 26214400
I1119 12:18:18.845304 38939 memory_optimize_pass.cc:201] Cluster name : tmp_2  size: 26214400
I1119 12:18:18.845309 38939 memory_optimize_pass.cc:201] Cluster name : conv2d_63.tmp_0  size: 6553600
I1119 12:18:18.845314 38939 memory_optimize_pass.cc:201] Cluster name : nearest_interp_v2_5.tmp_0  size: 6553600
--- Running analysis [ir_graph_to_program_pass]
I1119 12:18:18.869153 38939 analysis_predictor.cc:598] ======= optimize end =======
I1119 12:18:18.869192 38939 naive_executor.cc:107] ---  skip [feed], feed -> x
I1119 12:18:18.870604 38939 naive_executor.cc:107] ---  skip [tmp_2], fetch -> fetch
WARNING: Logging before InitGoogleLogging() is written to STDERR
I1119 12:18:18.870671 38939 main.cpp:94] The predict img: ./data/1.jpg
Detected boxes num: 23
The detection visualized image saved in ./ocr_vis.png
I1119 12:18:21.244637 38939 autolog.h:50] ----------------------- Config info -----------------------
I1119 12:18:21.244679 38939 autolog.h:51] runtime_device: cpu
I1119 12:18:21.244690 38939 autolog.h:52] ir_optim: True
I1119 12:18:21.244700 38939 autolog.h:53] enable_memory_optim: True
I1119 12:18:21.244709 38939 autolog.h:54] enable_tensorrt: 0
I1119 12:18:21.244729 38939 autolog.h:55] enable_mkldnn: False
I1119 12:18:21.244737 38939 autolog.h:56] cpu_math_library_num_threads: 10
I1119 12:18:21.244747 38939 autolog.h:57] ----------------------- Data info -----------------------
I1119 12:18:21.244757 38939 autolog.h:58] batch_size: 1
I1119 12:18:21.244767 38939 autolog.h:59] input_shape: dynamic
I1119 12:18:21.244776 38939 autolog.h:60] data_num: 1
I1119 12:18:21.244786 38939 autolog.h:61] ----------------------- Model info -----------------------
I1119 12:18:21.244796 38939 autolog.h:62] model_name: ocr_det
I1119 12:18:21.244805 38939 autolog.h:63] precision: fp32
I1119 12:18:21.244814 38939 autolog.h:64] ----------------------- Perf info ------------------------
I1119 12:18:21.244824 38939 autolog.h:65] Total time spent(ms): 2239
I1119 12:18:21.244834 38939 autolog.h:67] preprocess_time(ms): 53.6787, inference_time(ms): 2069.26, postprocess_time(ms): 117.04

New questions:
1.What does the log text "Profiler is deactivated, and no profiling report will be generated." mean ?

0aydgbwb

0aydgbwb3#

(训练是在conda环境下,这里的部署也就没有在docker环境下)
编译PaddleOCR C++预测demo,运行

sh tools/build.sh

报错如下:

-- The CXX compiler identification is GNU 5.4.0
-- The C compiler identification is GNU 5.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found OpenCV: /home/chenying/PaddleOCR/deploy/cpp_infer/opencv-3.4.7/opencv3 (found version "3.4.7")
cmake cxx flags -g -o3 -fopenmp -std=c++11
cp: cannot create regular file '/usr/lib/libmklml_intel.so': Permission denied
-- Found Git: /usr/bin/git (found version "2.7.4")
default cmake for auto_log, no need to compile
-- Configuring done
-- Generating done
-- Build files have been written to: /home/chenying/PaddleOCR/deploy/cpp_infer/build
[ 12%] Building CXX object CMakeFiles/ppocr.dir/src/main.cpp.o
[ 25%] Building CXX object CMakeFiles/ppocr.dir/src/ocr_cls.cpp.o
[ 37%] Building CXX object CMakeFiles/ppocr.dir/src/ocr_rec.cpp.o
[ 50%] Building CXX object CMakeFiles/ppocr.dir/src/ocr_det.cpp.o
[ 62%] Building CXX object CMakeFiles/ppocr.dir/src/preprocess_op.cpp.o
[ 75%] Building CXX object CMakeFiles/ppocr.dir/src/postprocess_op.cpp.o
[ 87%] Building CXX object CMakeFiles/ppocr.dir/src/utility.cpp.o
cc1plus: fatal error: CMakeFiles/ppocr.dir/src/main.cpp.d: No such file or directory
compilation terminated.
cc1plus: fatal error: CMakeFiles/ppocr.dir/src/ocr_cls.cpp.d: No such file or directory
compilation terminated.
cc1plus: fatal error: CMakeFiles/ppocr.dir/src/postprocess_op.cpp.d: No such file or directory
cc1plus: fatal error: CMakeFiles/ppocr.dir/src/ocr_rec.cpp.d: No such file or directory
compilation terminated.
cc1plus: fatal error: CMakeFiles/ppocr.dir/src/ocr_det.cpp.d: No such file or directory
compilation terminated.
compilation terminated.
cc1plus: fatal error: CMakeFiles/ppocr.dir/src/preprocess_op.cpp.d: No such file or directory
compilation terminated.
CMakeFiles/ppocr.dir/build.make:75: recipe for target 'CMakeFiles/ppocr.dir/src/main.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/main.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/ppocr.dir/build.make:131: recipe for target 'CMakeFiles/ppocr.dir/src/postprocess_op.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/postprocess_op.cpp.o] Error 1
cc1plus: fatal error: CMakeFiles/ppocr.dir/src/utility.cpp.d: No such file or directory
compilation terminated.
CMakeFiles/ppocr.dir/build.make:117: recipe for target 'CMakeFiles/ppocr.dir/src/ocr_rec.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/ocr_rec.cpp.o] Error 1
CMakeFiles/ppocr.dir/build.make:103: recipe for target 'CMakeFiles/ppocr.dir/src/ocr_det.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/ocr_det.cpp.o] Error 1
CMakeFiles/ppocr.dir/build.make:89: recipe for target 'CMakeFiles/ppocr.dir/src/ocr_cls.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/ocr_cls.cpp.o] Error 1
CMakeFiles/ppocr.dir/build.make:145: recipe for target 'CMakeFiles/ppocr.dir/src/preprocess_op.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/preprocess_op.cpp.o] Error 1
CMakeFiles/ppocr.dir/build.make:159: recipe for target 'CMakeFiles/ppocr.dir/src/utility.cpp.o' failed
make[2]: *** [CMakeFiles/ppocr.dir/src/utility.cpp.o] Error 1
CMakeFiles/Makefile2:99: recipe for target 'CMakeFiles/ppocr.dir/all' failed
make[1]: *** [CMakeFiles/ppocr.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
hof1towb

hof1towb4#

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o3 ${FLAG_OPENMP} -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${FLAG_OPENMP} -std=c++11")

please replace the code (in the line 78 in CMakeLists.txt)

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o3 ${FLAG_OPENMP} -std=c++11")

with

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${FLAG_OPENMP} -std=c++11")
# you can add `-o3` option
ie3xauqp

ie3xauqp5#

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o3 ${FLAG_OPENMP} -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${FLAG_OPENMP} -std=c++11")

please replace the code (in the line 78 in CMakeLists.txt)

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o3 ${FLAG_OPENMP} -std=c++11")

with

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${FLAG_OPENMP} -std=c++11")
# you can add `-o3` option

非常感谢,Thank you very much!
使用

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} ${FLAG_OPENMP} -std=c++11")

成功了。
输出如下:

-- The CXX compiler identification is GNU 5.4.0
-- The C compiler identification is GNU 5.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found OpenCV: /home/chenying/PaddleOCR/deploy/cpp_infer/tmp/opencv-3.4.7/opencv3 (found version "3.4.7")
cmake cxx flags -fopenmp -std=c++11
cp: cannot create regular file '/usr/lib/libmklml_intel.so': Permission denied
-- Found Git: /usr/bin/git (found version "2.33.1")
default cmake for auto_log, no need to compile
end
-- Configuring done
-- Generating done
-- Build files have been written to: /home/chenying/PaddleOCR/deploy/cpp_infer/build
[ 12%] Building CXX object CMakeFiles/ppocr.dir/src/main.cpp.o
[ 25%] Building CXX object CMakeFiles/ppocr.dir/src/ocr_cls.cpp.o
[ 37%] Building CXX object CMakeFiles/ppocr.dir/src/ocr_det.cpp.o
[ 50%] Building CXX object CMakeFiles/ppocr.dir/src/ocr_rec.cpp.o
[ 62%] Building CXX object CMakeFiles/ppocr.dir/src/postprocess_op.cpp.o
[ 75%] Building CXX object CMakeFiles/ppocr.dir/src/preprocess_op.cpp.o
[ 87%] Building CXX object CMakeFiles/ppocr.dir/src/utility.cpp.o
[100%] Linking CXX executable ppocr
[100%] Built target ppocr

补充:没有在docker环境下:
build.sh 内容如下:

OPENCV_DIR=/home/chenying/PaddleOCR/deploy/cpp_infer/tmp/opencv-3.4.7/opencv3
LIB_DIR=/home/chenying/PaddleOCR/deploy/cpp_infer/tmp/paddle_inference
CUDA_LIB_DIR=/usr/local/cuda/lib64
CUDNN_LIB_DIR=/usr/local/cuda/lib64

BUILD_DIR=build
rm -rf ${BUILD_DIR}
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
cmake .. \
    -DPADDLE_LIB=${LIB_DIR} \
    -DWITH_MKL=ON \
    -DWITH_GPU=ON \
    -DWITH_STATIC_LIB=OFF \
    -DWITH_TENSORRT=OFF \
    -DOPENCV_DIR=${OPENCV_DIR} \
    -DCUDNN_LIB=${CUDNN_LIB_DIR} \
    -DCUDA_LIB=${CUDA_LIB_DIR} \
    -DTENSORRT_DIR=${TENSORRT_DIR} \

make -j
ehxuflar

ehxuflar6#

Hey, guys, I have met a runtime exiting problem when running cpp_infer/main.cpp on Win64 platform. Here is my CMakeLists.txt:

project(ppocr CXX C)
cmake_minimum_required(VERSION 3.14)

option(WITH_MKL        "Compile demo with MKL/OpenBlas support, default use MKL."       ON)
option(WITH_GPU        "Compile demo with GPU/CPU, default use CPU."                    ON)
option(WITH_STATIC_LIB "Compile demo with static/shared library, default use static."   ON)
option(WITH_TENSORRT "Compile demo with TensorRT."   OFF)

SET(PADDLE_LIB "${PROJECT_SOURCE_DIR}/third-party/paddle-paddle" CACHE PATH "Location of libraries")
SET(OPENCV_DIR "${PROJECT_SOURCE_DIR}/third-party/opencv" CACHE PATH "Location of libraries")
SET(CUDA_LIB "${PROJECT_SOURCE_DIR}/third-party/cuda_cudnn" CACHE PATH "Location of libraries")
SET(CUDNN_LIB "${PROJECT_SOURCE_DIR}/third-party/cuda_cudnn" CACHE PATH "Location of libraries")
SET(TENSORRT_DIR "${PROJECT_SOURCE_DIR}/third-party/tensor_rt" CACHE PATH "Compile demo with TensorRT")

MESSAGE("WITH_MKL: ${WITH_MKL}")
MESSAGE("WITH_GPU: ${WITH_GPU}")
MESSAGE("WITH_TENSORRT: ${WITH_TENSORRT}")
MESSAGE("PADDLE_LIB: ${PADDLE_LIB}")
MESSAGE("OPENCV_DIR: ${OPENCV_DIR}")
MESSAGE("CUDA_LIB: ${CUDA_LIB}")
MESSAGE("CUDNN_LIB: ${CUDNN_LIB}")
MESSAGE("TENSORRT_DIR: ${TENSORRT_DIR}")

set(DEMO_NAME "ppocr")

# add utf-8 support on win platform
IF (WIN32)
    ADD_DEFINITIONS(/utf-8)
ENDIF ()

macro(safe_set_static_flag)
    foreach(flag_var
        CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
        CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
      if(${flag_var} MATCHES "/MD")
        string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
      endif(${flag_var} MATCHES "/MD")
    endforeach(flag_var)
endmacro()

if (WITH_MKL)
    ADD_DEFINITIONS(-DUSE_MKL)
endif()

if(NOT DEFINED PADDLE_LIB)
  message(FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib")
endif()

if(NOT DEFINED OPENCV_DIR)
    message(FATAL_ERROR "please set OPENCV_DIR with -DOPENCV_DIR=/path/opencv")
endif()

if (WIN32)
  find_package(OpenCV 4.5.3 REQUIRED PATHS ${PROJECT_SOURCE_DIR}/third-party/opencv NO_DEFAULT_PATH)
  include_directories("${PADDLE_LIB}/paddle/include")
  link_directories("${PADDLE_LIB}/paddle/lib")
  MESSAGE(STATUS "OpenCV library status:")
  MESSAGE(STATUS "    config: ${OpenCV_DIR}")
  MESSAGE(STATUS "    version: ${OpenCV_VERSION}")
  MESSAGE(STATUS "    libraries: ${OpenCV_LIBS}")
  MESSAGE(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

else ()
  find_package(OpenCV 4.5.3 REQUIRED PATHS ${PROJECT_SOURCE_DIR}/third-party/opencv NO_DEFAULT_PATH)
  include_directories("${PADDLE_LIB}/paddle/include")
  link_directories("${PADDLE_LIB}/paddle/lib")
  MESSAGE(STATUS "OpenCV library status:")
  MESSAGE(STATUS "    config: ${OpenCV_DIR}")
  MESSAGE(STATUS "    version: ${OpenCV_VERSION}")
  MESSAGE(STATUS "    libraries: ${OpenCV_LIBS}")
  MESSAGE(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
endif ()
include_directories(${OpenCV_INCLUDE_DIRS})
SET(FFMPEG ${PROJECT_SOURCE_DIR}/third-party/ffmpeg)
LINK_DIRECTORIES(${FFMPEG}/lib)

if (WIN32)
    add_definitions("/DGOOGLE_GLOG_DLL_DECL=")
    if(WITH_MKL)
        set(FLAG_OPENMP "/openmp")
    endif()
    set(CMAKE_C_FLAGS_DEBUG   "${CMAKE_C_FLAGS_DEBUG} /bigobj /MTd ${FLAG_OPENMP}")
    set(CMAKE_C_FLAGS_RELEASE  "${CMAKE_C_FLAGS_RELEASE} /bigobj /MT ${FLAG_OPENMP}")
    set(CMAKE_CXX_FLAGS_DEBUG  "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MTd ${FLAG_OPENMP}")
    set(CMAKE_CXX_FLAGS_RELEASE   "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MT ${FLAG_OPENMP}")
    if (WITH_STATIC_LIB)
        safe_set_static_flag()
        add_definitions(-DSTATIC_LIB)
    endif()
    message("cmake c debug flags " ${CMAKE_C_FLAGS_DEBUG})
    message("cmake c release flags " ${CMAKE_C_FLAGS_RELEASE})
    message("cmake cxx debug flags " ${CMAKE_CXX_FLAGS_DEBUG})
    message("cmake cxx release flags " ${CMAKE_CXX_FLAGS_RELEASE})
else()
    if(WITH_MKL)
        set(FLAG_OPENMP "-fopenmp")
    endif()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -o3 ${FLAG_OPENMP} -std=c++11")
    set(CMAKE_STATIC_LIBRARY_PREFIX "")
    message("cmake cxx flags" ${CMAKE_CXX_FLAGS})
endif()

if (WITH_GPU)
    if (NOT DEFINED CUDA_LIB OR ${CUDA_LIB} STREQUAL "")
        message(FATAL_ERROR "please set CUDA_LIB with -DCUDA_LIB=/path/cuda-8.0/lib64")
    endif()
    if (NOT WIN32)
        if (NOT DEFINED CUDNN_LIB)
            message(FATAL_ERROR "please set CUDNN_LIB with -DCUDNN_LIB=/path/cudnn_v7.4/cuda/lib64")
        endif()
    endif(NOT WIN32)
endif()

include_directories("${PADDLE_LIB}/third_party/install/protobuf/include")
include_directories("${PADDLE_LIB}/third_party/install/glog/include")
include_directories("${PADDLE_LIB}/third_party/install/gflags/include")
include_directories("${PADDLE_LIB}/third_party/install/xxhash/include")
include_directories("${PADDLE_LIB}/third_party/install/zlib/include")
include_directories("${PADDLE_LIB}/third_party/boost")
include_directories("${PADDLE_LIB}/third_party/eigen3")

include_directories("${CMAKE_SOURCE_DIR}/")

if (NOT WIN32)
  if (WITH_TENSORRT AND WITH_GPU)
     include_directories("${TENSORRT_DIR}/include")
     link_directories("${TENSORRT_DIR}/lib")
  endif()
endif(NOT WIN32)

link_directories("${PADDLE_LIB}/third_party/install/zlib/lib")

link_directories("${PADDLE_LIB}/third_party/install/protobuf/lib")
link_directories("${PADDLE_LIB}/third_party/install/glog/lib")
link_directories("${PADDLE_LIB}/third_party/install/gflags/lib")
link_directories("${PADDLE_LIB}/third_party/install/xxhash/lib")
link_directories("${PADDLE_LIB}/paddle/lib")

if(WITH_MKL)
  include_directories("${PADDLE_LIB}/third_party/install/mklml/include")
  if (WIN32)
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.lib
            ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5md.lib)
  else ()
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX}
            ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX})
    execute_process(COMMAND cp -r ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel${CMAKE_SHARED_LIBRARY_SUFFIX} /usr/lib)
  endif ()
  set(MKLDNN_PATH "${PADDLE_LIB}/third_party/install/mkldnn")
  if(EXISTS ${MKLDNN_PATH})
    include_directories("${MKLDNN_PATH}/include")
    if (WIN32)
      set(MKLDNN_LIB ${MKLDNN_PATH}/lib/mkldnn.lib)
    else ()
      set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0)
    endif ()
  endif()
else()
  if (WIN32)
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/openblas${CMAKE_STATIC_LIBRARY_SUFFIX})
  else ()
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas${CMAKE_STATIC_LIBRARY_SUFFIX})
  endif ()
endif()

# Note: libpaddle_inference_api.so/a must put before libpaddle_inference.so/a
if(WITH_STATIC_LIB)
  if(WIN32)
    set(DEPS
        ${PADDLE_LIB}/paddle/lib/paddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX})
  else()
    set(DEPS
        ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_STATIC_LIBRARY_SUFFIX})
  endif()
else()
  if(WIN32)
    set(DEPS
        ${PADDLE_LIB}/paddle/lib/paddle_inference${CMAKE_SHARED_LIBRARY_SUFFIX})
  else()
    set(DEPS
        ${PADDLE_LIB}/paddle/lib/libpaddle_inference${CMAKE_SHARED_LIBRARY_SUFFIX})
  endif()
endif(WITH_STATIC_LIB)

if (NOT WIN32)
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags protobuf z xxhash
        )
    if(EXISTS "${PADDLE_LIB}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
    if (EXISTS "${PADDLE_LIB}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
else()
    set(DEPS ${DEPS}
        ${MATH_LIB} ${MKLDNN_LIB}
        glog gflags_static libprotobuf xxhash)
    set(DEPS ${DEPS} libcmt shlwapi)
    if (EXISTS "${PADDLE_LIB}/third_party/install/snappy/lib")
        set(DEPS ${DEPS} snappy)
    endif()
    if(EXISTS "${PADDLE_LIB}/third_party/install/snappystream/lib")
        set(DEPS ${DEPS} snappystream)
    endif()
endif(NOT WIN32)

if(WITH_GPU)
  if(NOT WIN32)
    if (WITH_TENSORRT)
      set(DEPS ${DEPS} ${TENSORRT_DIR}/lib/libnvinfer${CMAKE_SHARED_LIBRARY_SUFFIX})
      set(DEPS ${DEPS} ${TENSORRT_DIR}/lib/libnvinfer_plugin${CMAKE_SHARED_LIBRARY_SUFFIX})
    endif()
    set(DEPS ${DEPS} ${CUDA_LIB}/libcudart${CMAKE_SHARED_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/libcudnn${CMAKE_SHARED_LIBRARY_SUFFIX})
  else()
    set(DEPS ${DEPS} ${CUDA_LIB}/cudart${CMAKE_STATIC_LIBRARY_SUFFIX} )
    set(DEPS ${DEPS} ${CUDA_LIB}/cublas${CMAKE_STATIC_LIBRARY_SUFFIX} )
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn${CMAKE_STATIC_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn_ops_infer${CMAKE_STATIC_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn_ops_infer64_8${CMAKE_STATIC_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn_cnn_infer${CMAKE_STATIC_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn_cnn_infer64_8${CMAKE_STATIC_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn_adv_infer${CMAKE_STATIC_LIBRARY_SUFFIX})
    set(DEPS ${DEPS} ${CUDNN_LIB}/cudnn_adv_infer64_8${CMAKE_STATIC_LIBRARY_SUFFIX})
  endif()
endif()

if (NOT WIN32)
    set(EXTERNAL_LIB "-ldl -lrt -lgomp -lz -lm -lpthread")
    set(DEPS ${DEPS} ${EXTERNAL_LIB})
endif()

set(DEPS ${DEPS} ${OpenCV_LIBS})

include(FetchContent)
include(external-cmake/auto-log.cmake)
include_directories(${FETCHCONTENT_BASE_DIR}/extern_autolog-src)

AUX_SOURCE_DIRECTORY(./src SRCS)
add_executable(${DEMO_NAME} ${SRCS})
# target_link_libraries(${DEMO_NAME} ${DEPS})

if (WIN32)
    # opencv
    FILE(GLOB OPENCV_LIBS ${PROJECT_SOURCE_DIR}/third-party/opencv/x64/vc16/lib/*.lib)
    FILE(GLOB OPENCV_DLLS ${PROJECT_SOURCE_DIR}/third-party/opencv/x64/vc16/bin/*.dll)
    MESSAGE("OPENCV_DLLS = ${OPENCV_DLLS}")
    # target link libs
    TARGET_LINK_LIBRARIES(${DEMO_NAME} PUBLIC ${OPENCV_LIBS} ${DEPS})
else ()
    # opencv
    FILE(GLOB OPENCV_LIBS ${PROJECT_SOURCE_DIR}/third-party/opencv/*.so*)
    FILE(GLOB FFMPEG_LIBS ${FFMPEG}/lib/*.so*)
    IF(WITH_STATIC_LIB) 
      TARGET_LINK_LIBRARIES(${DEMO_NAME} PUBLIC ${OPENCV_LIBS} ${FFMPEG_LIBS} ${DEPS})
    ELSE()
      TARGET_LINK_LIBRARIES(${DEMO_NAME} PUBLIC opencv_world ${FFMPEG_LIBS} ${DEPS})
    ENDIF()
endif ()

if (WIN32 AND WITH_MKL)
    FILE(GLOB CUDA_DLLS ${CUDA_LIB}/lib/*.dll)
    MESSAGE("CUDA_DLLS = ${CUDA_DLLS}")
    add_custom_command(TARGET ${DEMO_NAME} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.dll ./mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5md.dll ./libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mkldnn/lib/mkldnn.dll ./mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.dll ./release/mklml.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mklml/lib/libiomp5md.dll ./release/libiomp5md.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/third_party/install/mkldnn/lib/mkldnn.dll ./release/mkldnn.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PADDLE_LIB}/paddle/lib/paddle_inference.dll ./release/paddle_inference.dll
        COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CUDA_DLLS} ./release/
    )
endif()

Here is tool/build.bat

:: win project build
echo off
set cur_path=%cd%

if not exist %cur_path%\build (
    echo %cur_path%\build does not exist
    md %cur_path%\build 
)
cd %cur_path%\build
:: echo clean build cache
:: del CMakeCache.txt
:: if compile is MSVC-2017
::   cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Release ..
:: else
echo ------------------------------------------------------------------------------------------------
echo Configure Start 
cmake .. -DCMAKE_BUILD_TYPE=Release -DOCR_MKL=ON -DOCR_GPU=ON -DOCR_STATIC_LIB=OFF -DOCR_TENSORRT=ON
echo Configure Done 

echo ------------------------------------------------------------------------------------------------
echo Build Start
cmake --build . --config=Release --parallel=8
echo Build Done
:: cmake --install . --config=Release

:: you can also use your local path if is needed
:: CUDA_LIB_DIR=/home/xxx/cuda-10.2+cudnn-8.0.3_lib64
:: CUDNN_LIB_DIR=/home/xxx/cuda-10.2+cudnn-8.0.3_lib64
:: CUDNN_LIB_DIR=/home/xxx/cuda-10.2+cudnn-8.0.3_lib64

env:
win10
cuda11+cudnn8
paddle-paddle-2.0.2 https://paddle-wheel.bj.bcebos.com/2.0.2/win-infer/trt_mkl/post11/paddle_inference.zip
tensorrt 7.2.3.4
opencv 4.5.3

running cmd & logs

any suggestions ?

相关问题