Deep Learning Frameworks Configuration
主要是Ubuntu 16.04 + cuda7.5 + cudnn5.0 + python2 + Matlab2014b + theano0.8.2 + caffe的配置,但是Ubuntu 16.04 + cuda8.0 + cudnn5.0 + python2 + tensorflow + theano + opencv 3.2 + caffe也类似
主要参考
http://www.linuxidc.com/Linux/2016-07/132860.htm
http://blog.csdn.net/g0m3e/article/details/51420565
http://blog.csdn.net/yahag/article/details/51968004
http://blog.csdn.net/lien0906/article/details/46816243
http://blog.csdn.net/ubunfans/article/details/47724341
[TOC] 依然不支持。。。
1. 安装依赖包
sudo apt-get install build-essential # basic requirement
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 libgflags-dev libgoogle-glog-dev liblmdb-dev
2. 安装nvidia显卡驱动
添加官方源 sudo add-apt-repository ppa:graphics-drivers/ppa
在系统设置,Software&Updates中选Additional Drivers,选显卡驱动,重启
查看是否安装成功 nvidia-settings
3. 安装 cuda7.5 for ubuntu 15.04 runfile(local) (cuda 8.0类似)
# cd 到目录文件
chmod 777 cuda_7.5.18_linux.run
sudo ./cuda_7.5.18_linux.run --override
# 注意不要再次安装nvidia驱动
================Problem:==============
Missing recommended library: libGLU.so
Missing recommended library: libXmu.so
$ sudo apt-get install libglu1-mesa libxi-dev libxmu-dev libglu1-mesa-dev
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/libGLU.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libXmu.so /usr/lib/libXmu.so
$ sudo ldconfig
======================================
4.更新cudnn5.0动态库,下载解压
# cd到cudnn5.0解压后的include目录
sudo cp cudnn.h /usr/local/cuda/include/
# cd到lib64目录
sudo cp lib* /usr/local/cuda/lib64/
# 建立链接
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5
sudo ln -s libcudnn.so.5.0.5 libcudnn.so.5
sudo ln -s libcudnn.so.5 libcudnn.so
# 设置环境变量和动态链接库
sudo gedit /etc/profile
# 末尾添加
# PATH=/usr/local/cuda/bin:$PATH
# export PATH
# 保存之后,创建链接文件
sudo vim /etc/ld.so.conf.d/cuda.conf
# 输入
# /usr/local/cuda/lib64
# 使链接生效
sudo ldconfig
5. cuda用例安装与测试
cd /usr/local/cuda-7.5/include
sudo cp host_config.h host_config.h.bak
sudo gedit host_config.h
# 找到下面这段
# if GNUC > 4 || (GNUC == 4 && GNUC_MINOR > 9) #改4为5
# error – unsupported GNU version! gcc versions later than 4.9 are not supported!
# endif /* GNUC > 4 || (GNUC == 4 && GNUC_MINOR > 9) */
# 编译,测试
cd /usr/local/cuda/samples
sudo make all -j4
cd /usr/local/cuda/samples/bin/x86_64/linux/release
sudo ./deviceQuery
6. BLAS用Atlas
sudo apt-get install libatlas-base-dev
7. python配置
这一步更多的是为后面装Theano做准备,用pip 安装numpy,scipy,解决依赖关系,这几步可能出错,至关重要。。。
sudo apt-get install python-pip
sudo pip install numpy
sudo pip install scipy
sudo pip install matplotlib ipython jupyter pandas sympy nose spyder
# (sudo apt-get install python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose)
pip install -U scikit-learn
# (测试sklearn nosetests -v sklearn)
# cd到caffe目录python文件夹
sudo su
for req in $(cat requirements.txt); do pip install -i https://pypi.tuna.tsinghua.edu.cn/simple $req; done
# 如果第一次有很多红字错误,再运行几遍指导安装成功,对于黄字提示无需理会,可能是pip版本需要更新
# 测试numpy, scipy
python -c "import numpy;numpy.test()"
python -c "import scipy;scipy.test()"
8. 安装Matlab2014b
# 加入系统环境变量
sudo gedit /etc/profile
# PATH="$PATH:/opt/MATLAB/R2014b/bin"
source /etc/profile
matlab shortcuts设置
具体 HOME > ENVIRONMENT > Preferences > Keyboard > Shortcuts
然后把“Emacs Default Set”改成“Windows Default Set” 保存,OK!
9. OpenCV (!慎重,可能不成功)
安装OpenCV3.1.0
sudo apt-get install libqt4-dev libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev libdc1394-22
sudo apt-get install libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev
sudo apt-get install libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get install libtbb-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev
sudo apt-get install libvorbis-dev libxvidcore-dev x264 v4l-utils unzip
mkdir build
cd build/
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j4
sudo make install
# 在/usr/local目录下查找opencv库所在位置,我在解答看到有人是在/usr/local/opencv和/usr/local/opencv2下面,
# 但我这里是在/usr/local/lib下找到的。如果找不到,可尝试:
sudo updatedb && locate libopencv_core.so.3.1 # 3.1为版本号
# 新建文件:
sudo vim /etc/ld.so.conf.d/opencv.conf
# 写入地址/usr/local/lib,并保存
sudo ldconfig -v
# ===================================== 不用
# 修改build文件夹下的flags.make(全部)
#
# CXX_FLAGS = -fsigned-char
# 为(添加-O3 -fPIC)
# CXX_FLAGS = -O3 -fPIC -fsigned-char
# =====================================
10. 安装tensorflow
两种方式安装:不通过源码编译的话,目前需要cuda8.0+cudnn5.0,按照官网指示安装,比较简单;源码安装容易出问题。
https://www.tensorflow.org/versions/r0.12/get_started/os_setup.html#pip-installation
# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
# Requires CUDA toolkit 8.0 and CuDNN v5. For other versions, see "Installing from sources" below.
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.0rc1-cp27-none-linux_x86_64.whl
11. 配置caffe
# cd到caffe目录
sudo cp Makefile.config.example Makefile.config
sudo gedit Makefile.config
# 将USE_CUDNN := 1 取消注释,在
# INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include后面打上一个空格
# 添加/usr/include/hdf5/serial
# 这是因为ubuntu16.04的文件包含位置发生了变化,尤其是需要用到的hdf5的位置,所以需要更改这一路径,
# 如果没有这一句可能会报一个找不到hdf5.h的错误
# PYTHON_INCLUDE := /usr/include/python2.7 \
# /usr/lib/python2.7/dist-packages/numpy/core/include先不做更改。
# 如果是需要生成matlab的caffe wrapper,取消注释MATLAB_DIR然后替换为自己的目录
# MATLAB_DIR := /opt/MATLAB/R2014b
# make之前先解决下面问题
# ================Problem:==============
# /usr/bin/ld: cannot find -lhdf5_hl
# /usr/bin/ld: cannot find -lhdf5
# collect2: error: ld returned 1 exit status
# Makefile:566: recipe for target '.build_release/lib/libcaffe.so.1.0.0-rc3' failed
# make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1
#
# 在打开的Makefile.config修改如下内容:
# INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
# LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
# 修改为:
# INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
# libraryY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
# 为hdf5之类的文件创建新的链接
#
# cd /usr/lib/x86_64-linux-gnu
# sudo ln -s libhdf5_serial.so.10.1.0 libhdf5.so
# sudo ln -s libhdf5_serial_hl.so.10.0.2 libhdf5_hl.so
# sudo ldconfig
# # 这里的10.1.0和10.0.2根据不同的系统可能对应的数字会不同,比如在ubuntu15.10中其数字就是8.0.2.
#
# ======================================
#
# ================Problem:==============
# string.h ‘memcy’ was not declared in this scope
#
# 由于gcc编译器版本太新,解决方法是打开makefile搜索并替换
# NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
# 为
# NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
# 保存退出
# ======================================
# cd到caffe目录
make all -j4
make test -j4
make runtest
make matcaffe # 可能g++版本太高,会有warning,但还是会编译通过,不知道成功没,没用过
make pycaffe
make distribute
# 写入系统环境变量
sudo gedit /etc/profile
# PYTHONPATH="/.../caffe-master/python:$PYTHONPATH"
# export PYTHONPATH
source /etc/profile
# 或者写入用户环境变量
sudo gedit ~/.bashrc
# export PYTHONPATH="/..../caffe-master/python:$PYTHONPATH"
source ~/.bashrc
# 之后编译链接库,打开python,输入:
python
import caffe
至此caffe配置编译完成#
12. 安装Theano
sudo pip install theano
python -c "import theano; theano.test()"
# 这里theano.test()报错很正常,不用管
sudo gedit ~/.theanorc
# [global]
# device=gpu
# floatX=float32
#
# [blas]
# ldflags=
#
# [cuda]
# root=/usr/local/cuda
#
# [nvcc]
# flags=-D_FORCE_INLINES
python
import theano
# Using gpu device 0: GeForce GT xxx (CNMeM is disabled, cuDNN 5005)
网友评论