Install Caffe under Mac OS X10.10

Source: Internet
Author: User
Tags install homebrew intel mkl



Install Caffe under Mac OS X10.10






[Email protected]



Http://blog.csdn.net/surgewong






in Linux learning Caffe "1" for some time, but also gradually to the framework of Caffe have a little understanding. There are many people who study Caffe under Linux, and the reference materials on the internet want to be more. Installation configuration tutorial A lot, out of the problem are relatively good solution. Two days ago the boss got a Mac notebook and asked me to help him install Caffe on his Mac. Poor cock has not played a Mac notebook before, directed at the Mac of this curiosity, began a painful installation trip.






First, the Mac software installation method



Accustomed to the Linux under the sudo apt-get install XXXX Software installation method, the Mac under the Brew install XXXX is easy to get started. However, there was hardly any basis for the Mac before, and it was difficult to understand some of the specific terms, such as: Formula,framework. Use a few more times, and begin to understand it slowly. The brew is installed by means of a "2" package management tool called homebrew. Common commands for installation around brew are:



Brew Install XXXX----install package or corresponding library



Brew Uninstall XXXX-to uninstall package or corresponding library



Brew Update-Update homebrew Yourself



Brew Upgrade--upgrade all software that can be upgraded (by means of brew installation)



Brew List--list all software installed through brew



Brew Doctor----diagnose if the installation was successful



Brew Edit----edit xxxx (Formula) corresponding software security device file



Brew Help-List common commands






Second, the installation of Caffe necessary dependencies



Refer to the Official tutorial "3", Caffe need to install the content is:



CUDA Better be version 6.5



BLAS can be provided through Atlas,mkl,openblas



OPENCV version greater than or equal to 2.4



The Boost version is approximately or equal to 1.5, and a Python version is required if necessary



Glog, GFlags, Protobuf, Leveldb, Snappy, HDF5, Lmdb



The following are not required:



Python python 2.7 numpy version greater than or equal to 1.7



Matlab provides a MEX compiler






Third. the installation of CUDA and BLAS



1.cuda Installation: Under the MAC cuda installation compared to Linux is much simpler, directly download "4", and then directly double-click, follow the prompts to install directly, other related settings can refer to the document "5".



It is primarily necessary to set up Cuda-related paths, which can be set in/etc/profile with the following environment variables:



Export Path=/developer/nvidia/cuda-6.5/bin: $PATH



Export Dyld_library_path=/developer/nvidia/cuda-6.5/lib: $DYLD _library_path






2. Installation ofAtlas : The Veclib framework (accelerate frame) under the MAC system itself integrates the implementation of Atlas, which only needs to be specified in the directory where the corresponding header files are compiled caffe.






3.Openblas Installation: Use Brew to install. (There may be some problems with direct use of the brew installation, as described later)



Brew Install Homebrew/science/openblas---> Direct installation



Brew Install--build-from-source Homebrew/science/openblas--by compiling the source installation






4. Installation ofMKL : Intel Mkl is a commercially available library for CPU optimization, can use the student free version, can register an account with the Intel official website "6", download the corresponding Mac version of MKL.






Fourth, OpenCV, Glog, GFlags, Protobuf, Leveldb, Snappy, HDF5, Lmdb installation



Starting with Mac 10.9, the system default C + + compiler is clang/clang++ instead of gcc/g++, and the corresponding C + + standard library is libc++ (mainly for C + + X11). Many dependent libraries in Caffe are primarily based on the Libstdc++ library, so it is easy to use the default compilation options :undefined symbols for architecture x86_64 The error. To solve this problem, it is not necessary to ensure that the corresponding dependency itself is based on libstdc++ to compile the installation.



The above dependencies can be installed first through the brew, but you need to choose to install through the source, and at compile time choose to use the Libstdc++ library to compile. You can use this method by editing the corresponding homebrew formula. The Openblas mentioned earlier is preferably compiled and installed in this way. For each homebrew formula that needs to be installed:






Boost Snappy Leveldb protobuf gflags glog szip lmdb HOMEBREW/SCIENCE/OPENCV






Use brew edit FORMULA (such as brew edit boost) to add the appropriate env definition to the environment:








 def install      # ADD THE FOLLOWING:      ENV.append "CXXFLAGS", "-stdlib=libstdc++"      ENV.append "CFLAGS", "-stdlib=libstdc++"      ENV.append "LDFLAGS", "-stdlib=libstdc++ -lstdc++"      # The following is necessary because libtool likes to strip LDFLAGS:      ENV["CXX"] = "/usr/bin/clang++ -stdlib=libstdc++"





For each formula in order first uninstall and then re-compile the installation by source code:








for x in snappy leveldb gflags glog szip lmdb homebrew/science/opencv; do brew uninstall $x; brew install --build-from-source --fresh -vd $x; donebrew uninstall protobuf; brew install --build-from-source --with-python --fresh -vd protobufbrew install --build-from-source --fresh -vd boost boost-python





Note: Even if the above compilation is successful, during the compilation of the Caffe process, the missing Tr1/truple header file may be prompted, which also requires the installation of Hdf5 dependencies, which can be installed in a similar manner as described above.






Fifth. OpenCV Local source code compilation, and GFlags, Glog Local source code compilation



1. Installation ofOpenCV : The above mentioned Brew installation method may fail to install. I encountered a lot of trouble in installing OpenCV.



A. Direct use of the brew install HOMEBREW/SCIENCE/OPENCV can successfully install OPENCV, but the OPENCV does not compile the Cuda library itself, it is compiled by default libc++ library, so in the use of compiled Caffe The undefined symbols for architecture x86_64 error will appear. This way is not advisable.






B. The author installs with the Brew install--build-from-source--FRESH-VD HOMEBREW/SCIENCE/OPENCV, the system installs 2.4.10.1 version, this version, has a cuda compatibility problem A bug that does not compile properly. (Note: The Mac is not very familiar, no attempt to fix the problem) the author used Linux under the version is 2.4.9, encountered a similar bug "7." So give up using this method and use 2.4.9 source to compile directly.






C. When compiling with the source code, the biggest thing is how to make it choose libstdc++ instead of libc++ when compiling OpenCV. OpenCV is generated makefile by CMake, the corresponding cmake configuration needs to be modified to add the appropriate settings. Because the grammar of CMake is not very familiar, can only guess. The author adds a cmake/opencvdetectcuda.cmake to the 151th line of the file.



Set (cuda_nvcc_flags ${cuda_nvcc_flags} "-xcompiler-stdlib=libstdc++; -xlinker-stdlib=libstdc++ ")



You can then follow the normal compilation steps directly, but the compilation time is relatively long.






2. Installation of gflags : The author uses the fourth step of the brew installation does not make gflags successfully use the libstdc++ library to compile (compile Caffe error). The same configuration is added to the GFlags cmake related files. The author in cmake/cmakecxxinformation.cmake 209 Line Out add



set (cmake_cxx_flags "-stdlib=libstdc++" ${cmake_cxx_flags})



Then compile the installation directly according to the normal compilation steps.






3. Installation of Glog : Glog is dependent on gflags, so gflags must be installed before installing Glog, when compiling glog, some files (*unittest.cc) compile errors, The main problem is namespace problems (there is no reason to delve into them, only solutions are given here). You only need to include the appropriate file in the



using namespace gflags;






Sixth. Compiling Caffe



When compiling the Caffe, you need to set up dependent paths and library dependencies, and wait for make to succeed. Now enjoy using Caffe programming under your MAC!









Resources:






"1" Caffe Home



"2" Homebrew Home



"3" Caffe installation website



"4" CUDA official website



"5" CUDA online documentation



"6" Intel official website MKL



"7" a OpenCV 2.4.9 and CUDA compatibility Bug















Install Caffe under Mac OS X10.10


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.