Ubuntu18.04 安装caffe CPU版本

1, 添加依赖
sudo apt-get install -y vim make cmake gcc g++ git
sudo apt-get install -y python-pip libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev
sudo apt-get install -y protobuf-compiler libatlas-base-dev libhdf5-serial-dev libboost-all-dev libboost-all-dev
2,安装python相关包
sudo apt-get install -y libopencv-dev python-opencv
sudo apt-get install -y python-pandas python-sympy python-nose
sudo apt-get install -y python-numpy python-scipy python-matplotlib ipython ipython-notebook
3,caffe配置

3.1 下载caffe源码

git clone https://github.com/BVLC/caffe.git

3.2 进入caffe/python目录

cat requirements.txt    # 查看安装caffe的依赖
su - root                      # 使用root权限执行下面的命令,并进入caffe/python目录
pip install --upgrade pip
for req in $(cat requirements.txt); do sudo pip install $req;done
su - rose # 退出root权限,进入rose权限

3.3 在caffe目录,修改make.config配置文件,编译caffe

cd ..
pwd
  /home/rose/work/caffe
cp Makefile.config.example Makefile.config
sudo gedit Makefile.config

修改两处
1,CPU_ONLY :=1,去掉前面#符号,CPU版本
2,原来数据

# Whatever else you find you need goes here.
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/hdf5/serial
4 编译caffe
pwd
  /home/rose/work/caffe
sudo make pycaffe     # 编译python,方便运行MNIST
sudo make all
sudo make test
sudo make runtest

执行以上步骤,编译成功

5,训练MNIST

5.1 添加系统环境变量

``` vi ~/.bashrc export PYTHONPATH=/home/rose/work/caffe/python:$PYTHONPATH source ~/.bashrc ```

5.2 测试

import caffe
不报错,导入成功

5.3 获取MNIST数据集

./data/mnist/get_mnist.sh
./examples/mnist/create_mnist.sh   # 将其转换为lmdb数据库格式

5.4 训练网络

./examples/mnist/train_lenet.sh

5.5 测试网络

./build/tools/caffe.bin test -model examples/mnist/lenet_train_test.prototxt -weights  examples/mnist/lenet_iter_10000.caffemodel -iterations 100

你可能感兴趣的:(环境搭建)