These days, I am in the middle of the configuration of Caffe in Ubuntu14.04 due to the need of a small project. Here I want to write down the steps to show how to install it.

If you follow the installation instructions of the official site, I think you will be crazy. The documents are not in order. I succeeded to install it according to a Chinese blog. Apart from simple translation, I will also add some contents.

The whole process is as follows:

Environments:

  • Ubuntu 14.04 64bit
  • 8G Memory
  • GeForce GT 705 Graphics Card
  • CUDA 7.5
  • caffe from github

Steps:

  • Install all the dependencies
  • Install CUDA 7.5
  • Install Atlas
  • Install OpenCV
  • Install Anaconda2
  • Install Caffe
  • Compile Python wrapper
  • Test Caffe

Install all the dependencies

1
2
sudo apt-get install build-essential  # basic requirement  
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler #required by caffe

Install CUDA 7.5

You can follow the office website instructions install it. Before you install the packages, you’d better check it whether the package is intact through md5.

1
md5sum package_name

After you finish the installation, please reboot the computer.

1
sudo reboot

Later, we need to configure the environmental variable for cuda.

1
2
3
4
5
6
sudo gedit /etc/profile
# add the content into /etc/profile
export PATH=/usr/local/cuda/bin:$PATH

# make the profile into effect
source /etc/profile

At the same time, we need to add the library path to /etc/ld.so.conf.d folder.

1
2
3
4
5
6
7
cd /etc/ld.so.conf.d
sudo vim cuda.conf
# add the contents into cuda.conf file
/usr/local/cuda/lib64

# make the file into effect
sudo ldconfig

Now we install CUDA SAMPLE

1
2
3
4
5
6
cd /usr/local/cuda/samples
sudo make all -j4 # 4 means the number of your cpu cores
# It will take about 10 mins to complete installation

cd samples/bin/x86_64/linux/release
./deviceQuery
  1. ./deviceQuery Starting…
  2. CUDA Device Query (Runtime API) version (CUDART static linking)
  3. Detected 1 CUDA Capable device(s)
  4. Device 0: “GeForce GTX 670”
  5. CUDA Driver Version / Runtime Version 6.5 / 6.5
  6. CUDA Capability Major/Minor version number: 3.0
  7. Total amount of global memory: 4095 MBytes (4294246400 bytes)
  8. ( 7) Multiprocessors, (192) CUDA Cores/MP: 1344 CUDA Cores
  9. GPU Clock rate: 1098 MHz (1.10 GHz)
  10. Memory Clock rate: 3105 Mhz
  11. Memory Bus Width: 256-bit
  12. L2 Cache Size: 524288 bytes
  13. Maximum Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  14. Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers
  15. Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers
  16. Total amount of constant memory: 65536 bytes
  17. Total amount of shared memory per block: 49152 bytes
  18. Total number of registers available per block: 65536
  19. Warp size: 32
  20. Maximum number of threads per multiprocessor: 2048
  21. Maximum number of threads per block: 1024
  22. Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  23. Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
  24. Maximum memory pitch: 2147483647 bytes
  25. Texture alignment: 512 bytes
  26. Concurrent copy and kernel execution: Yes with 1 copy engine(s)
  27. Run time limit on kernels: Yes
  28. Integrated GPU sharing Host Memory: No
  29. Support host page-locked memory mapping: Yes
  30. Alignment requirement for Surfaces: Yes
  31. Device has ECC support: Disabled
  32. Device supports Unified Addressing (UVA): Yes
  33. Device PCI Bus ID / PCI location ID: 1 / 0
  34. Compute Mode:
  35. < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
  36. deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 6.5, CUDA Runtime Version = 6.5, NumDevs = 1, Device0 = GeForce GTX 670
  37. Result = PASS

If you command window shows the similar result, that means your display card driver is installed successfully, otherwise there will be something wrong with your installation.

Install Atlas

1
sudo apt-get install libatlas-base-dev

Install OpenCV-2.4.10

  1. Download the installation script
  2. Go to the Install-OpenCV/Ubuntu/2.4 folder
    1
    sudo sh ./opencv2_4_10.sh

Install Anaconda2

  • Download Anaaconda2 from official website

  • Unzip and go to the folder

    1
    sudo sh ./Anaconda2-2.4.1-Linux-x86_64.sh
  • Add the Anaconda Library Path

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    sudo vim /etc/ld.so.conf
    # add the contents at the end of the file
    /home/your_name/anaconda2/lib
    # make the file into effect
    sudo ldconfig

    sudo vim ~/.bashrc
    export LD_LIBARY_PATH="/home/your_username/anaconda2/lib:$LD_LIBRARY_PATH"

    export PATH="/home/your_username/anaconda2/bin:$PATH"

    source ~/.bashrc

    #test python version

pythonversion

Install Caffe

  • Download Caffe from github

    then we need to download python dependencies

    1
    2
    3
    cd caffe-master/python
    for req in $(cat requirements.txt);
    do sudo pip install $req; done

    make sure all the dependencies have installed properly, otherwise we will meet many issues when compiling caffe

  • Compile Caffe

1
2
3
cd caffe-master
cp Makefile.config.example Makefile.config
sudo vim Makefile.config

We should make some changes to the configuration.

1
2
3
4
5
6
7
8
# Comment out these lines
ANACONDA_HOME := $(HOME)/anaconda2
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
1
2
3
4
# make sure your current foler is caffe-master
sudo make all -j4
sudo make test
sudo runtest

Compile Python Wrapper

1
2
# make sure your current folder is caffe-master
sudo make pycaffe

Ok, you do a very good job! Congratulations! You have finished all the steps to install caffe. Now let’s make a small test to feel the performance of caffe.

Test

We will use the mnist example to make a test. I also followed a Chinese blog

1
sudo sh data/mnist/get_mnist.sh     # get training data and testing data from the internet

You will see four files in the folder of data/mnist

  • train-images-idx3-ubyte (training samples)
  • train-labels-idx1-ubyte (training samples’ labels)
  • t10k-images-idx3-ubyte (testing samples)
  • t10k-labels-idx1-ubyte (testing samples’ labels)
1
2
3
sudo sh examples/mnist/create_mnist.sh  # transfer the format of original datasets

sudo time sh examples/mnist/train_lenet.sh # make it run(cpu 13mins; GPU 4mins; GPU+cudnn 40 s)
相关文章
评论
分享
  • T Bill vs T Notes vs T Bonds

    T 指的是 Treasury, 国债,债券发行机构为美国中央政府(federal government),为了解决政府日常运营所需资金的问题,例如遇到财政赤字时,不仅可以通过增加税收的方式,也可以通过发债的方式解决政府资金短缺。 美...

    T Bill vs T Notes vs T Bonds
  • 加德满都/巴德岗4日游--最幸福的地区

    时间:20190605-20190608; 从广州乘坐飞机直达加德满都,4个小时。 飞机上可以远远看到珠峰 加德满都海拔1340米左右,比北京晚2小时15分 D1: 加德满都泰米尔到达加德满都机场(标记1)为当地时间11点左右。订的酒...

    加德满都/巴德岗4日游--最幸福的地区
  • I graduated from Nanjing Normal University, majoring in computer science and technology. Now I am applying for Master...

  • 身份信息泄露,南京警方让回户籍所在地报警,户籍所在地警方让去支付宝所在的派出所报警,我到底该去哪里报警??为什么求助那么困难??

    本人南京市溧水区石湫镇人,南京大学毕业,目前香港工作。前段时间遇到一件特别心塞的事情,身份信息被盗,总计盗款38000元左右,已报警,不立案。报警过程更加心塞。 事情大概是这样的: 身份被盗:我的身份证号码(未丢失)+银行卡号码(...

    身份信息泄露,南京警方让回户籍所在地报警,户籍所在地警方让去支付宝所在的派出所报警,我到底该去哪里报警??为什么求助那么困难??
  • 美西之行七 Bryce Canyon

    美西之行七 Bryce Canyon今天前往Bryce Canyon。 路上的视野很开阔,颜色也较之前变得小清新了一些。 看到一辆RV车,载着一家随处转悠 可爱的大叔主动配合照相 马场 小木屋 到达Bryce Canyon 又开始浓...

    美西之行七 Bryce Canyon
  • 美西之旅六 Arches Canyon

    美西之旅六 Arches Canyon离开blanding之后,驱车前往Arches Canyon,中文名为拱石国家公园。 沿途的颜色开始变成橙黄 路上碰到一只被撞死的小鹿,身体还是温热的。这在西部是经常发生的事情 晚上住在一个叫...

    美西之旅六 Arches Canyon
  • 美西之旅五大峡谷到Blanding

    美西之旅 Grand Canyon –> Blanding小镇 离开Page之后,计划去羚羊谷,但是去羚羊谷要经过一片私人领地,造成景区价格偏高,朋友说他之前去过并没有网上照片拍的那么美,同时我们也要赶路,所以决定不再进入羚羊...

    美西之旅五大峡谷到Blanding
  • 美西之旅四大峡谷

    美西之旅 大峡谷(Grand Canyon)进入国家公园第一站--大峡谷。 大峡谷模拟图 我们直接坐蓝线到底,之后一站一个景点下来走 大峡谷 光影倒映在山谷,为其增添新色彩 走走走,拍拍拍 逛完南峡谷,准备驱车进入北峡谷。 北峡谷入...

    美西之旅四大峡谷
  • 美西之旅三 拉斯维加斯到大峡谷

    美西之旅 拉斯维加斯->大峡谷 离开Vegas之后,我们驱车前往Grand Canyon大峡谷。Vegas外围的民宅,沙漠中的家园。每家每户门前都栽种着一颗绿树,即使再荒凉,心中依然绿树成荫。 在去往大峡谷的中途会经过Hover...

    美西之旅三 拉斯维加斯到大峡谷
  • 美西之旅之拉斯维加斯

    美西之旅 洛杉矶->拉斯维加斯 早上9点多从洛杉矶出发,沿着15号公路向东北方向驶去,进入拉斯维加斯。从洛杉矶到拉斯维加斯大概4个小时车程,途中经过两个很大的OutLet,买买买忘了时间,大概到晚上12点多才到拉斯。原本计划只在...

    美西之旅之拉斯维加斯
Please check the comment setting in config.yml of hexo-theme-Annie!