Ubuntu 安装 Caffe
Caffe
Caffe 安装(Python2 CPU版本)
参考博文https://blog.csdn.net/pangyunsheng/article/details/79418896
- 安装环境
- Ubuntu 16.04 STL
- Python 2.7(Caffe对Python3支持不好)
安装步骤
apt安装依赖
sudo apt-get install python-pip
pip install ipython==5.3.0 --user
pip install matplotlib==2.2.3 --user
pip install 'scikit-image<0.15' --user
sudo apt-get install python-numpy
sudo apt-get install libprotobuf-dev
sudo apt-get install libleveldb-dev
sudo apt-get install libsnappy-dev
sudo apt-get install libopencv-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install protobuf-compiler
sudo apt-get install libgflags-dev
sudo apt-get install libgoogle-glog-dev
sudo apt-get install liblmdb-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get install git
克隆caffe项目
mkdir ~/Documents/GitRepos
cd ~/Documents/GitRepos
: 在当前用户的Documents目录下创建GitRepos目录用于存放git克隆下来的项目git clone git://github.com/BVLC/caffe.git
配置caffe的Makefile
cd caffe
cp Makefile.config.example Makefile.config
- 修改
Makefile.config
配置文件- 去掉
CPU_ONLY
前面的注释 - 在
INCLUDE_DIRS
中添加/usr/include/hdf5/serial
- 在
LIBRARY_DIRS
中添加/usr/lib/x86_64-linux-gnu/hdf5/serial
- 去掉
通过make编辑
make all -j 4
make test -j 4
make runtest
编译Python 2接口
cd python
for req in $(cat requirements.txt); do pip install $req; done
pip install -r requirements.txt --user
export PYTHONPATH=~/Documents/GitRepos/caffe/python:$PYTHONPATH
exec "$SHELL"
cd ..
make pycaffe -j 4
- 重启一个Terminal
python
import caffe
: 没有提示模块没有扎到则正确
Caffe(Python3虚拟环境 CPU版本)
apt安装依赖(请先安装pyenv, 并切换到Python3的虚拟环境)
+ `sudo apt-get install python3-pip` + `sudo apt-get install python-numpy` + `sudo apt-get install libprotobuf-dev` + `sudo apt-get install libleveldb-dev` + `sudo apt-get install libsnappy-dev` + `sudo apt-get install libopencv-dev` + `sudo apt-get install libhdf5-serial-dev` + `sudo apt-get install protobuf-compiler` + `sudo apt-get install libgflags-dev` + `sudo apt-get install libgoogle-glog-dev` + `sudo apt-get install liblmdb-dev` + `sudo apt-get install libatlas-base-dev` + `sudo apt-get install --no-install-recommends libboost-all-dev` + `sudo apt-get install git`
克隆caffe项目
mkdir ~/Documents/GitRepos
cd ~/Documents/GitRepos
: 在当前用户的Documents目录下创建GitRepos目录用于存放git克隆下来的项目git clone git://github.com/BVLC/caffe.git
配置caffe的Makefile
cd caffe
cp Makefile.config.example Makefile.config
- 修改
Makefile.config
配置文件- 去掉
CPU_ONLY
前面的注释 - 在
INCLUDE_DIRS
中添加/usr/include/hdf5/serial
- 在
LIBRARY_DIRS
中添加/usr/lib/x86_64-linux-gnu/hdf5/serial
- 注释掉PYTHON2的项
PYTHON_INCLUDE := /home/yourname/.pyenv/versions/3.5.2/include/python3.5m \ /home/yourname/.pyenv/versions/3.5.2/lib/python3.5/site-packages/numpy/core/include
- 取消
PYTHON_LIBRARIES
的注释, 修改为PYTHON_LIBRARIES := boost_python-py35 python3.5m
- 注意: 到
/usr/lib/x86_64-linux-gnu
目录下确定存在libboost_python3.5m.so
, 如果没有则将虚拟环境中的复制过来 - 修改
PYTHON_LIB := /home/yourname/.pyenv/versions/3.5.2/lib
- 取消
WITH_PYTHON_LAYER := 1
的注释
- 去掉
通过make编辑
make all -j 4
make test -j 4
make runtest
编译Python 3接口
cd python
pip install -r requirements.txt --user
export PYTHONPATH=~/Documents/GitRepos/caffe/python:$PYTHONPATH
exec "$SHELL"
cd ..
make pycaffe -j 4
- 重启一个Terminal
python
import caffe
: 没有提示模块没有扎到则正确