ubuntu18安装caffe(CPU)

1、前言

历时不知多少天,终于在自己电脑上配置好了caffe环境

2、所需环境

1、ubuntu18.04
2、python3.6 (默认是只有3.6)

3、安装

3.1切换清华源

cp /etc/apt/sources.list /etc/apt/sources_backup.list
vim /etc/apt/sources.list
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

先将原始的sources.list清空,再将上述清华源粘贴到sources.list中,更新一下。

sudo apt-get update
sudo apt-get upgrade

3.2 安装依赖包

apt-get install libprotobuf-dev
apt-get install libleveldb-dev
apt-get install libsnappy-dev
apt-get install libopencv-dev
apt-get install libhdf5-serial-dev
apt-get install protobuf-compiler
apt-get install libgflags-dev
apt-get install libgoogle-glog-dev
apt-get install liblmdb-dev
apt-get install libatlas-base-dev

如果遇到 E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系 ,千万不要用 aptitude 替换 apt-get,因为ubuntu18中二者不兼容。(我使用清华源没有保证错,在使用阿里云源时报错了)

3.3、下载caffe源代码,并解压

apt-get install git
git clone git://github.com/BVLC/caffe.git 

如果克隆超时,可以直接去github中下载。

解压(根据下载的压缩文件类型进行解压):
unzip caffe-mast.zip

3.4、编译

进入caffe文件夹中

cp Makefile.config.example Makefile.config

修改 Makefile.config

在这里插入图片描述
ubuntu18安装caffe(CPU)_第1张图片
ubuntu18安装caffe(CPU)_第2张图片
依次执行

make all

遇到报错:

Makefile:591: recipe for target ‘.build_release/src/caffe/internal_thread.o’ failed
make: *** [.build_release/src/caffe/internal_thread.o] Error 1

解决:

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

再次执行:

make all
make test
make runtest #到这一步就太幸福了

3.5 配置python环境
进去caffe文件下的python目录
此处使用pip3安装

apt install python3-pip
for req in $(cat requirements.txt); do pip3 install $req; done

3.6 将python加入全局环境变量
注意此处的python路径,写自己对应的

vim ~/.bashrc
在文件的最后面添加一条语句
export PYTHONPATH=/home/用户名/caffe/python:$PYTHONPATH

make pycaffe

ubuntu18安装caffe(CPU)_第3张图片

至此结束,完成

参考

https://www.cnblogs.com/acgoto/p/11570188.html
https://blog.csdn.net/weixin_30725315/article/details/98363945

你可能感兴趣的:(caffe,深度学习,linux,ubuntu)