Installing Caffe [English] - LCAD-UFES/carmen_lcad GitHub Wiki

Install Dependencies

IMPORTANT: This installation has not been widely tested.

TO DO: Verify if --no-install-recommends is necessary.

 sudo apt-get install --no-install-recommends \
 build-essential \
 cmake \
 git \
 libgoogle-glog-dev \
 libgtest-dev \
 libiomp-dev \
 libleveldb-dev \
 liblmdb-dev \
 libopenmpi-dev \
 libsnappy-dev \
 libprotobuf-dev \
 openmpi-bin \
 openmpi-doc \
 protobuf-compiler \
 python-dev \
 python-pip \
 libgflags-dev \
 libgoogle-glog-dev \
 liblmdb-dev

Install OpenBLAS

 cd ~/packages_carmen
 wget "https://sourceforge.net/projects/openblas/files/v0.3.0/OpenBLAS%200.3.0%20version.tar.gz/download" -O openblas-0.3.0.tar.gz
 tar -vzxf openblas-0.3.0.tar.gz
 cd xianyi-OpenBLAS-939452e/
 make
 sudo make install

One-liner command:

 cd ~/packages_carmen && wget "https://sourceforge.net/projects/openblas/files/v0.3.0/OpenBLAS%200.3.0%20version.tar.gz/download" -O openblas-0.3.0.tar.gz && tar -vzxf openblas-0.3.0.tar.gz && cd xianyi-OpenBLAS-939452e/ && make && sudo make install

Compile Caffe

Note: The -DCUDA_ARCH_BIN="XX" parameter specifies the GPU architecture.

To find the GPU architecture:

 cd /usr/local/cuda-9.1/samples/1_Utilities/deviceQuery
 sudo make 
 ./deviceQuery

Look for the line "CUDA Capability Major/Minor version number". Ignore the dot; for example, if the value is 3.0, use 30 for the -DCUDA_ARCH_BIN cmake parameter.

 cd $CARMEN_HOME/sharedlib/ENet/caffe-enet
 mkdir build && cd build
 cmake -DBLAS=open -DCUDA_ARCH_NAME=Manual -DCUDA_ARCH_BIN="50" -DCUDA_ARCH_PTX="" .. 
 make all -j 20 
 make pycaffe

One-liner command:

 cd $CARMEN_HOME/sharedlib/ENet/caffe-enet && mkdir build && cd build && cmake -DBLAS=open -DCUDA_ARCH_NAME=Manual -DCUDA_ARCH_BIN="61" -DCUDA_ARCH_PTX="" .. && make all -j 20 && make pycaffe

If you encounter the following error:

 CMake Warning at /home/mscdo/opencv-3.1.0/cmake/OpenCVConfig.cmake:166 (message):
   Found OpenCV Windows Pack but it has no binaries compatible with your
   configuration.

   You should manually point CMake variable OpenCV_DIR to your build of OpenCV
   library.
 Call Stack (most recent call first):
   example/mnist/CMakeLists.txt:2 (find_package)

 CMake Error at example/mnist/CMakeLists.txt:2 (find_package):
   Found package configuration file:

     /home/mscdo/opencv-3.1.0/cmake/OpenCVConfig.cmake

   but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be
   NOT FOUND.

Delete the contents of the build folder to remove configuration files and rerun the cmake command, including the path to the OpenCV build folder:

 rm -rf $CARMEN_HOME/sharedlib/ENet/caffe-enet/build/*
 cd $CARMEN_HOME/sharedlib/ENet/caffe-enet/build
 cmake -DBLAS=open -DCUDA_ARCH_NAME=Manual -DCUDA_ARCH_BIN="50" -DCUDA_ARCH_PTX="" -D OpenCV_DIR=<PASTA ONDE VOCÊ BAIXOU A OPENCV>/opencv-3.1.0/build/ ..
 make all -j 20 
 make pycaffe

If other errors occur at this stage, consult our FAQ.

Add to Your User's .bashrc (gedit ~/.bashrc):

 #Caffe ENet
 export CAFFE_ENET_HOME=$CARMEN_HOME/sharedlib/ENet/caffe-enet
 export CAFFE_HOME=$CAFFE_ENET_HOME
 export PYTHONPATH=$CAFFE_ENET_HOME/python:$PYTHONPATH
 export LD_LIBRARY_PATH=$CAFFE_ENET_HOME/build/lib:$LD_LIBRARY_PATH
 export GLOG_minloglevel=1

Verify if the following file exists:

ls $CAFFE_ENET_HOME/include/caffe/proto/caffe.pb.h

If it does not exist, follow these steps:

 cd $CAFFE_ENET_HOME
 protoc src/caffe/proto/caffe.proto --cpp_out=.
 mkdir include/caffe/proto
 mv src/caffe/proto/caffe.pb.h include/caffe/proto/

One-liner command:

cd $CAFFE_ENET_HOME && protoc src/caffe/proto/caffe.proto --cpp_out=. && mkdir include/caffe/proto && mv src/caffe/proto/caffe.pb.h include/caffe/proto/