본문 바로가기

컴퓨터이야기

Caffe 설치하기

http://caffe.berkeleyvision.org/install_apt.html 참조

먼저 파이썬 환경을 셋업하자

conda create --name caffe_dev1
source activate caffe_dev1



1. Opencv를 설치하자
$ wget https://github.com/Itseez/opencv/archive/2.4.11.zip
 
$ unzip 2.4.11.zip
$ cd opencv-2.4.11
$ mkdir release
$ cd release
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
 
$ make
$ sudo make install


또는

conda install opencv=2.4.11


2. 라이브러리를 설치하자
sudo apt-get update sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler sudo apt-get install --no-install-recommends libboost-all-dev
bumjh

==> conda install scikit-image

3. CUDA 미설치

NVIDIA 드라이버가 없어서 skip



4. caffe 다운받기

git clone https://github.com/BVLC/caffe.git cd caffe cp Makefile.config.example Makefile.config

----------------------------------------------------------
Makefile.config 파일에서 두가지만 체크!
CPU_ONLY := 1

PYTHON_INCLUDE := /usr/local/include/python2.7 \

                                          /usr/local/include/python2.7/numpy
------------------------------------------------

만약 Anaconda Python을 사용한다면 위를 주석처리하고 아래의 줄을 찾아 주석을 해제한다.

ANACONDA_HOME := $(HOME)/anaconda
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
    # $(ANACONDA_HOME)/include/python2.7 \
    # $(ANACONDA_HOME)/lib/python2.7/dist-packages/numpy/core/include \

# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
5. 컴파일하기


mkdir build 
cd build 
cmake .. 
make all 
make install 
make runtestmake clean make all make test make runtest


==============
중간에 오류가 나서
conda install -c conda-forge icu=56.1
이렇게 해결!

make test make runtest


6. 실행 결과








Prerequisites

Caffe has several dependencies:

  • CUDA is required for GPU mode.
    • library version 7+ and the latest driver version are recommended, but 6.* is fine too
    • 5.5, and 5.0 are compatible but considered legacy
  • BLAS via ATLAS, MKL, or OpenBLAS.
  • Boost >= 1.55
  • protobufgloggflagshdf5

Optional dependencies:

  • OpenCV >= 2.4 including 3.0
  • IO libraries: lmdbleveldb (note: leveldb requires snappy)
  • cuDNN for GPU acceleration (v6)

Pycaffe and Matcaffe interfaces have their own natural needs.

  • For Python Caffe: Python 2.7 or Python 3.3+numpy (>= 1.7), boost-provided boost.python
  • For MATLAB Caffe: MATLAB with the mex compiler.

cuDNN Caffe: for fastest operation Caffe is accelerated by drop-in integration of NVIDIA cuDNN. To speed up your Caffe models, install cuDNN then uncomment the USE_CUDNN := 1 flag in Makefile.configwhen installing Caffe. Acceleration is automatic. The current version is cuDNN v6; older versions are supported in older Caffe.

CPU-only Caffe: for cold-brewed CPU-only Caffe uncomment the CPU_ONLY := 1 flag in Makefile.configto configure and build Caffe without CUDA. This is helpful for cloud or cluster deployment.


Python and/or MATLAB Caffe (optional)

Python

The main requirements are numpy and boost.python (provided by boost). pandas is useful too and needed for some examples.

You can install the dependencies with

for req in $(cat requirements.txt); do pip install $req; done

but we suggest first installing the Anaconda Python distribution, which provides most of the necessary packages, as well as the hdf5 library dependency.

To import the caffe Python module after completing the installation, add the module directory to your $PYTHONPATH by export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH or the like. You should not import the module in the caffe/python/caffe directory!

Caffe’s Python interface works with Python 2.7. Python 3.3+ should work out of the box without protobuf support. For protobuf support please install protobuf 3.0 alpha (https://developers.google.com/protocol-buffers/). Earlier Pythons are your own adventure.

MATLAB

Install MATLAB, and make sure that its mex is in your $PATH.

Caffe’s MATLAB interface works with versions 2015a, 2014a/b, 2013a/b, and 2012b.

for Ubuntu (< 17.04)

General dependencies

sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev

CUDA: Install by apt-get or the NVIDIA .run package. The NVIDIA package tends to follow more recent library and driver versions, but the installation is more manual. If installing from packages, install the library and latest driver separately; the driver bundled with the library is usually out-of-date. This can be skipped for CPU-only installation.

BLAS: install ATLAS by sudo apt-get install libatlas-base-dev or install OpenBLAS by sudo apt-get install libopenblas-dev or MKL for better CPU performance.

Python (optional): if you use the default Python you will need to sudo apt-get install the python-devpackage to have the Python headers for building the pycaffe interface.

Compatibility notes, 16.04

CUDA 8 is required on Ubuntu 16.04.

Remaining dependencies, 14.04

Everything is packaged in 14.04.

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

CMake Build

In lieu of manually editing Makefile.config to configure the build, Caffe offers an unofficial CMake build thanks to @Nerei, @akosiorek, and other members of the community. It requires CMake version >= 2.8.7. The basic steps are as follows:

mkdir build
cd build
cmake ..
make all
make install
make runtest

See PR #1667 for options and details.

'컴퓨터이야기' 카테고리의 다른 글

시그모이드함수 미분  (0) 2018.02.05
Pycaffe matcaffe 설치하기  (0) 2017.11.08
openface repository  (0) 2017.11.02
openface 테스트  (0) 2017.11.02
openface 설치하기  (0) 2017.11.01