Ubuntu18.04上 Caffe 环境安装
系统环境
ubuntu18.04
安装步骤
安装python3.7.5
注意,哪怕本地已经装了python3.7.5,也必须重装!!
安装依赖
apt-get install libffi-dev (很重要,必须先安装再配置python) apt-get install zlib* apt-get install gcc apt-get install g++
下载安装包
下载地址: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
安装相关依赖包
编译安装protobuf
下载
下载地址:https://github.com/protocolbuffers/protobuf/releases/download/v3.11.2/protobuf-all-3.11.2.tar.gz
安装依赖包
pip3.7 install six
编译安装
tar -xzvf protobuf-all-3.11.2.tar.gz cd protobuf-3.11.2 / ./configure make -j8 make check -j8 sudo make install -j8 cd python python3.7 setup.py build python3.7 setup.py test python3.7 setup.py install
命令行安装其它依赖包
sudo apt-get install libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler sudo apt-get install --no-install-recommends libboost-all-dev sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev sudo apt-get install git cmake build-essential libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt-get install python-numpy libtbb2 libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
安装Caffe
下载
下载地址:https://github.com/BVLC/caffe.git
放到合适路径
mv caffe /usr/local
修改caffe目录下Makefile.config(附件有修改好的版本,如果安装目录与教程一致可直接使用)
将:
#CPU_ONLY := 1
修改为:
CPU_ONLY := 1
将:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
修改为:
INCLUDE_DIRS :=$(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
将:
PYTHON_LIB := /usr/lib
修改为:
PYTHON_LIB :=/usr/local/python3.7.5/lib
将:
PYTHON_INCLUDE := /usr/include/python2.7 \ /usr/lib/python2.7/dist-packages/numpy/core/include
修改为:
# PYTHON_INCLUDE := /usr/include/python2.7 \ # /usr/lib/python2.7/dist-packages/numpy/core/include
将:
# PYTHON_LIBRARIES := boost_python3 python3.5m # PYTHON_INCLUDE := /usr/include/python3.5m \ # /usr/lib/python3.5/dist-packages/numpy/core/include
修改为:
PYTHON_LIBRARIES :=boost_python-py36 python3.7m PYTHON_INCLUDE :=/usr/local/python3.7.5/include\ /usr/local/python3.7.5/include/python3.7m\ /usr/local/python3.7.5/lib/python3.7/site-packages/numpy/core/include
将:
#WITH_PYTHON_LAYER := 1
修改为:
WITH_PYTHON_LAYER := 1
修改caffe目录下Makefile文件
将:
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
修改为:
NVCCFLAGS+=-D_FORCE_INLINES-ccbin=$(CXX)-Xcompiler-fPIC $(COMMON_FLAGS)
将:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
修改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
将:
PYTHON_LIBRARIES ?= boost_python python2.7
修改为:
PYTHON_LIBRARIES ?=boost_python3 python3.7m
编译安装
make all -j8 make test -j8 make runtest -j8 make pycaffe -j8
配置环境变量
在文件/etc/profile写入:
export PYTHONPATH=/usr/local/caffe/python:$PYTHONPATH
执行:
source /etc/profile
验证
可能遇到的报错
解决命令:
ln -s /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5_hl.so /usr/lib/libhdf5_hl.so ln -s /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so /usr/lib/libhdf5.so
解决命令:
ln -s /usr/local/python3.7.5/lib/libpython3.7m.so.1.0 /usr/lib/libpython3.7m.so
解决命令:
pip3.7 install -U scikit-image
解决命令:
find / -name "*boost_python*"
如果找到里面是:
将上面Makefile. config 中的
PYTHON_LIBRARIES :=boost_python-py36 python3.7m
修改为:
PYTHON_LIBRARIES :=boost_python-py35 python3.7m
将上面Makefile中的:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
修改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial opencv_core opencv_highgui opencv_imgproc
解决命令:
pip3.7 install six==1.9
解决命令:
find / -name libprotoc.so.10 找到libprotoc.so.10所在位置如下:
在/etc/ld.so.conf.d/创建libpython.conf 写入对应路径,如:/usr/local/protobuf-3.0.0-beta-4/src/.libs/libprotoc.so.10 执行:ldconfig
后续
python2.7 + caffe
不同点:
安装python2.7时:
./configure --prefix=/usr/local/python2.7.14 --enable-shared CFLAGS=-fPIC --enable-unicode=ucs4
Caffe的makefile.config对应着python2.7进行配置
ubuntu16.04 + python3.7.5 + caffe
protobuf采用附件的3.0.0版本,其它与上文相同。
- 点赞
- 收藏
- 关注作者
评论(0)