[Caffe] Install Caffe and the depended packages

This article is just for me to quickly record the all the steps to install the depended packages for Caffe. So, be careful that it maybe is not good for you to walk through them in your environment. ^_^

# Install CCMAKE

$ sudo apt-get install cmake-curses-gui

# Build my own installation location

$ mkdir ~/local_install

# ProtoBuffer

$ tar zxvf protobuf-2.5.0.tar.gz
$ cd protobuf-2.5.0
$ ./configure --prefix=/home/liudanny/local_install/
$ make -j2
$ make install

#Boost

$ tar xvf boost_1_56_0.tar.bz2
$ cd boost_1_56_0
### ./bootstrap.sh --show-libraries ###
$ ./bootstrap.sh --with-libraries=program_options,filesystem,system,exception,thread
$ ./b2
$ cp -r boost/ /home/liudanny/local_install/include
$ cp stage/lib/* /home/liudanny/local_install/lib/

# Gflags

$ unzip gflags-2.1.1.zip
$ cd gflags-2.1.1
$ mkdir build
$ cd build
$ cmake ..
$ ccmake ..

$ make -j2
$ make install

# Glog

$ tar zxvf glog-0.3.3.tar.gz
$ cd glog-0.3.3
$ ./configure --prefix=/home/liudanny/local_install
$ make -j2
$ make install

#BLAS

$ tar zxvf OpenBLAS-0.2.14.tar.gz
$ cd OpenBLAS-0.2.14
$ make TARGET=ATOM -j2
$ make PREFIX=/home/liudanny/local_install install

#HDF5

$ tar jxvf hdf5-1.8.9.tar.bz2
$ cd hdf5-1.8.9
$ ./configure --prefix=/home/liudanny/local_install/
$ make -j2 && make install

#OpenCV

$ wget -O opencv-2.4.13.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.13/opencv-2.4.13.zip/download
$ uzip opencv-2.4.13.zip
$ unzip opencv-2.4.13.zip
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/liudanny/local_install -D BUILD_NEW_PYTHON_SUPPORT=OFF -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -DWITH_IPP=OFF ..
$ make -j2
$ make install

#LMDB/LevelDB

$ tar zxvf lmdb.tgz
$ cd libraries/liblmdb
$ make -j2
$ cp lmdb.h ~/local_install/include
$ cp libleveldb.so* ~/local_install/lib/

$ tar zxvf leveldb-1.7.0.tar.gz
$ cd leveldb-1.7.0
$ make -j2
$ cp -r include/leveldb  ~/local_install/include/
$ cp liblmdb.so ~/local_install/lib/

# Snappy

$ tar zxvf snappy-1.1.1.tar.gz
$ cd snappy-1.1.1
$ ./configure --prefix=/home/liudanny/local_install/
$ make -j2 && make install

# Check ~/local_install

$ cd ~/local_install
$ tree -d -L 2
.
|-- bin
|-- include
|   |-- boost
|   |-- gflags
|   |-- glog
|   |-- google
|   |-- leveldb
|   |-- opencv
|   `-- opencv2
|-- lib
|   |-- cmake
|   `-- pkgconfig
`-- share
    |-- doc
    |-- hdf5_examples
    `-- OpenCV

# Caffe

git clone https://github.com/BVLC/caffe.git
cd caffe
vi Makefile.config
INCLUDE_DIRS := /home/liudanny/local_install/include $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := /home/liudanny/local_install/lib $(PYTHON_LIB) /usr/local/lib /usr/lib
make -j2
make test
make runtest

# Test a program

blob_demo.cpp
#include <vector>
#include <iostream>
#include <caffe/blob.hpp>
using namespace caffe;
using namespace std;
int main(void)
{
  Blob<float> a;
  cout<<"Size : "<< a.shape_string()<<endl;
  a.Reshape(1, 2, 3, 4); 
  cout<<"Size : "<< a.shape_string()<<endl;
   
  float * p = a.mutable_cpu_data();
  for(int i = 0; i < a.count(); i++)
  {
    p[i] = i;
  }
  for(int u = 0; u < a.num(); u++)
  {
    for(int v = 0; v < a.channels(); v++)
    {   
      for(int w = 0; w < a.height(); w++)
      {   
        for(int x = 0; x < a.width(); x++)
        {   
          cout<<"a["<<u<<"]["<<v<<"]["<<w<<"]["<<x<<"] = "<< a.data_at(u, v, w, x)<<endl;
        }   
      }   
    }   
  }
 
  cout<<"ASUM = "<<a.asum_data()<<endl;
  cout<<"SUMSQ = "<<a.sumsq_data()<<endl;
 
  return 0;
}

  Setup environment variables and compile the example code
$ export CAFFE_ROOT=/home/liudanny/git/caffe
$ export CAFFE_DPKG_INCLUDE=/home/liudanny/local_install/include
$ export CAFFE_DPKG_LIB=/home/liudanny/local_install/lib
$ export LD_LIBRARY_PATH=$CAFFE_ROOT/build/lib/:$LD_LIBRARY_PATH
$ g++ -o app blob_demo.cpp -I $CAFFE_ROOT/include/ -I $CAFFE_DPKG_INCLUDE/ -D CPU_ONLY -I $CAFFE_ROOT/.build_release/src/ -L $CAFFE_ROOT/build/lib/ -L $CAFFE_DPKG_LIB/ -lcaffe -lglog
  
  Run the program app
$ export LD_LIBRARY_PATH=$CAFFE_ROOT/build/lib/:$LD_LIBRARY_PATH
$ ./app
Size : (0)
Size : 1 2 3 4 (24)
a[0][0][0][0] = 0
a[0][0][0][1] = 1
a[0][0][0][2] = 2
a[0][0][0][3] = 3
a[0][0][1][0] = 4
a[0][0][1][1] = 5
a[0][0][1][2] = 6
a[0][0][1][3] = 7
a[0][0][2][0] = 8
a[0][0][2][1] = 9
a[0][0][2][2] = 10
a[0][0][2][3] = 11
a[0][1][0][0] = 12
a[0][1][0][1] = 13
a[0][1][0][2] = 14
a[0][1][0][3] = 15
a[0][1][1][0] = 16
a[0][1][1][1] = 17
a[0][1][1][2] = 18
a[0][1][1][3] = 19
a[0][1][2][0] = 20
a[0][1][2][1] = 21
a[0][1][2][2] = 22
a[0][1][2][3] = 23
ASUM = 276
SUMSQ = 4324

P.S:
I also write a Makefile for all of these tedious work:
CAFFE_ROOT = /home/liudanny/git/caffe
CAFFE_DPKG_INCLUDE = /home/liudanny/local_install/include
CAFFE_DPKG_LIB = /home/liudanny/local_install/lib

CC = g++
CFLAGS = -I $(CAFFE_ROOT)/include/ -I $(CAFFE_DPKG_INCLUDE)/ -D CPU_ONLY -I $(CAFFE_ROOT)/.build_release/src/
LDFLAGS =  -L $(CAFFE_ROOT)/build/lib/ -L $(CAFFE_DPKG_LIB)/ 
LIBS = -lcaffe -lglog

all: app

app: main.o
 $(CC) main.o -o app $(LDFLAGS) $(LIBS)

main.o:
 $(CC) $(CFLAGS) -c main.cpp

clean:
 rm -f main.o app

Comments

Blogger said…
If you want your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (even if they're dating somebody else now) you gotta watch this video
right away...

(VIDEO) Why your ex will NEVER get back...

Popular posts from this blog

[Open vSwitch] How to get port statistics from interface in OVS

[Quagga] How to compile and install Quagga on Ubuntu 12.04

[JSON] How to use jansson lib to generate JSON data in C