1. 安装Caffe依赖包
在Ubuntu16.04系统中,Caffe的所有依赖包都可以用apt-get搞定。
sudo apt-get -y install git
sudo apt-get -y install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get -y install --no-install-recommends libboost-all-dev
sudo apt-get -y install libatlas-base-dev
sudo apt-get -y install python-dev (貌似Ubuntu16.04已经包含了python包)
sudo apt-get -y install libgflags-dev libgoogle-glog-dev liblmdb-dev
Caffe所需要的安装就这样轻轻松松搞定啦!
2. 下载Caffe源码:
cd caffe
mv Makefile.config.example Makefile.config
3. 修改Makefile.config文件
gedit Makefile.config (修改Makefile.config文件)
#CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
# -gencode arch=compute_20,code=sm_21 \
# -gencode arch=compute_30,code=sm_30 \
# -gencode arch=compute_35,code=sm_35 \
CUDA_ARCH := -gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
# -gencode arch=compute_61,code=compute_61
2)将以下两行:
INCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/include
LIBRARIES +=glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
修改为:
INCLUDE_DIRS:=$(PYTHON_INCLUDE) /usr/local/include/usr/include/hdf5/serial/
LIBRARIES +=glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
修改Makefile.config之后,保存,就可以进行编译了!
make -j
测试caffe训练mnist数据集
cd data/mnist/
./get_mnist.sh (下载mnist数据集)
cd
cd caffe
./examples/mnist/create_mnist.sh (转换格式)
./examples/mnist/train_lenet.sh (训练)
用训练好的模型对数据进行预测:
./build/tools/caffe.bin test -model examples/mnist/lenet_train_test.prototxt -weights examples/mnist/lenet_iter_10000.caffemodel -iterations 100