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兩個(gè)文件
修改: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
打開(kāi)CPU_ONLY := 1(入門建議先只用cpu訓(xùn)練秉氧,進(jìn)階再用gpu)
修改:Makefile:(181行左右)
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
4.在caffe根目錄:
make all -j4
5.運(yùn)行手寫(xiě)識(shí)別過(guò)程:在caffe目錄下
cd data/mnist
./get_mnist.sh(若沒(méi)有權(quán)限眷昆,chmod +x ./get_mnist.sh 賦予權(quán)限) 下載數(shù)據(jù)
6.轉(zhuǎn)換格式
./examples/mnist/create_mnist.sh
7.訓(xùn)練超參數(shù)
在/examples/mnist/lenet_solver.prototxt將mode改為cpu
再運(yùn)行
./build/tools/caffe train --solver=examples/mnist/lenet_solver.prototxt $@
可以看到最后的結(jié)果達(dá)到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.