Centos7.6上 Caffe 环境安装
系统环境
【OS】centos 7.6
【arch】 x86_64
【python环境】python3.7.5(本文环境中将python及pip对应配置成“python3.7”“pip3.7”,下文中“python3.7”“pip3.7”均针对该python版本)
安装python3.7.5
安装依赖
yum install libffi libffi-devel yum search bzip2 yum install bzip2-devel.x86_64(根据上一步yum search bzip2支持的bzip包)
下载安装包链接:
https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz
编译安装
tar -xzvf Python-3.7.5.tgz cd Python-3.7.5/ ./configure --prefix=/usr/local/python3.7.5 --enable-shared CFLAGS=-fPIC sudo make && make install
加入链接库与环境变量
在/etc/ld.so.conf.d/创建libpython.conf
写入:/usr/local/python3.7.5/lib
执行:ldconfig
/etc/profile写入:export PATH=/usr/local/python3.7.5/bin:$PATH
执行:source /etc/profile *
依赖包安装
yum命令可直接安装的依赖包
执行:
sudo yum install protobuf-devel snappy-devel opencv-devel boost-devel
需要编译安装的依赖包
cmake
下载地址:https://cmake.org/files/v3.3/cmake-3.3.2.tar.gz
执行:
tar xzvf cmake-3.3.2.tar.gz; cd cmake-3.3.2; ./bootstrap; gmake; make install
protobuf
下载地址:https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protobuf-all-3.11.2.tar.gz
执行:
tar -xzvf protobuf-all-3.11.2.tar.gz cd protobuf-3.11.2 ./configure make make check make install cd /usr/bin/ mv protoc protoc_27 (注:如存在其它版本,需要换掉) ln -s /usr/local/bin/protoc protoc
glog
glog库会默认安装在/usr/local/lib下,头文件放在/usr/local/include/gflags/
下载地址:https://github.com/google/glog/archive/v0.3.3.tar.gz
执行:
tar zxvf glog-0.3.3.tar.gz; cd glog-0.3.3; ./configure; make && make install
gflags
gflags库会默认安装在/usr/local/lib下,头文件放在/usr/local/include/gflags/
github地址:https://github.com/gflags/gflags
执行:
export CXXFLAGS="-fPIC" unzip gflags-master.zip; cd gflags-master; mkdir build && cd build; export CXXFLAGS="-fPIC" && cmake .. && make VERBOSE=1
lmdb
github地址:https://github.com/LMDB/lmdb
执行:
unzip lmdb-mdb.master.zip; cd lmdb-mdb.master/libraries/liblmdb; make && make install
hdf5:
hdf5会安装在/usr/local/hdf5/lib下,头文件放在/usr/local/hdf5/include
下载地址:https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.1/src/hdf5-1.10.1.tar
执行: tar xf hdf5-1.10.1.tar; cd hdf5-1.10.1; ./configure --prefix=/usr/local/hdf5; make; make check; make install; make check-install
leveldb:
leveldb会默认安装在/usr/local/lib下,头文件放在/usr/local/include/leveldb
下载地址:https://codeload.github.com/google/leveldb/tar.gz/v1.20
执行:
tar xf leveldb-1.20.tar.gz; cd leveldb-1.20; make; sudo cp -r include/leveldb /usr/local/include; sudo cp out-shared/lib* /usr/local/lib
openblas:
github地址:https://github.com/xianyi/OpenBLAS
执行:
unzip OpenBLAS-develop.zip; cd OpenBLAS-develop; make -j4; make install
boost-python3
下载地址:https://liquidtelecom.dl.sourceforge.net/project/boost/boost/1.73.0/boost_1_73_0.zip
解压 tar -xvf boost173_0.zip
修改包问题
修改tools/build/src/tools/python.jam第547行,将:
includes ?= $(prefix)/include/python$(version);
修改为:
includes ?= $(prefix)/include/python$(version)m ;
执行:
cd boost_1_73_0 ./bootstrap.sh --with-python=/usr/local/python3.7.5/bin/python3 --prefix=/usr/local/boost ./b2 stage threading=multi link=shared sudo ./b2 install threading=multi link=shared
Caffe安装
下载
github地址:https://github.com/BVLC/caffe
执行:
unzip caffe-master.zip; mv caffe-master /usr/local/caffe cd /usr/local/caffe; cp Makefile.config.example Makefile.config vi ./Makefile.config
Makefile.config修改
将:
#CPU_ONLY := 1
修改为:
CPU_ONLY := 1
将:
BLAS := atlas
修改为:
BLAS := open
将:
# BLAS_INCLUDE := /path/to/your/blas # BLAS_LIB := /path/to/your/blas
修改为:
BLAS_INCLUDE := /opt/OpenBLAS/include BLAS_LIB := /opt/OpenBLAS/lib
将:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
修改为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/hdf5/include LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/hdf5/lib /usr/local/python3.7.5/lib
将:
YTHON_INCLUDE := /usr/include/python2.7 \ /usr/lib/python2.7/dist-packages/numpy/core/include
修改为:
PYTHON_INCLUDE :=/usr/local/python3.7.5/include\ /usr/local/python3.7.5/include/python3.7m\ /root/.local/lib/python3.7/site-packages/numpy/core/include
注:这里的PYTHON_INCLUD和安装的python3.7.5以及site-packages路径相关,换成本机对应的路径
Makefile修改
将:
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
修改为:
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir)) -std=c++11
编译
执行: make all -j4 make test; make runtest
当显示如下时,说明caffe已经安装成功
Python3.7 + Caffe
进入caffe根目录的python文件夹下,里面有一个requirements.txt。
执行:
for req in $(cat requirements.txt); do sudo pip3.7 install $req;done
在caffe目录下执行:
make pycaffe
当显示如下时,说明pycaffe已经安装成功
添加到环境变量
在文件/etc/profile写入:
export PYTHONPATH=/usr/local/caffe/python:$PYTHONPATH
执行:
source /etc/profile
- 点赞
- 收藏
- 关注作者
评论(0)