正确的方式链接到Caffe库

时间:2017-02-09 07:29:57

标签: c++ cmake caffe

我正在为我的项目使用caffe library

我的CMakeLists.txt文件如下

cmake_minimum_required(VERSION 2.6)
PROJECT(endtoendlib)
set(Caffe_DIR "/home/Softwares/Libraries/caffe-master/build/cmake")
include_directories( ${PROJECT_BINARY_DIR})

# Find Caffe
FIND_PACKAGE(Caffe REQUIRED)
# adding sources to target
add_executable(endtoendlib endtoendLstm.cpp)
target_link_libraries(endtoendlib ${Caffe_LIBS})

当我运行cmake ..时,我的错误为

CMake Warning (dev) at
 /home/Softwares/Libraries/caffe-master/build/cmake/CaffeConfig.cmake:22
 (if):
   given arguments:

     "ON"

   An argument named "ON" appears in a conditional statement.  Policy CMP0012
   is not set: if() recognizes numbers and boolean constants.  Run "cmake
   --help-policy CMP0012" for policy details.  Use the cmake_policy command to
   set the policy and suppress this warning.
 Call Stack (most recent call first):
   CMakeLists.txt:9 (FIND_PACKAGE)
 This warning is for project developers.  Use -Wno-dev to suppress it.

我该如何解决这个问题?

有没有更好的方法链接到caffe库及其配件?

1 个答案:

答案 0 :(得分:0)

对于那些使用cmake从c ++项目链接到caffe库有困难的人,以下是我可以成功使用的CMakeLists.txt。请根据您的设置更改为正确的路径。

cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0012 OLD)

PROJECT(endtoendlib)


if(ON)
  if(NOT OpenCV_FOUND)
    set(Caffe_OpenCV_CONFIG_PATH "/usr/local/share/OpenCV")
    if(Caffe_OpenCV_CONFIG_PATH)
      get_filename_component(Caffe_OpenCV_CONFIG_PATH ${Caffe_OpenCV_CONFIG_PATH} ABSOLUTE)

      if(EXISTS ${Caffe_OpenCV_CONFIG_PATH} AND NOT TARGET opencv_core)
        message(STATUS "Caffe: using OpenCV config from ${Caffe_OpenCV_CONFIG_PATH}")
        include(${Caffe_OpenCV_CONFIG_PATH}/OpenCVModules.cmake)
      endif()

    else()
      find_package(OpenCV REQUIRED)
    endif()
    unset(Caffe_OpenCV_CONFIG_PATH)
  endif()
endif()

# Compute paths
get_filename_component(Caffe_CMAKE_DIR "/home/Softwares/Libraries/caffe-master/build/cmake" PATH)
set(Caffe_INCLUDE_DIRS "/home/Softwares/Libraries/caffe-master/include")
list(APPEND Caffe_INCLUDE_DIRS "/usr/include")
list(APPEND Caffe_INCLUDE_DIRS "/usr/local/cuda-8.0/include")
list(APPEND Caffe_INCLUDE_DIRS "/usr/local/include/opencv")
list(APPEND Caffe_INCLUDE_DIRS "/usr/include/atlas")
list(APPEND Caffe_INCLUDE_DIRS "/home/Softwares/Libraries/caffe-master/build/src/")

# Our library dependencies
#if(NOT TARGET caffe AND NOT caffe_BINARY_DIR)
include("/home/Softwares/Libraries/caffe-master/build/ccmake/CaffeTargets.cmake")
#endif()

# List of IMPORTED libs created by CaffeTargets.cmake
set(Caffe_LIBRARIES "/home/Softwares/Libraries/caffe-master/build/lib/libcaffe.so")

# Definitions
set(Caffe_DEFINITIONS "-DUSE_OPENCV;-DUSE_LMDB;-DUSE_LEVELDB")

# Cuda support variables
set(Caffe_CPU_ONLY OFF)
set(Caffe_HAVE_CUDA TRUE)
set(Caffe_HAVE_CUDNN FALSE)


include_directories( ${PROJECT_BINARY_DIR} ${Caffe_INCLUDE_DIRS})

# adding sources to target
add_executable(endtoendlib endtoendLstm.cpp)
target_link_libraries(endtoendlib ${OpenCV_LIBS} ${Caffe_LIBRARIES} -lglog -lprotobuf -lboost_system)

如果您有类似关注的错误,则表示您未使用WITH_PYTHON_LAYER := 1 in Makefile.config

构建caffe
Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: ImageData (known types: AbsVal, Accuracy, ArgMax, BNLL, BatchNorm, BatchReindex, Bias, Concat, ContrastiveLoss, Convolution, Crop, Data, Deconvolution, Dropout, DummyData, ELU, Eltwise, Embed, EuclideanLoss, Exp, Filter, Flatten, HDF5Data, HDF5Output, HingeLoss, Im2col, InfogainLoss, InnerProduct, Input, LRN, LSTM, LSTMUnit, Log, MVN, MemoryData, MultinomialLogisticLoss, PReLU, Parameter, Pooling, Power, RNN, ReLU, Reduction, Reshape, SPP, Scale, Sigmoid, SigmoidCrossEntropyLoss, Silence, Slice, Softmax, SoftmaxWithLoss, Split, TanH, Threshold, Tile)