Ubuntu 16.4下安装caffe及手写识别

Ubuntu 16.4下安装caffe

1.安装caffe所需要的依赖包

sudo apt-get install git
sudo apt-get install libprotobuf-dev 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 libatlas-base-dev
sudo apt-get install python-dev
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

2.下载Caffe源码:

git clone https://github.com/bvlc/caffe.git
cd caffe/
mv Makefile.config.example Makefile.config

3.修改Makefile和Makefile.config两个文件

修改:Makefile.config:(95行左右)
INCLUDE_DIRS := /usr/include $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
LIBRARY_DIRS :=/usr/lib $(PYTHON_LIB) /usr/local/lib /usr/lib

打开CPU_ONLY := 1(入门建议先只用cpu训练,进阶再用gpu)
修改:Makefile:(181行左右)
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

4.在caffe根目录:

make all -j4

5.运行手写识别过程:在caffe目录下

cd data/mnist
./get_mnist.sh(若没有权限,chmod +x ./get_mnist.sh 赋予权限) 下载数据

6.转换格式

./examples/mnist/create_mnist.sh
7.训练超参数
在/examples/mnist/lenet_solver.prototxt将mode改为cpu
再运行
./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt $@
可以看到最后的结果达到0.9917

I0705 17:10:00.829900 17611 data_layer.cpp:73] Restarting data prefetching from start.
I0705 17:10:00.991636 17608 solver.cpp:398]     Test net output #0: accuracy = 0.9917
I0705 17:10:00.991662 17608 solver.cpp:398]     Test net output #1: loss = 0.0268429 (* 1 = 0.0268429 loss)
I0705 17:10:00.991664 17608 solver.cpp:316] Optimization Done.
I0705 17:10:00.991667 17608 caffe.cpp:259] Optimization Done.

你可能感兴趣的:(Ubuntu 16.4下安装caffe及手写识别)