首页 > 代码库 > caffe安装笔记
caffe安装笔记
caffe安装笔记:
环境及安装前检查
硬件:
T630 CPU32核 64G内存4G硬盘
显卡:
root@shendu:~# lspci |grep -i nvidia
02:00.0 3D controller: NVIDIA Corporation GK110GL [Tesla K20Xm] (rev a1)
软件:
Ubuntu14.04 server64bit版本:ubuntu-14.04.5-server-amd64.iso
Python 2.7.12
root@shendu:~# uname -a
Linux shendu.pp100.net 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
说明:购买服务器和显卡就费了不少时间,蛋疼点是两者兼容性,不太好买,买回来后有些主板可能不兼容导致lspci|grep –i nvidia没结果,就是主板识别不了显卡。折腾了好久买好了。
?
安装说明:
依赖+cudnn+ Anaconda2 +caffe
?
安装过程统一用root账号,统一安装在 /root/caffe目录下。
?
安装前检查:
*首先验证你是否有nvidia的显卡(http://developer.nvidia.com/cuda-gpus这个网站查看你是否有支持gpu的显卡):
$ lspci | grep -i nvidia?
?
*查看linux发行版本
uname -m && cat /etc/*release*看gcc版本
$ gcc --version?
说明:是cuda 32位尚未找到合适的安装包,所以这里的linux要64位的)
?
安装依赖
apt-get?install?build-essential??#?basic?requirement??
apt-get?install?libprotobuf-dev?libleveldb-dev?libsnappy-dev?libopencv-dev?libboost-all-dev?libhdf5-serial-dev?libgflags-dev?libgoogle-glog-dev?liblmdb-dev?protobuf-compiler?#required?by?caffe
apt-get install libatlas-base-dev -y
apt-get install libprotobuf-dev -y
apt-get install libleveldb-dev -y
apt-get install libsnappy-dev -y
apt-get install libopencv-dev -y
apt-get install libboost-all-dev -y
apt-get install libhdf5-serial-dev -y
apt-get install libgflags-dev -y
apt-get install libgoogle-glog-dev -y
apt-get install liblmdb-dev -y
apt-get install protobuf-compiler –y
apt-get?install?libatlas-base-dev? #安装Intel MKL 或Atlas,默认我们用显卡来运算,软件默认就是Atlas,保持不变
?
?
安装cuda7.5
*在cuda官网(https://developer.nvidia.com/cuda-downloads#linux )下载对应版本
下载并安装
dpkg -i cuda-repo-ubuntu1404-7-5-local_7.5-18_amd64.deb
安装cuda(安装cuda的同时就会把显卡驱动也全部安装好)
apt-get install cuda -y
?
安装cudnn
tar xf cudnn-7.5-linux-x64-v5.0-ga.tgz #自行下载
cd?cuda
cp lib64/* /usr/local/cuda/lib64/
cp?include/cudnn.h?/usr/local/cuda/include/?
更新软连接
cd /usr/local/cuda/lib64/
sudo chmod +r libcudnn.so.5.0.5
sudo ln -sf libcudnn.so.5.0.5 libcudnn.so.5
sudo ln -sf libcudnn.so.5 libcudnn.so
sudo ldconfig
echo ‘/usr/local/cuda/lib64‘ >> /etc/ld.so.conf.d/cuda.conf
echo ‘/root/anaconda2/lib‘ >> /etc/ld.so.conf
?
统一设置环境变量
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/root/anaconda2/lib:$LD_LIBRARY_PATH"
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH
export PYTHONPATH=/root/caffe/caffe-master/python
安装CUDA SAMPLE
cd /usr/local/cuda/samples
make?all?–j12
cd ?/usr/local/cuda/samples/bin/x86_64/linux/release
./deviceQuery #如果出现显卡信息, 则驱动及显卡安装成功
安装opencv
https://github.com/bearpaw/Install-OpenCV #下载zip包,拖进Ubuntu解压到/root/caffe
下载opencv-2.4.9.zip 到/root/caffe下 #自行网上下载
root@shendu:~/caffe# ls
caffe-master caffe-master.zip Install-OpenCV Install-OpenCV-master.zip opencv-2.4.9 opencv-2.4.9.zip
root@shendu:~/caffe# pwd
/root/caffe
#安装依赖
/root/caffe/Install-OpenCV/Ubuntu/dependencies.sh
#安装脚本修改
root@shendu:~/caffe/Install-OpenCV/Ubuntu/2.4# cat opencv2_4_9.sh
arch=$(uname -m)
if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; then
flag=1
else
flag=0
fi
echo "Installing OpenCV 2.4.9"
mkdir OpenCV
cd OpenCV
echo "Removing any pre-installed ffmpeg and x264"
sudo apt-get -y remove ffmpeg x264 libx264-dev
echo "Installing Dependenices"
sudo apt-get -y install libopencv-dev
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get -y install python-dev python-numpy
sudo apt-get -y install libtbb-dev
sudo apt-get -y install libqt4-dev libgtk2.0-dev
sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
sudo apt-get -y install x264 v4l-utils ffmpeg
# sudo apt-get -y install libgtk2.0-dev # duplicate
echo "Downloading OpenCV 2.4.9"
#wget -O OpenCV-2.4.9.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip/download #注释掉
echo "Installing OpenCV 2.4.9"
unzip OpenCV-2.4.9.zip
cd opencv-2.4.9
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_CUBLAS=OFF -D WITH_CUDA=OFF -D WITH_CUFFT=OFF .. #添加这三项
make -j12
sudo make install
sudo sh -c ‘echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf‘
sudo ldconfig
cd ../../..
rm -rf OpenCV
echo "OpenCV 2.4.9 ready to be used"
?
mkdir –p /root/caffe/Install-OpenCV/Ubuntu/2.4/
cp /root/caffe/opencv-2.4.9.zip /root/caffe/Install-OpenCV/Ubuntu/2.4/OpenCV/OpenCV-2.4.9.zip
/root/caffe/Install-OpenCV/Ubuntu/2.4/opencv2_4_9.sh
?
安装Caffe所需要的Python环境
https://www.continuum.io/downloads#all
bash /root/Anaconda2-4.2.0-Linux-x86_64.sh #一路yes即可。
cd /root/caffe/caffe-master/python
for?req?in?$(cat?requirements.txt);?do?pip?install?$req;?done? #安装前先看看你的echo $PATH正常不。有问题重启下机器。
安装caffe(操作前重启下机器,确保$PATH正常)
cd /root/caffe/caffe-master
cp?Makefile.config.example?Makefile.config
make?all?-j4??
make?test??
make?runtest??
?
测试验证
1.
sudo sh ./examples/mnist/create_mnist.sh??
生成mnist-train-leveldb/ 和 mnist-test-leveldb/文件夹,这里包含了LDB格式的数据集
? ? 注:新版caffe都需要从根目录上执行,如果使用下列命令执行:
? ? # cd examples/mnist??
? ? # sudo sh ./create_mnist.sh??
? ? 可能会遇到这个错误:./create_mnist.sh: 16: ./create_mnist.sh: build/examples/mnist/convert_mnist_data.bin: not found,全路径试试。
2,验证python
import caffe #此处不要用ipython,可以用bpython。
3,查看显卡驱动版本
查看显卡的驱动版本
? ? cat /proc/driver/nvidia/version?
caffe安装笔记