常说天作孽犹可违,人作孽不可活啊,那为了毕设,我就是作死啊。没办法自己从三月份辞掉实习开始断断续续学习深度学习,才明白入坑虽浅,基情不断啊。为了能够完成毕设,便选了Caffe,也到处都是坑啊。没办法,为了祭奠我那糟糕透顶的记忆脑细胞,用我这糟糕的文笔稍微记录一下吧。
首先想吐槽一下,我的电脑没有Nvidia,没有Nvidia,没有Nvidia,重要的事情说三篇。在这上面就耽误了好几天。
安装依赖包
1.安装protobuf,leveldb,snappy,opencv,hdf5, protobuf compiler andboost:
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
2.安装gflags,glogs ,lmdb andatlas.
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
sudo apt-get install libatlas-base-dev
下载Caffe
使用git直接下载Caffe非常简单,或者去https://github.com/BVLC/caffe下载
git clone git://github.com/BVLC/caffe.git
编译Caffe
1.切换到Caffe所在目录
cp Makefile.config.example Makefile.config
2.配置Makefile.config
1)CPU_ONLY := 1
2)配置一些引用文件(增加部分主要是解决新版本下,HDF5的路径问题)
1)INCLUDE_DIRS := $(PYTHON_INCLUDE)
/usr/local/include
/usr/lib/x86_64-linux-gnu/hdf5/serial/include
2)LIBRARY_DIRS := $(PYTHON_LIB)
/usr/local/lib
/usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
3)BLAS := atlas
计算能力 mkl > openlas >atlas
3.Make Caffe
make all -j8
make test -j8
make runtest -j8
4.编译成功,否则执行 make clean 多执行以下,否则多google吧
编译Python接口
1.Caffe拥有python\C++\shell接口,在Caffe使用python特别方便,在实例中都有接口的说明。
1)确保pip已经安装
sudo apt-get install python-pip
2)新建shell文件并执行安装依赖
for req in $(cat requirements.txt); do pip install $req; done
3)编译python接口
make pycaffe
当出现下面错误的时候修改
Makefile.config
atal error: numpy/arrayobject.h: No such file or directory.
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include This is where our error is. So by changing this line to:
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include
# Our problem is gone.
2.运行python结构
sudo gedit /etc/profile
末尾添加: export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
用完整路径
source /etc/profile
export PYTHONPATH=$PYTHONPATH:/home/learning/caffe/python (caffe路径下的python)
)
在Mnist运行Lenet
1.获取数据源