文栏 - 信息技术 - 浏览文章 - Installing Caffe with Aanaconda on CentOS (Tested on 7.2)
Installing Caffe with Aanaconda on CentOS (Tested on 7.2)
发布时间: 2016/10/7 11:10:57 作者: 素素 出处: 本站发布

Prerequisites

NVidia Driver, Cuda Toolkit 7.5, cuDNN v5 or v5.1, Anaconda2-4.0.0 64bit or Anaconda2-4.2.0 64bit and OpenCV 3.1 (using conda installation) should be installed and configed following previous documents.

Install General Dependencies

# yum install protobuf-devel leveldb-devel snappy-devel opencv-devel boost-devel hdf5-devel
# yum install gflags-devel glog-devel lmdb-devel
# yum install openblas-devel

Download Caffe

Go to this page https://github.com/BVLC/caffe. Download the latest version.

Tested Version: 2c34393fc5aec9899d92c64be41598a3184d3347 (20160928) . This version is a refined version based on release candidate 3. Link: https://github.com/BVLC/caffe/archive/2c34393fc5aec9899d92c64be41598a3184d3347.zip

Download the file to /opt/ml-items, unzip it.

# wget https://github.com/BVLC/caffe/archive/2c34393fc5aec9899d92c64be41598a3184d3347.zip
# unzip 2c34393fc5aec9899d92c64be41598a3184d3347.zip
# mv caffe-2c34393fc5aec9899d92c64be41598a3184d3347 caffe-2c34393

Config Makefile

# cd caffe-2c34393
# cp Makefile.config.example Makefile.config
# vi Makefile.config

If you do not want to change it one by one, a modified version of mine can be used. The steps for changing it are provided.

^^^^^^ Items for Change

User cuDNN

uncomment

USE_CUDNN := 1 

Use OpenCV version 3

uncomment

OPENCV_VERSION := 3

Use OpenBLAS

change

BLAS := atlas

to

BLAS := open

uncomment

BLAS\_INCLUDE

and change it to

BLAS_INCLUDE := /usr/include/openblas

uncomment

BLAS_LIB

and change it to B

LAS_LIB := /usr/lib64

Replace Default Path with Anaconda Path

comment

PYTHON_INCLUDE := /usr/include/python2.7/usr/lib/python2.7/dist-packages/numpy/core/include

uncomment

ANACONDA_HOME := $(HOME)/anaconda
PYTHON_INCLUDE

change it into

ANACONDA_HOME := /opt/anaconda2

comment

PYTHON_LIB := /usr/lib

uncomment

PYTHON_LIB := $(ANACONDA_HOME)/lib

uncomment

WITH_PYTHON_LAYER := 1

Add 64 bit Library Path

add

/usr/lib64

to the end of LIBRARY_DIRS

^^^^^^ End Items for Change

Compilation

Link OpenCV Libs

Since we install OpenCV using Anaconda, the path of OpenCV libraries are a little different with the normal installation. Link operations should be used.

# cd /usr/lib64
# ln -s /opt/anaconda2/lib/libhdf5.so.10 libhdf5.so.10
# ln -s /opt/anaconda2/lib/libhdf5_hl.so.10 libhdf5_hl.so.10
# ln -s /opt/anaconda2/lib/libopencv_core.so.3.1 libopencv_core.so.3.1
# ln -s /opt/anaconda2/lib/libopencv_highgui.so.3.1 libopencv_highgui.so.3.1
# ln -s /opt/anaconda2/lib/libopencv_imgproc.so.3.1 libopencv_imgproc.so.3.1
# ln -s /opt/anaconda2/lib/libopencv_imgcodecs.so.3.1 libopencv_imgcodecs.so.3.1
# ldconfig

Compile Caffe by multithread. For example, -j8 use 8 threads. (A good choice for the number of threads is the number of cores in your machine)

# make all -j8
# make test -j8
# make runtest -j8

For the last command, it should show PASSED at the end.

Run Samples (Check Points)

Download and create MNIST database

# ./data/mnist/get_mnist.sh
# ./examples/mnist/create_mnist.sh

Run it. With a Titan X, the following script should be finished within 25 seconds.

# ./examples/mnist/train_lenet.sh

Python Interface

Comoplie the Python interface.

# make pycaffe -j8

Install dependency module in Python

# conda install protobuf
# conda install -c https://conda.binstar.org/dougal lmdb

Add Caffe module directory to PYTHONPATH

# vi /etc/profile

Add the following line to the end of /etc/profile

export PYTHONPATH=$PYTHONPATH:/opt/ml-items/caffe-2c34393/python:

Refresh

# source /etc/profile

Check Points

# python

>> import caffe

It should be no error.

Copy mnist_example.py to /opt/ml-items/caffe-2c34393/examples and run it. It should be no error.

# cd /opt/ml-items/caffe-2c34393/examples
# python mnist_example.py

end Check Points

所属分类: 信息技术   所属专题: 原创
共有 7143 人次浏览

评论作者:
电子邮件:
评论内容:
投票评价:
验 证 码:
图片包含4个随机字符,点击刷新
请输入上面图片中的随机字符