ubuntu14.04 安装caffe步骤 CPU版本

xiaoxiao2021-02-28  86

(1)安装依赖库:

$ sudo apt-get install libprotobuf-devlibleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler

$ sudo apt-get install--no-install-recommends libboost-all-dev

(2)安装BLAS:

$ sudo apt-get install libatlas-base-dev

(3)安装python:

如果没有安装python,先安装python

如果已经安装,在命令行直接输入python,打开python查看版本号:

$ python

Python 2.7.6 (default, Oct 26 2016,20:30:19)

Ctrl+D退出python

(4)安装pycaffe接口依赖:

$ sudo apt-get install python-dev

(5)安装opencv:

如果没有安装opencv,先安装opencv

如果已经安装opencv,查看opencv版本

$ pkg-config --modversion opencv

3.2.0

(6)Ubuntu14.04还需安装其他依赖库:

$ sudo apt_get install libgflags-devlibgoogle-glog-dev liblmdb-dev

(7)下载Caffe:

$ cd ~

$ git clonegit://github.com/BVLC/caffe.git

(8)修改相关文件

a、为了make指令的执行,将 Makefile.config.example文件名重命名修改为Makefile.config。

$ cd ~/caffe

$ cp Makefile.config.exampleMakefile.config

b、打开Makefile.config文件:去掉CPU_ONLY:= 1的注释,由于是仅CPU安装,注释掉CUDA有关的行: 

#CUDA_DIR := /usr/local/cuda 

#CUDA_ARCH := -gencodearch=compute_20,code=sm_20 \ 

#       -gencode arch=compute_20,code=sm_21 \ 

#       -gencode arch=compute_30,code=sm_30 \ 

#       -gencode arch=compute_35,code=sm_35 \ 

#       -gencode arch=compute_50,code=sm_50 \ 

#       -gencode arch=compute_50,code=compute_50 

去掉注释WITH_PYTHON_LAYER:= 1 

INCLUDE_DIRS := $(PYTHON_INCLUDE)/usr/local/include /usr/include/hdf5/serial 

LIBRARY_DIRS := $(PYTHON_LIB)/usr/local/lib /usr/lib /usr/lib/i386-linux-gnu/hdf5/serial/usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial 

#TEST_GPUID := 0 

c、修改caffe/examples/cpp_classification/classification.cpp文件,加入:

#include <opencv2/imgproc/types_c.h>

#include<opencv2/objdetect/objdetect_c.h>

d、Makefile 修改:

LIBRARIES += glog gflags protobufboost_system boost_filesystem m hdf5_hl hdf5 lmdb opencv_core opencv_highguiopencv_imgproc opencv_imgcodecs

(9)接下来就要进行编译啦,直接make

$ cd ~/fast-rcnn/caffe-fast-rcnn

$ make all 

$ make test

$ make runtest

若没有错误则表示安装成功,否则makeclean,重新编译。

(10)配置pycaffe:

a、安装依赖库:

$ sudo apt-get install python-numpypython-scipy python-matplotlib python-sklearn python-skimage python-h5pypython-protobuf python-leveldb python-networkx python-nose python-pandaspython-gflags Cython ipython

$ sudo apt-get install protobuf-c-compilerprotobuf-compiler

b、编译:

$ cd ~/caffe

$ make pycaffe

c、添加~/caffe/Python到$PYTHONPATH:

$ sudo gedit /etc/profile

 末尾添加: export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH

$ source /etc/profile # 使之生效

d、测试是否可以引用:

$ python

Python 2.7.6 (default, Oct 26 2016,20:30:19)

[GCC 4.8.4] on linux2

Type "help","copyright", "credits" or "license" for moreinformation.

>>> import caffe

>>> 

转载请注明原文地址: https://www.6miu.com/read-78637.html

最新回复(0)