Introduction
Caffe is a deep learning framework made with expression, speed, and modularity in mind.
Ref: http://caffe.berkeleyvision.org/
Usage
module load caffe/caffe
Installation
module load cmake/3.5.0 module load octave/3.8.0 module load boost/1.60.0 module load opencv/3.1.0 module load library/hdf5/1.8.7 #module load cuda/7.5.18 module load caffe/gflags/gflags module load caffe/glog/0.3.3 module load caffe/leveldb/leveldb module load caffe/lmdb/lmdb module load caffe/protobuf/protobuf module load caffe/snappy/snappy module load python/2.7.1-shared module load library/atlas/3.10.2 module load matlab/2015b cd /sw/caffe unzip caffe-master.zip cd /sw/caffe/caffe-master mkdir build
Compilation issues on RHEL 6.5
OpenCV issues
The following needed to be done with openCV to make it compile on RGEL/Centos 6.5 - Try to find OpenCV (using pkg-config) cd /sw/caffe/caffe-master/cmake/Modules vi FindOpenCV.cmake <<<<<< # # If OpenCV was installed in a non-defaul location, set OpenCV_DIR # # Once done, this will define # # OpenCV_FOUND - system has OpenCV # OpenCV_INCLUDE_DIRS - the OpenCV include directories # OpenCV_LIBRARIES - link these to use OpenCV # OpenCV_LIBRARY_DIRS - the OpenCV library directories # # Created: 10 Jan 2012 by bermaw (bermaw at gmail.com) SET("OpenCV_DIR" "/sw/opencv/opencv-3.1.0") SET(ENV{PKG_CONFIG_PATH} ${OpenCV_DIR}/lib/pkgconfig) FIND_PACKAGE(PkgConfig REQUIRED) pkg_check_modules(OpenCV REQUIRED opencv) #--- OpenCV (with pkgconfig) find_package(PkgConfig REQUIRED) pkg_check_modules(OPENCV REQUIRED opencv) # https://bugs.freedesktop.org/show_bug.cgi?id=82245 # list(APPEND LIBRARIES ${OPENCV_LIBRARIES}) list(APPEND LIBRARIES ${OPENCV_LDFLAGS}) message(STATUS LIBS ${OPENCV_VERSION}) include_directories(${OPENCV_INCLUDE_DIRS}) >>>>>>>>>>>>>>>>>
Here is the module file for opencv which included 3rdParty Software
module display opencv/3.1.0 ------------------------------------------------------------------- /sw/com/modulefiles/opencv/3.1.0: setenv OpenCV_DIR /sw/opencv/opencv-3.1.0 setenv OPENCV_INCLUDE_INSTALL_PATH /sw/opencv/opencv-3.1.0/include setenv OpenCV_LIB_PATH /sw/opencv/opencv-3.1.0/lib setenv OpenCV_INCLUDE_DIRS /sw/opencv/opencv-3.1.0/include:/sw/opencv/opencv-3.1.0/include/opencv:/sw/opencv/opencv-3.1.0/include/opencv2 prepend-path MANPATH /sw/opencv/opencv-3.1.0/share/OpenCV prepend-path LIBRARY_PATH /sw/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx/lib/intel64:/sw/opencv/opencv-3.1.0/lib:/sw/opencv/opencv-3.1.0/lib/pkgconfig prepend-path FPATH /sw/opencv/opencv-3.1.0/include:/sw/opencv/opencv-3.1.0/3rdparty/include/opencl/1.2/CL:/sw/opencv/opencv-3.1.0/3rdparty/include:/sw/opencv/opencv-3.1.0/3rdparty/include/dshow:/sw/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx/include:/sw/opencv/opencv-3.1.0/3rdparty/libjasper:/sw/opencv/opencv-3.1.0/3rdparty/libjasper/jasper:/sw/opencv/opencv-3.1.0/3rdparty/libjpeg:/sw/opencv/opencv-3.1.0/3rdparty/libpng:/sw/opencv/opencv-3.1.0/3rdparty/libtiff:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/cpu-features:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dec:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dsp:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/enc:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/mux:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/utils:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/webp:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Half:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmThread:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Iex:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmImf:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Imath:/sw/opencv/opencv-3.1.0/3rdparty/tbb:/sw/opencv/opencv-3.1.0/3rdparty/zlib prepend-path LD_LIBRARY_PATH /sw/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx/lib/intel64:/sw/opencv/opencv-3.1.0/lib prepend-path CPATH /sw/opencv/opencv-3.1.0/include:/sw/opencv/opencv-3.1.0/include/opencv:/sw/opencv/opencv-3.1.0/include/opencv2:/sw/opencv/opencv-3.1.0/3rdparty/include/opencl/1.2/CL:/sw/opencv/opencv-3.1.0/3rdparty/include:/sw/opencv/opencv-3.1.0/3rdparty/include/dshow:/sw/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx/include:/sw/opencv/opencv-3.1.0/3rdparty/libjasper:/sw/opencv/opencv-3.1.0/3rdparty/libjasper/jasper:/sw/opencv/opencv-3.1.0/3rdparty/libjpeg:/sw/opencv/opencv-3.1.0/3rdparty/libpng:/sw/opencv/opencv-3.1.0/3rdparty/libtiff:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/cpu-features:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dec:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dsp:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/enc:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/mux:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/utils:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/webp:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Half:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmThread:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Iex:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmImf:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Imath:/sw/opencv/opencv-3.1.0/3rdparty/tbb:/sw/opencv/opencv-3.1.0/3rdparty/zlib prepend-path C_INCLUDE_PATH /sw/opencv/opencv-3.1.0/include:/sw/opencv/opencv-3.1.0/include/opencv:/sw/opencv/opencv-3.1.0/include/opencv2:/sw/opencv/opencv-3.1.0/3rdparty/include/opencl/1.2/CL:/sw/opencv/opencv-3.1.0/3rdparty/include:/sw/opencv/opencv-3.1.0/3rdparty/include/dshow:/sw/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx/include:/sw/opencv/opencv-3.1.0/3rdparty/libjasper:/sw/opencv/opencv-3.1.0/3rdparty/libjasper/jasper:/sw/opencv/opencv-3.1.0/3rdparty/libjpeg:/sw/opencv/opencv-3.1.0/3rdparty/libpng:/sw/opencv/opencv-3.1.0/3rdparty/libtiff:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/cpu-features:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dec:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dsp:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/enc:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/mux:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/utils:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/webp:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Half:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmThread:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Iex:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmImf:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Imath:/sw/opencv/opencv-3.1.0/3rdparty/tbb:/sw/opencv/opencv-3.1.0/3rdparty/zlib prepend-path CPLUS_INCLUDE_PATH /sw/opencv/opencv-3.1.0/include:/sw/opencv/opencv-3.1.0/include/opencv:/sw/opencv/opencv-3.1.0/include/opencv2:/sw/opencv/opencv-3.1.0/3rdparty/include/opencl/1.2/CL:/sw/opencv/opencv-3.1.0/3rdparty/include:/sw/opencv/opencv-3.1.0/3rdparty/include/dshow:/sw/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx/include:/sw/opencv/opencv-3.1.0/3rdparty/libjasper:/sw/opencv/opencv-3.1.0/3rdparty/libjasper/jasper:/sw/opencv/opencv-3.1.0/3rdparty/libjpeg:/sw/opencv/opencv-3.1.0/3rdparty/libpng:/sw/opencv/opencv-3.1.0/3rdparty/libtiff:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/cpu-features:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dec:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dsp:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/enc:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/mux:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/utils:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/webp:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Half:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmThread:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Iex:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmImf:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Imath:/sw/opencv/opencv-3.1.0/3rdparty/tbb:/sw/opencv/opencv-3.1.0/3rdparty/zlib prepend-path INCLUDE /sw/opencv/opencv-3.1.0/include:/sw/opencv/opencv-3.1.0/include/opencv:/sw/opencv/opencv-3.1.0/include/opencv2:/sw/opencv/opencv-3.1.0/3rdparty/include/opencl/1.2/CL:/sw/opencv/opencv-3.1.0/3rdparty/include:/sw/opencv/opencv-3.1.0/3rdparty/include/dshow:/sw/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx/include:/sw/opencv/opencv-3.1.0/3rdparty/libjasper:/sw/opencv/opencv-3.1.0/3rdparty/libjasper/jasper:/sw/opencv/opencv-3.1.0/3rdparty/libjpeg:/sw/opencv/opencv-3.1.0/3rdparty/libpng:/sw/opencv/opencv-3.1.0/3rdparty/libtiff:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/cpu-features:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dec:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/dsp:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/enc:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/mux:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/utils:/sw/opencv/opencv-3.1.0/3rdparty/libwebp/webp:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Half:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmThread:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Iex:/sw/opencv/opencv-3.1.0/3rdparty/openexr/IlmImf:/sw/opencv/opencv-3.1.0/3rdparty/openexr/Imath:/sw/opencv/opencv-3.1.0/3rdparty/tbb:/sw/opencv/opencv-3.1.0/3rdparty/zlib prepend-path PATH /sw/opencv/opencv-3.1.0/bin:/sw/opencv/opencv-3.1.0/share/OpenCV/:/sw/opencv/opencv-3.1.0/cmake prepend-path PKG_CONFIG_PATH /sw/opencv/opencv-3.1.0/lib/pkgconfig -------------------------------------------------------------------
Check the version of openCV
module load opencv/3.1.0 pkg-config --modversion opencv pkg-config --static --libs opencv pkg-config --cflags --libs opencv
Protobuf Issue
vi /sw/caffe/caffe-master/cmake/Modules/FindProtobuf.cmake # Locate and configure the Google Protocol Buffers library. # Defines the following variables: # # PROTOBUF_FOUND - Found the Google Protocol Buffers library # PROTOBUF_INCLUDE_DIRS - Include directories for Google Protocol Buffers # PROTOBUF_LIBRARIES - The protobuf library # # The following cache variables are also defined: # PROTOBUF_LIBRARY - The protobuf library # PROTOBUF_PROTOC_LIBRARY - The protoc library # PROTOBUF_INCLUDE_DIR - The include directory for protocol buffers # PROTOBUF_PROTOC_EXECUTABLE - The protoc compiler # # ==================================================================== # Example: # # find_package(Protobuf REQUIRED) # include_directories(${PROTOBUF_INCLUDE_DIRS}) # # include_directories(${CMAKE_CURRENT_BINARY_DIR}) # PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS foo.proto) # add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS}) # target_link_libraries(bar ${PROTOBUF_LIBRARY}) # # NOTE: You may need to link against pthreads, depending # on the platform. # ==================================================================== # # PROTOBUF_GENERATE_CPP (public function) # SRCS = Variable to define with autogenerated # source files # HDRS = Variable to define with autogenerated # header files # ARGN = proto files # # ==================================================================== #============================================================================= # Copyright 2009 Kitware, Inc. # Copyright 2009 Philip Lowman <philip@yhbt.com> # Copyright 2008 Esben Mose Hansen, Ange Optimization ApS # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distributed this file outside of CMake, substitute the full # License text for the above reference.) function(PROTOBUF_GENERATE_CPP SRCS HDRS) if(NOT ARGN) message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files") return() endif(NOT ARGN) set(${SRCS}) set(${HDRS}) foreach(FIL ${ARGN}) get_filename_component(ABS_FIL ${FIL} ABSOLUTE) get_filename_component(FIL_WE ${FIL} NAME_WE) list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL} DEPENDS ${ABS_FIL} COMMENT "Running C++ protocol buffer compiler on ${FIL}" VERBATIM ) endforeach() set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) set(${SRCS} ${${SRCS}} PARENT_SCOPE) set(${HDRS} ${${HDRS}} PARENT_SCOPE) endfunction() find_path(PROTOBUF_INCLUDE_DIR google/protobuf/service.h) # Google's provided vcproj files generate libraries with a "lib" # prefix on Windows if(WIN32) set(PROTOBUF_ORIG_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "") endif() find_library(PROTOBUF_LIBRARY NAMES protobuf DOC "The Google Protocol Buffers Library" ) find_library(PROTOBUF_PROTOC_LIBRARY NAMES protoc DOC "The Google Protocol Buffers Compiler Library" ) find_program(PROTOBUF_PROTOC_EXECUTABLE NAMES protoc DOC "The Google Protocol Buffers Compiler" ) mark_as_advanced(PROTOBUF_INCLUDE_DIR PROTOBUF_LIBRARY PROTOBUF_PROTOC_LIBRARY PROTOBUF_PROTOC_EXECUTABLE) # Restore original find library prefixes if(WIN32) set(CMAKE_FIND_LIBRARY_PREFIXES "${PROTOBUF_ORIG_FIND_LIBRARY_PREFIXES}") endif() include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROTOBUF DEFAULT_MSG PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR) if(PROTOBUF_FOUND) set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIR}) set(PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARY}) endif()
FindMATLAB.cmake
Soruce: https://github.com/casadi/casadi/blob/master/cmake/FindMATLAB.cmake
# - this module looks for Matlab # Defines: # MATLAB_INCLUDE_DIR: include path for mex.h, engine.h # MATLAB_LIBRARIES: required libraries: libmex, etc # MATLAB_MEX_LIBRARY: path to libmex.lib # MATLAB_MX_LIBRARY: path to libmx.lib # MATLAB_MAT_LIBRARY: path to libmat.lib # MATLAB_ENG_LIBRARY: path to libeng.lib # MATLAB_ROOT: path to Matlab's root directory # MATLAB_MEX_EXE: path to mex program # MATLAB_MEX_EXT: mex extension # MATLAB_CFLAGS, MATLAB_CLINKER_FLAGS, MATLAB_CLIBS (and same for CXX and Fortran) # # Note: You cannot use MATLAB_CLIBS etc to "target_link_libraries" as that gets confused # by the flag that specifies where the matlab libraries are (at least on Windows for Visual Studio). # This variable also contains system libraries etc so it's probably not a good idea to use it in # your CMake file. You should probably use # # include_directories(${MATLAB_INCLUDE_DIR}) # add_definitions(${MATLAB_CXXFLAGS}) # target_link_libraries(yourmexfile ${MATLAB_LIBRARIES} ) # # Reason for MATLAB_CXXFLAGS: on linux, mex files need to be compiled with -fPIC, but that means all # linked libraries need to be compiled with -fPIC as well. # This is a derivative work of file FindMatlab.cmake released with # CMake v2.8, because the original seems to be a bit outdated # # This file uses ideas from Gerardus (Author: Ramon Casero <rcasero@...>, Tom Doel) # and a post by Kent Williams # http://www.cmake.org/pipermail/cmake/2013-December/056593.html # # Heavily modified by Kris Thielemans for WIN32 and recent versions of matlab #============================================================================= # Copyright 2005-2009 Kitware, Inc. # Copyright 2014 University College London # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distribute this file outside of CMake, substitute the full # License text for the above reference.) # If MATLAB_ROOT was defined in the environment, use it. if (NOT MATLAB_ROOT AND NOT $ENV{MATLAB_ROOT} STREQUAL "") set(MATLAB_ROOT $ENV{MATLAB_ROOT} CACHE PATH "set this if CMake does not find it automatically") file(TO_CMAKE_PATH "${MATLAB_ROOT}" MATLAB_ROOT) endif() if (NOT MATLAB_ROOT) # get path to the Matlab executable find_program(MATLAB_EXE_PATH matlab PATHS /usr/local/bin) if (MATLAB_EXE_PATH) # found it, so let's find its absolute path and go one level up to find MATLAB_ROOT message(STATUS "MATLAB executable found: ${MATLAB_EXE_PATH}") # remove symbolic links get_filename_component(MATLAB_EXE_PATH "${MATLAB_EXE_PATH}" REALPATH ) # find directory of executable get_filename_component(my_MATLAB_ROOT "${MATLAB_EXE_PATH}" PATH ) # find root dir get_filename_component(my_MATLAB_ROOT "${my_MATLAB_ROOT}" PATH ) # store it in the cache set(MATLAB_ROOT "${my_MATLAB_ROOT}" CACHE PATH "Location of MATLAB files") else() # First set MATLAB_ROOT to an empty string but as a cached variable # this avoids CMake creating a local variable with the same name set(MATLAB_ROOT "" CACHE PATH "Location of MATLAB files") # now go and look in more places if(WIN32) # Search for a version of Matlab available, starting from the most modern one to older versions foreach(MATVER "8.5" "8.4" "8.3" "8.2" "8.1" "8.0" "7.16" "7.15" "7.14" "7.13" "7.12" "7.11" "7.10" "7.9" "7.8" "7.7" "7.6" "7.5" "7.4") if((NOT DEFINED MATLAB_ROOT) OR ("${MATLAB_ROOT}" STREQUAL "") OR ("${MATLAB_ROOT}" STREQUAL "/registry")) get_filename_component(MATLAB_ROOT "[HKEY_LOCAL_MACHINE\\SOFTWARE\\MathWorks\\MATLAB\\${MATVER};MATLABROOT]" ABSOLUTE) endif() endforeach() if("${MATLAB_ROOT}" STREQUAL "/registry") set(MATLAB_ROOT "") endif() elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") # Check if this is a Mac # we look in the applications folder # Search for a version of Matlab available, starting from the most modern one to older versions foreach(MATVER "R2015b" "R2015a" "R2014b" "R2014a" "R2013b" "R2013a" "R2012b" "R2012a" "R2011b" "R2011a" "R2010b" "R2010a" "R2009b" "R2009a" "R2008b") if((NOT DEFINED MATLAB_ROOT) OR ("${MATLAB_ROOT}" STREQUAL "")) if(EXISTS /Applications/MATLAB_${MATVER}.app) set(MATLAB_ROOT /Applications/MATLAB_${MATVER}.app) endif() endif() endforeach() else() # could go and look in some other default places for other OSses endif() endif() endif() if ("${MATLAB_ROOT}" STREQUAL "") message(STATUS "MATLAB not found. Set MATLAB_ROOT") # TODO should really skip rest of configuration as it will all fail anyway. else() message(STATUS "MATLAB_ROOT set to ${MATLAB_ROOT}") endif() # Find out where MATLAB libraries are IF (NOT MATLAB_LIBRARIES) if (WIN32) # Directory name depending on whether the Windows architecture is 32 # bit or 64 bit if(CMAKE_SIZEOF_VOID_P MATCHES "4") set(WINDIR "win32") elseif(CMAKE_SIZEOF_VOID_P MATCHES "8") set(WINDIR "win64") else() message(FATAL_ERROR "CMAKE_SIZEOF_VOID_P (${CMAKE_SIZEOF_VOID_P}) doesn't indicate a valid platform") endif() # Folder where the MEX libraries are, depending on the Windows compiler if(${CMAKE_GENERATOR} MATCHES "Visual Studio 6") set(MATLAB_LIBRARIES_DIR "${MATLAB_ROOT}/extern/lib/${WINDIR}/microsoft/msvc60") elseif(${CMAKE_GENERATOR} MATCHES "Visual Studio 7") # Assume people are generally using Visual Studio 7.1, # if using 7.0 need to link to: ../extern/lib/${WINDIR}/microsoft/msvc70 set(MATLAB_LIBRARIES_DIR "${MATLAB_ROOT}/extern/lib/${WINDIR}/microsoft/msvc71") # set(MATLAB_LIBRARIES_DIR "${MATLAB_ROOT}/extern/lib/${WINDIR}/microsoft/msvc70") elseif(${CMAKE_GENERATOR} MATCHES "Borland") # Assume people are generally using Borland 5.4, # if using 7.0 need to link to: ../extern/lib/${WINDIR}/microsoft/msvc70 set(MATLAB_LIBRARIES_DIR "${MATLAB_ROOT}/extern/lib/${WINDIR}/microsoft/bcc54") # set(MATLAB_LIBRARIES_DIR "${MATLAB_ROOT}/extern/lib/${WINDIR}/microsoft/bcc50") # set(MATLAB_LIBRARIES_DIR "${MATLAB_ROOT}/extern/lib/${WINDIR}/microsoft/bcc51") elseif(${CMAKE_GENERATOR} MATCHES "Visual Studio*") # If the compiler is Visual Studio, but not any of the specific # versions above, we try our luck with the microsoft directory set(MATLAB_LIBRARIES_DIR "${MATLAB_ROOT}/extern/lib/${WINDIR}/microsoft/") endif() else(WIN32) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") set(LIBRARY_EXTENSION .dylib) else() set(LIBRARY_EXTENSION .so) endif() # There seems to be no way to let cmake do a search in subdirectories, so use "find" execute_process( COMMAND find "${MATLAB_ROOT}/bin" -name libmex${LIBRARY_EXTENSION} COMMAND xargs echo -n OUTPUT_VARIABLE mex_lib ) if (mex_lib) # find directory of executable get_filename_component(MATLAB_LIBRARIES_DIR ${mex_lib} PATH ) endif() endif(WIN32) if (NOT MATLAB_LIBRARIES_DIR) set(MATLAB_LIBRARIES_DIR ${MATLAB_ROOT}) endif() message(STATUS "Will look for MATLAB libraries in ${MATLAB_LIBRARIES_DIR}") endif() # MATLAB_LIBRARIES if (WIN32) set(BATEXT .bat) set(LIBPREFIX lib) endif() # This is common to all platforms: # Get paths to the Matlab MEX libraries find_library(MATLAB_MEX_LIBRARY ${LIBPREFIX}mex HINTS ${MATLAB_LIBRARIES_DIR} ) find_library(MATLAB_MX_LIBRARY ${LIBPREFIX}mx HINTS ${MATLAB_LIBRARIES_DIR} ) find_library(MATLAB_MAT_LIBRARY ${LIBPREFIX}mat HINTS ${MATLAB_LIBRARIES_DIR} ) find_library(MATLAB_ENG_LIBRARY ${LIBPREFIX}eng HINTS ${MATLAB_LIBRARIES_DIR} ) find_library(MATLAB_UT_LIBRARY ${LIBPREFIX}ut HINTS ${MATLAB_LIBRARIES_DIR} ) # Get path to the include directory find_path(MATLAB_INCLUDE_DIR "mex.h" HINTS "${MATLAB_ROOT}/extern/include" "${MATLAB_ROOT}/include" ) find_program( MATLAB_MEX_PATH mex${BATEXT} HINTS ${MATLAB_ROOT}/bin DOC "The mex program path" ) find_program( MATLAB_MEXEXT_PATH mexext${BATEXT} HINTS ${MATLAB_ROOT}/bin DOC "The mexext program path" ) # find mex extension execute_process( COMMAND ${MATLAB_MEXEXT_PATH} OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE MATLAB_MEX_EXT ) set(MATLAB_LIBRARIES ${MATLAB_MEX_LIBRARY} ${MATLAB_MX_LIBRARY} ${MATLAB_ENG_LIBRARY} ${MATLAB_UT_LIBRARY} CACHE PATH "Libraries to link mex files" ) ######################### find flags using "mex -v" # This is based on Kent Williams's post at # http://www.cmake.org/pipermail/cmake/2013-December/056593.html # mex -v outputs all the settings used for building MEX files, so # we can use it to grab the important variables needed # This sets MATLAB_CFLAGS, MATLAB_CLINKER_FLAGS, MATLAB_CLIBS (and same for CXX and Fortran) macro(MATLAB_GETFLAGS FILENAME) execute_process(COMMAND ${MATLAB_MEX_PATH} -v -n ${FILENAME} OUTPUT_VARIABLE mexOut ERROR_VARIABLE mexErr) # parse mex output line by line by turning file into CMake list of lines string(REGEX REPLACE "\r?\n" ";" _mexOut "${mexOut}") foreach(line ${_mexOut}) if("${line}" MATCHES "[\t ]+DEFINES *:") # on Linux string(REGEX REPLACE "[\t ]+DEFINES *: *" "" mexDefines "${line}") elseif("${line}" MATCHES "[\t ]+COMPDEFINES *:") # on Windows string(REGEX REPLACE "[\t ]+COMPDEFINES *: *" "" mexDefines "${line}") elseif("${line}" MATCHES "[\t ]+LINKFLAGS *:") string(REGEX REPLACE "[\t ]+LINKFLAGS *: *" "" mexLdFlags "${line}") # get rid of /implib statement used on some older windows-matlab versions (refers to temp file) string(REGEX REPLACE "/implib:\".*\"" "" mexLdFlags "${mexLdFlags}") elseif("${line}" MATCHES "[\t ]+LINKLIBS *:") string(REGEX REPLACE "[\t ]+LINKLIBS *: *" "" mexLdLibs "${line}") elseif("${line}" MATCHES "[\t ]+LINKEXPORT *:") string(REGEX REPLACE "[\t ]+LINKEXPORT *: *" "" mexLdExport "${line}") elseif("${line}" MATCHES "[\t ]+CXXFLAGS *[:=]") string(REGEX REPLACE "[\t ]+CXXFLAGS *[:=] *" "" mexCxxFlags "${line}") #message(STATUS "mexcxx ${mexCxxFlags}") elseif("${line}" MATCHES "[\t ]+CFLAGS *[:=]") string(REGEX REPLACE "[\t ]+CFLAGS *[:=] *" "" mexCFlags "${line}") elseif("${line}" MATCHES "[\t ]+FFLAGS *[:=]") string(REGEX REPLACE "[\t ]+FFLAGS *[:=] *" "" mexFFlags "${line}") # pre-2014a flags elseif("${line}" MATCHES "[\t ]+CXXLIBS *[:=]") string(REGEX REPLACE "[\t ]+CXXLIBS *[:=] *" "" mexCxxLibs "${line}") elseif("${line}" MATCHES "[\t ]+CLIBS *[:=]") string(REGEX REPLACE "[\t ]+CLIBS *[:=] *" "" mexCLibs "${line}") elseif("${line}" MATCHES "[\t ]+FLIBS *[:=]") string(REGEX REPLACE "[\t ]+FLIBS *[:=] *" "" mexFLibs "${line}") elseif("${line}" MATCHES "[\t ]+LDFLAGS *[:=]") string(REGEX REPLACE "[\t ]+LDFLAGS *[:=] *" "" mexLdFlags "${line}") elseif("${line}" MATCHES "[\t ]+LDCXXFLAGS *[:=]") string(REGEX REPLACE "[\t ]+LDCXXFLAGS *[:=] *" "" mexLdCxxFlags "${line}") elseif("${line}" MATCHES "[\t ]+LDCFLAGS *[:=]") string(REGEX REPLACE "[\t ]+LDCFLAGS *[:=] *" "" mexLdCFlags "${line}") elseif("${line}" MATCHES "[\t ]+LDFLAGS *[:=]") string(REGEX REPLACE "[\t ]+LDFLAGS *[:=] *" "" mexLdFFlags "${line}") endif() endforeach() endmacro() # Since 2014a or so, mex can only be used for one type of source and no longer # reports all flags. We therefore need to run mex with different file types. #### C MATLAB_GETFLAGS(${PROJECT_SOURCE_DIR}/src/cmake/FindMATLAB_mextest.c) set(MATLAB_CFLAGS "${mexDefines} ${mexCFlags}" CACHE STRING "Flags to compile C MATLAB Mex files (or libraries that link with them)") set(MATLAB_CLINKER_FLAGS "${mexLdFlags} ${mexLdCFlags} ${mexLdExport}" CACHE STRING "Flags to link MATLAB C Mex files") set(MATLAB_CLIBS "${mexLdLibs} ${mexCLibs}" CACHE STRING "Flags with libraries to link MATLAB C Mex files") #### C++ MATLAB_GETFLAGS(${PROJECT_SOURCE_DIR}/src/cmake/FindMATLAB_mextest.cxx) set(MATLAB_CXXFLAGS "${mexDefines} ${mexCxxFlags}" CACHE STRING "Flags to compile C++ MATLAB Mex files (or libraries that link with them)") set(MATLAB_CXXLINKER_FLAGS "${mexLdFlags} ${mexLdCxxFlags} ${mexLdExport}" CACHE STRING "Flags to link MATLAB C++ Mex files") set(MATLAB_CXXLIBS "${mexLdLibs} ${mexCxxLibs}" CACHE STRING "Flags with libraries to link MATLAB C++ Mex files") #### Fortran MATLAB_GETFLAGS(${PROJECT_SOURCE_DIR}/src/cmake/FindMATLAB_mextest.f) set(MATLAB_FFLAGS "${mexDefines} ${mexFFlags}" CACHE STRING "Flags to compile Fortran MATLAB Mex files (or libraries that link with them)") set(MATLAB_FLINKER_FLAGS "${mexLdFlags} ${mexLdFFlags} ${mexLdExport}" CACHE STRING "Flags to link MATLAB Fortran Mex files") set(MATLAB_FLIBS "${mexLdLibs} ${mexFLibs}" CACHE STRING "Flags with libraries to link MATLAB Fortran Mex files") # handle the QUIETLY and REQUIRED arguments and set MATLAB_FOUND to TRUE if # all listed variables are TRUE INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(MATLAB "MATLAB not found. If you do have it, set MATLAB_ROOT and reconfigure" MATLAB_ROOT MATLAB_INCLUDE_DIR MATLAB_LIBRARIES MATLAB_MEX_PATH MATLAB_MEXEXT_PATH MATLAB_MEX_EXT ) mark_as_advanced( MATLAB_EXE_PATH MATLAB_LIBRARIES MATLAB_MEX_LIBRARY MATLAB_MX_LIBRARY MATLAB_ENG_LIBRARY MATLAB_INCLUDE_DIR MATLAB_FOUND MATLAB_MAT_LIBRARY MATLAB_MEX_PATH MATLAB_MEXEXT_PATH MATLAB_MEX_EXT MATLAB_CFLAGS MATLAB_CXXFLAGS MATLAB_FFLAGS MATLAB_CLINKER_FLAGS MATLAB_CXXLINKER_FLAGS MATLAB_FLINKER_FLAGS MATLAB_CLIBS MATLAB_CXXLIBS MATLAB_FLIBS )
CMakeLists.txt
vi /sw/caffe/caffe-master/CMakeLists.txt Add the following at the bottom >>>>>> #target_link_libraries(filters ${OpenCV_LIBRARIES}) FIND_PACKAGE(OpenCV REQUIRED) FIND_PACKAGE(Protobuf REQUIRED) FIND_PACKAGE(Matlab REQUIRED) >>>>>>>> Also edit: vi /sw/caffe/caffe-master/src/caffe/CMakeLists.txt Added ${OpenCV_LIBRARIES} as in: target_link_libraries(caffe proto ${Caffe_LINKER_LIBS} ${OpenCV_LIBRARIES}) >>>>>>
Install libmpc-devel package
rpm -ivh /tmp/libmpc-devel-0.8-3.el6.x86_64.rpm /tmp/libmpc-0.8-3.el6.x86_64.rpm Preparing... ########################################### [100%] 1:libmpc ########################################### [ 50%] 2:libmpc-devel ########################################### [100%]
cd /sw/caffe/caffe-master/build cmake -D CMAKE_INSTALL_PREFIX=/sw/caffe/caffe -DBUILD_SHARED_LIBS=ON -DBUILD_matlab=ON -DMATLAB_DIR=/sw/Matlab/R2015b -DMatlab_mexext=/sw/Matlab/R2015b/bin/mex -DMatlab_mex=/sw/Matlab/R2015b/bin/mex -DMatlab_DIR=/sw/Matlab/R2015b -DOctave_DIR=/sw/octave/3.8.0 -DCUDNN_INCLUDE="/sw/cuda/cuda_7.5.18/include" -DCUDNN_LIBRARY="/sw/cuda/cuda_7.5.18/lib64/libcudnn.so" -DAtlas_LAPACK_LIBRARY=/sw/library/lapack/lapack-3.6.0/3.6.0/lib64/liblapack.so .. 2>&1 | tee cmakelog.txt make 2>&1 | tee makelog.txt You will get an error at nearly 100% . It is due to matlab2015a stuff needing gcc compiler version 4.7X. Then just do this: module load compilers/gcc-4.7.1 make 2>&1 | tee makelog2.txt make install 2>&1 | tee makeInstalllog.txt
>>>>>>>>> cmake -D CMAKE_INSTALL_PREFIX=/sw/caffe/caffe -DBUILD_SHARED_LIBS=ON -DBUILD_matlab=ON -DMATLAB_DIR=/sw/Matlab/R2015b -DMatlab_mexext=/sw/Matlab/R2015b/bin/mex -DMatlab_mex=/sw/Matlab/R2015b/bin/mex -DMatlab_DIR=/sw/Matlab/R2015b -DOctave_DIR=/sw/octave/3.8.0 -DCUDNN_INCLUDE="/sw/cuda/cuda_7.5.18/include" -DCUDNN_LIBRARY="/sw/cuda/cuda_7.5.18/lib64/libcudnn.so" -DAtlas_LAPACK_LIBRARY=/sw/library/lapack/lapack-3.6.0/3.6.0/lib64/liblapack.so .. 2>&1 | tee cmakelog.txt -- The C compiler identification is GNU 4.7.1 -- The CXX compiler identification is GNU 4.7.1 -- Check for working C compiler: /sw/gcc/4.7.1/bin/gcc -- Check for working C compiler: /sw/gcc/4.7.1/bin/gcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /sw/gcc/4.7.1/bin/g++ -- Check for working CXX compiler: /sw/gcc/4.7.1/bin/g++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - not found -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - not found -- Looking for pthread_create in pthread -- Looking for pthread_create in pthread - found -- Found Threads: TRUE -- Boost version: 1.60.0 -- Found the following Boost libraries: -- system -- thread -- filesystem -- chrono -- date_time -- atomic -- Found GFlags: /sw/caffe/gflags/usr/local/include -- Found gflags (include: /sw/caffe/gflags/usr/local/include, library: /sw/caffe/gflags/usr/local/lib/libgflags.a) -- Found Glog: /sw/caffe/glog/0.3.3/include -- Found glog (include: /sw/caffe/glog/0.3.3/include, library: /sw/caffe/glog/0.3.3/lib/libglog.so) -- Found PROTOBUF: /sw/caffe/protobuf/lib/libprotobuf.so -- Found PROTOBUF Compiler: /sw/caffe/protobuf/bin/protoc -- Found HDF5: /sw/library/hdf5/1.8.7/lib/libhdf5_hl.so;/sw/library/hdf5/1.8.7/lib/libhdf5.so;/usr/lib64/libz.so;/usr/lib64/libm.so (found version "1.8.7") -- Found LMDB: /sw/caffe/lmdb/usr/local/include -- Found lmdb (include: /sw/caffe/lmdb/usr/local/include, library: /sw/caffe/lmdb/usr/local/lib/liblmdb.so) -- Found LevelDB: /sw/caffe/leveldb/include -- Found LevelDB (include: /sw/caffe/leveldb/include, library: /sw/caffe/leveldb/lib/libleveldb.so) -- Found Snappy: /sw/caffe/snappy/include -- Found Snappy (include: /sw/caffe/snappy/include, library: /sw/caffe/snappy/lib/libsnappy.so) -- CUDA detected: 7.5 -- Found cuDNN: ver. 4.0.7 found (include: /sw/cuda/cuda_7.5.18/include, library: /sw/cuda/cuda_7.5.18/lib64/libcudnn.so) -- Added CUDA NVCC flags for: sm_20 -- Found PkgConfig: /usr/bin/pkg-config (found version "0.23") -- Checking for module 'opencv' -- Found opencv, version 3.1.0 -- Checking for module 'opencv' -- Found opencv, version 3.1.0 -- LIBS3.1.0 -- OpenCV found () -- Found Atlas: /sw/library/atlas/3.10.2/include -- Found Atlas (include: /sw/library/atlas/3.10.2/include, library: /sw/library/atlas/3.10.2/lib/libatlas.so) -- Found PythonInterp: /sw/python/2.7.1-shared/bin/python2.7 (found suitable version "2.7.1", minimum required is "2.7") -- Found PythonLibs: /sw/python/2.7.1-shared/lib/libpython2.7.so (found suitable version "2.7.1", minimum required is "2.7") -- Found NumPy: /sw/python/2.7.1-shared/lib/python2.7/site-packages/numpy-1.12.0.dev0+1380fdd-py2.7-linux-x86_64.egg/numpy/core/include (found suitable version "1.12.0.dev0+1380fdd", minimum required is "1.7.1") -- NumPy ver. 1.12.0.dev0+1380fdd found (include: /sw/python/2.7.1-shared/lib/python2.7/site-packages/numpy-1.12.0.dev0+1380fdd-py2.7-linux-x86_64.egg/numpy/core/include) -- Boost version: 1.60.0 -- Found the following Boost libraries: -- python dirname: missing operand Try `dirname --help' for more information. dirname: missing operand Try `dirname --help' for more information. -- Found MatlabMex: /sw/Matlab/R2015b/bin/mex -- Found Doxygen: /usr/bin/doxygen (found version "1.6.1") Not enough input arguments. -- Detected Doxygen OUTPUT_DIRECTORY: ./doxygen/ -- Found Git: /usr/bin/git (found version "1.7.1") -- -- ******************* Caffe Configuration Summary ******************* -- General: -- Version : 1.0.0-rc3 -- Git : unknown -- System : Linux -- C++ compiler : /sw/gcc/4.7.1/bin/g++ -- Release CXX flags : -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized -- Debug CXX flags : -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized -- Build type : Release -- -- BUILD_SHARED_LIBS : ON -- BUILD_python : ON -- BUILD_matlab : ON -- BUILD_docs : ON -- CPU_ONLY : OFF -- USE_OPENCV : ON -- USE_LEVELDB : ON -- USE_LMDB : ON -- ALLOW_LMDB_NOLOCK : OFF -- -- Dependencies: -- BLAS : Yes (Atlas) -- Boost : Yes (ver. 1.60) -- glog : Yes -- gflags : Yes -- protobuf : Yes (ver. 3.0.0) -- lmdb : Yes (ver. 0.9.70) -- LevelDB : Yes (ver. 1.18) -- Snappy : Yes (ver. 1.1.3) -- OpenCV : Yes (ver. 3.1.0) -- CUDA : Yes (ver. 7.5) -- -- NVIDIA CUDA: -- Target GPU(s) : Auto -- GPU arch(s) : sm_20 -- cuDNN : Yes (ver. 4.0.7) -- -- Python: -- Interpreter : /sw/python/2.7.1-shared/bin/python2.7 (ver. 2.7.1) -- Libraries : /sw/python/2.7.1-shared/lib/libpython2.7.so (ver 2.7.1) -- NumPy : /sw/python/2.7.1-shared/lib/python2.7/site-packages/numpy-1.12.0.dev0+1380fdd-py2.7-linux-x86_64.egg/numpy/core/include (ver 1.12.0.dev0+1380fdd) -- -- Matlab: -- Matlab : Yes (/sw/Matlab/R2015b/bin/mex, /sw/Matlab/R2015b/bin/mex -- Octave : Yes (/sw/octave/3.8.0/bin/mkoctfile) -- Build mex using : Matlab -- -- Documentaion: -- Doxygen : /usr/bin/doxygen (1.6.1) -- config_file : /sw/caffe/caffe-master/.Doxyfile -- -- Install: -- Install path : /sw/caffe/caffe -- -- LIBS3.1.0 -- Found Matlab: /sw/Matlab/R2015b/extern/include (found version "8.6") -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project: MATLAB_DIR Octave_DIR -- Build files have been written to: /sw/caffe/caffe-master/build >>>>>>>>>
make snip <<< CLIP [ 79%] Building CXX object src/caffe/CMakeFiles/caffe.dir/util/upgrade_proto.cpp.o [ 80%] Linking CXX shared library ../../lib/libcaffe.so [ 80%] Built target caffe Scanning dependencies of target convert_imageset [ 80%] Building CXX object tools/CMakeFiles/convert_imageset.dir/convert_imageset.cpp.o [ 80%] Linking CXX executable convert_imageset ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::Mat::Mat(cv::Mat const&, cv::Rect_<int> const&)' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::Mat::copySize(cv::Mat const&)' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::imread(cv::String const&, int)' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::String::allocate(unsigned long)' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::String::deallocate()' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::imencode(cv::String const&, cv::_InputArray const&, std::vector<unsigned char, std::allocator<unsigned char> >&, std::vector<int, std::allocator<int> > const&)' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::Mat::deallocate()' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::imdecode(cv::_InputArray const&, int)' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::fastFree(void*)' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int)' ../lib/libcaffe.so.1.0.0-rc3: undefined reference to `cv::flip(cv::_InputArray const&, cv::_OutputArray const&, int)' collect2: ld returned 1 exit status make[2]: *** [tools/convert_imageset] Error 1 make[1]: *** [tools/CMakeFiles/convert_imageset.dir/all] Error 2 make: *** [all] Error 2
Reference
- https://github.com/BVLC/caffe
- http://caffe.berkeleyvision.org/
- https://github.com/casadi/casadi/blob/master/cmake/FindMATLAB.cmake