Ubuntu14.04+CUDA7.5+CUDNN.V5+Anaconda+tensorflow

来源:互联网 发布:淘宝的欧莱雅是真的吗 编辑:程序博客网 时间:2024/05/22 13:23

1安装teamviwer(非必要,目的为远程控制,可跳过)

官网下载deb包https://www.teamviewer.com/en/download/linux/

$ sudo dpkg -i teamviewer_12.0.69753_i386.deb

安装可能会出现依赖错误,执行下条命令后再执行安装

$ sudo apt-get install -f

2安装CUDA7.5

2.1卸载原有NVIDIA驱动

$ sudo apt-get –purge remove nvidia-*

2.2禁用通用显卡驱动

终端中运行:$ lsmod | grep nouveau,如果有输出则代表nouveau正在加载。

在/etc/modprobe.d中创建文件blacklist-nouveau.conf,在文件中输入

blacklist nouveau  options nouveau modeset=0

运行

$ sudo update-initramfs –u

重启电脑

2.3执行安装

1)关闭图形化界面

$ sudo service lightdm stop

2)进入CUDA7.5安装文件目录执行安装,推荐runfile,下载地址https://developer.nvidia.com/cuda-75-downloads-archive

$ sudo sh cuda_7.5.18_linux.run

开始后会有一段用户协议,空格调到最后输入accept,接下来就是各种yes和确认路径,OpenGL可以不装
3)安装完成后重启图形界面服务

$ sudo service lightdm start

4)重启电脑,检查/dev目录,是否存在4个NVIDIA文件
$ ls /dev/nvidia*

2.4设置环境变量

1)打开profile文件,写入环境变量

$ sudo vim /etc/profile

Ubuntu中的vi编辑器可能有问题,建议安装vim

$ sudo apt-get install vim

2)写入环境变量

export PATH=/usr/local/cuda-7.5/bin:$PATH export
LD_LIBRARY_PATH=/usr/local/cuda7.5/lib64

3)设置生效

$ sudo source /etc/profile

2.5检查是否安装成功

1)检查驱动安装是否成功,成功则会驱动输出版本号

$ cat /proc/driver/nvidia/version

2)检查CUDA Toolkit安装是否成功,成功输出CUDA版本号

$ nvcc -V

3)编译CUDA的例程

$ cd /home/xxxx/NVIDIA_CUDA-7.5_Samples #xxxx为用户名

$ make

若失败,可能是缺少g++,执行安装

$ sudo apt-get install g++

编译可能需要比较长的时间
完成后,进入生成的bin目录/home/xxxx/NVIDIA_CUDA-7.5_Samples/bin运行例程

$ ./deviceQuery

若输出显卡信息即表示CUDA成功安装配置

3安装cuDNN

3.1下载解压

下载地址https://developer.nvidia.com/rdp/cudnn-download(需要注册下NVIDIA账号)
根据我们的版本选择cuDNN v5,文件名为cudnn-7.5-linux-x64-v5.0-ga.tgz
进入目录,解压后得到cuda目录

$ sudo tar -xvf cudnn-7.5-linux-x64-v5.0-ga.tgz

3.2复制文件

cd cuda sudo cp lib64/* /usr/local/cuda/lib64/ sudo cp include/cudnn.h
/usr/local/cuda/include/

3.3更新系统

sudo apt-get update && sudo apt-get upgrade sudo apt-get install
linux-source sudo apt-get install linux-headers-$(uname -r)

4Anaconda环境下安装tensorflow

4.1安装Anaconda

官网下载对应版本进行安装,我的如下

$ bash Anaconda2-4.2.0-Linux-x86_64.sh

安装过程一路yes和回车即可

4.2创建tensorflow环境执行安装

1)创建环境

$ conda create -n tensorflow python=2.7

2)pip方式进行安装

$ source activate tensorflow

3)根据不同版本,设置环境变量。

# Ubuntu/Linux 64-bit, CPU only, Python 2.7  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl  # Ubuntu/Linux 64-bit, GPU enabled, Python 2.7  # Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl  # Mac OS X, CPU only, Python 2.7:  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py2-none-any.whl  # Mac OS X, GPU enabled, Python 2.7:  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.10.0-py2-none-any.whl  # Ubuntu/Linux 64-bit, CPU only, Python 3.4  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp34-cp34m-linux_x86_64.whl  # Ubuntu/Linux 64-bit, GPU enabled, Python 3.4  # Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp34-cp34m-linux_x86_64.whl  # Ubuntu/Linux 64-bit, CPU only, Python 3.5  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp35-cp35m-linux_x86_64.whl  # Ubuntu/Linux 64-bit, GPU enabled, Python 3.5  # Requires CUDA toolkit 7.5 and CuDNN v5. For other versions, see "Install from sources" below.  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp35-cp35m-linux_x86_64.whl  # Mac OS X, CPU only, Python 3.4 or 3.5:  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.10.0-py3-none-any.whl  # Mac OS X, GPU enabled, Python 3.4 or 3.5:  (tensorflow)$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/gpu/tensorflow-0.10.0-py3-none-any.whl

4)根据使用的python2或者python3执行安装

# Python 2  (tensorflow)$ pip install --ignore-installed --upgrade $TF_BINARY_URL  # Python 3  (tensorflow)$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL

4)退出环境
$ source deactivate

4.3测试安装,执行下列代码

>>> import tensorflow as tfI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locallyI tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so locally>>> tf.__version__'0.10.0'>>> tf.__path__['/home/dskj/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow'](tensorflow的安装目录)
1 0
原创粉丝点击