#Ubuntu 18.04 安装tensorflow-gpu 1.9
参考
- https://tensorflow.google.cn/install/install_linux
- http://nvidia.com/cuda
- http://developer.nvidia.com/cudnn
说明
- 前提是机器上必须有Nvidia显卡,不太老就好(古董也没必要玩这个了吧,费电),在Nvidia官网可以查到显卡支持情况 https://developer.nvidia.com/cuda-gpus
- 安装过程中的命令都需要root身份,请使用su root切换或者每次加 sudo,编译运行测试代码使用普通用户就好
踩坑后的提示,怪我眼瞎坑自己,[手动抽脸表情]
- 必须按tensorflow 官网提示的版本安装 1.9 对应 CUDA 9.0,CUDA 9.0 要下载相应版本的cuDNN
- 如果喜欢折腾,建议使用没有重要数据的硬盘
- 安装包最好下载到其他电脑上,使用scp拷贝到安装机上,重装了几遍ubuntu,下一次包就2个G,作为联通40G所谓无线流量卡用户,想着还是蛋疼
下载主要安装文件
- CUDA® 工具包
#http://nvidia.com/cuda
#我选的是16.04的run文件,其他的坑不敢踩了
cuda_9.0.176_384.81_linux.run
- cuDNN 深度神经网络(DNN)开发环境,需要网站注册
#http://developer.nvidia.com/cudnn
libcudnn7-dev_7.1.4.18-1+cuda9.0_amd64.deb
libcudnn7_7.1.4.18-1+cuda9.0_amd64.deb
libcudnn7-doc_7.1.4.18-1+cuda9.0_amd64.deb
准备环境
看CUDA自带的驱动版本,这里是384.81,低于这个版本就要先卸载,>= 跳过
#建议run文件卸载,即你之前下载的Nvidia驱动run文件
chmod +x *.run
./NVIDIA-Linux-x86_64-384.59.run --uninstall
# 不建议采取这种,不知道为什么没尝试过
apt-get remove --purge nvidia*
禁用自带的nouveau驱动,如果你连Nvidia驱动都装过了,这一步也免了
vi /etc/modprobe.d/blacklist.conf
#加两行
blacklist nouveau
options nouveau modeset=0
#生效配置
update-initramfs -u
#重启,后分辨率变低了,毕竟没有显卡驱动了
reboot
#检查是否生效
lsmod | grep nouveau
#如果屏幕没有输出则禁用nouveau成功
安装必要的编译环境否者自带网卡驱动安装不上
apt install gcc g++ make make-guile
针对CUDA 9.0,必须将GCC降级为gcc5,也是安装CUDA时发现的
apt install gcc-5 g++-5
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 50
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 50
安装 CUDA® 工具包
一定要根据tensorflow版本安装对应版本的CUDA 1.9对应9.0,被自己眼瞎害的
chmod +x cuda_9.0.176_384.81_linux.run
sh ./cuda_9.0.176_384.81_linux.run
#会有说明,需要看的自己看,看了几页不想看/条款看不懂的 按q键
- 如果安装过程中提示失败,根据提示查看log排错
- 安装成功后的log
Do you accept the previously read EULA?
accept/decline/quit: accept You are attempting to install on an unsupported configuration. Do you wish to continue?
(y)es/(n)o [ default is no ]: y #这里384.81表示显卡驱动版本,如果本机安装的显卡驱动版本比它高就不需要安装
#选no主要是前面踩坑的时候安了CUDA9.2,呵呵
#正常应该是yes
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
(y)es/(n)o/(q)uit: n Install the CUDA 9.0 Toolkit?
(y)es/(n)o/(q)uit: y Enter Toolkit Location
[ default is /usr/local/cuda-9.0 ]: Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y Install the CUDA 9.0 Samples?
(y)es/(n)o/(q)uit: y Enter CUDA Samples Location
[ default is /root ]: Installing the CUDA Toolkit in /usr/local/cuda-9.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so
Missing recommended library: libGL.so Installing the CUDA Samples in /root ...
Copying samples to /root/NVIDIA_CUDA-9.0_Samples now...
Finished copying samples. ===========
= Summary =
=========== Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-9.0
Samples: Installed in /root, but missing recommended libraries Please make sure that
- PATH includes /usr/local/cuda-9.0/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-9.0/lib64, or, add /usr/local/cuda-9.0/lib64 to /etc/ld.so.conf and run ldconfig as root To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-9.0/bin Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-9.0/doc/pdf for detailed information on setting up CUDA. ***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 384.00 is required for CUDA 9.0 functionality to work.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
sudo <CudaInstaller>.run -silent -driver Logfile is /tmp/cuda_install_7657.log /root/NVIDIA_CUDA-9.0_Samples
设置环境变量
vi /etc/ld.so.conf.d/cuda.conf
#写入两行
/usr/local/cuda/lib64
/usr/local/cuda/extras/CUPTI/lib64
vi /etc/profile
#加入两行
export CUDA_HOME=/usr/local/cuda/bin
export PATH=$PATH:$CUDA_HOME
重启 reboot
测试安装情况
- 没有报错就表示安装成功
cd /root/NVIDIA_CUDA-9.0_Samples/samples/1_Utilities/deviceQuery
make
./deviceQuery
# Result = PASS 成功
cd ../bandwidthTest
make
./bandwidthTest
#Result = PASS 成功
cuDNN 安装
NVIDIA cuDNN is a GPU-accelerated library of primitives for deep neural networks.
#cuDNN v7.1.4 Runtime Library for Ubuntu16.04 (Deb)
dpkg -i libcudnn7_7.1.4.18-1+cuda9.0_amd64.deb
#cuDNN v7.1.4 Developer Library for Ubuntu16.04 (Deb)
dpkg -i libcudnn7-dev_7.1.4.18-1+cuda9.0_amd64.deb
#cuDNN v7.1.4 Code Samples and User Guide for Ubuntu16.04 (Deb)
libcudnn7-doc_7.1.4.18-1+cuda9.0_amd64.deb
# 锁定版本,免得自动更新破坏环境
apt-mark hold libcudnn7 libcudnn7-dev
测试
#Copy the cuDNN sample to a writable path.
$cp -r /usr/src/cudnn_samples_v7/ $HOME
#Go to the writable path.
$ cd $HOME/cudnn_samples_v7/mnistCUDNN
#Compile the mnistCUDNN sample.
$make clean && make
#Run the mnistCUDNN sample.
$ ./mnistCUDNN
#If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:
#Test passed!
安装 tensorflow-gpu 以python3为例
sudo apt-get install python3-pip python3-dev
pip3 install tensorflow-gpu
测试安装
#测试代码,保存到比如test.py
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
#执行 python3 test.py
#第一次有点慢
#没报错,有显卡信息,b'Hello, TensorFlow!',表示成功
结束了,老年人继续学习Tensorflow了
#Ubuntu 18.04 安装tensorflow-gpu 1.9的更多相关文章
- 深度学习应用系列(一)| 在Ubuntu 18.04安装tensorflow 1.10 GPU版本
tensorflow目前已经升级至r1.10版本.在之前的深度学习中,我是在MAC的虚拟机上跑CPU版本的tensorflow程序,当数据量变大后,tensorflow跑的非常慢,在内存不足情况下,又 ...
- 真实机下 ubuntu 18.04 安装GPU +CUDA+cuDNN 以及其版本选择(亲测非常实用)【转】
本文转载自:https://blog.csdn.net/u010801439/article/details/80483036 ubuntu 18.04 安装GPU +CUDA+cuDNN : 目前, ...
- [笔记] Ubuntu 18.04安装Docker CE及nvidia-docker2流程
Docker的好处之一,就是在Container里面可以随意瞎搞,不用担心弄崩Host的环境. 而nvidia-docker2的好处是NVidia帮你配好了Host和Container之间的CUDA相 ...
- [笔记] Ubuntu 18.04安装Docker CE及NVIDIA Container Toolkit流程
之前写的[笔记] Ubuntu 18.04安装Docker CE及nvidia-docker2流程已经out了,以这篇为准. Docker的好处之一,就是在Container里面可以随意瞎搞,不用担心 ...
- Ubuntu 18.04 安装MySQL
最近在写东西的时候,需要用到MySQL,在网上查了一下,都说Ubuntu18.04不能安装MySQL5.7.22, 总觉的不可能,所以自己就研究了一下,然后分享给大家 工具/原料 VMware W ...
- Ubuntu 18.04 安装博通(Broadcom)无线网卡驱动
目录 Ubuntu 18.04 安装博通(Broadcom)无线网卡驱动 Package gcc is not configured yet. 解决办法 history history | grep ...
- 在Ubuntu 18.04 安装 MySQL 8.0
在Ubuntu 18.04 安装 MySQL 8.0 ① 登入 mysql 官网,在官网中下载 deb 包,点击该链接,即可下载. https://dev.mysql.com/downloads/re ...
- Ubuntu 18.04 安装部署Net Core、Nginx全过程
Ubuntu 18.04 安装部署Net Core.Nginx全过程 环境配置 Ubuntu 18.04 ,Nginx,.Net Core 2.1, Let's Encrypt 更新系统 sudo a ...
- Ubuntu 18.04 安装和常用软件安装
Ubuntu 18.04 安装 下载 Ubuntu 制作 U 盘启动盘 设置电脑为 U 盘启动 插入 U 盘,重启电脑 按照提示安装 Ubuntu 更新 NVIDIA 显卡和 Broadcom 无线网 ...
- ubuntu 16.04 安装Tensorflow
ubuntu 16.04 安装Tensorflow(CPU) 安装python ubuntu 16.04自带python2.7,因此可以略过这一步 安装pip sudo apt-get install ...
随机推荐
- Java中关于Servlet中请求中文乱码及文件下载
1,Servlet请求响应中文乱码问题 package com.demo.servlet; import java.io.PrintWriter; import java.io.IOException ...
- 在VSCode使用Markdown绘制UML图
在VSCode使用Markdown绘制UML图 需要插件 Markdown All in One Markdown Preview Enhanced PlantUML markdownlint Mar ...
- 通过代码退出IOS程序
-(void) tapClick:(UITapGestureRecognizer *)tap{ [UIViewbeginAnimations:@"exitApplication"c ...
- 有关集合的foreach循环里的add/remove
转自:Hollis(微信号:hollischuang) 在阿里巴巴Java开发手册中,有这样一条规定: 但是手册中并没有给出具体原因,本文就来深入分析一下该规定背后的思考. 1 .foreach循环 ...
- mysql 8 windows 版本zip方式安装步骤
mysql 8 windows 版本zip方式安装步骤(下载地址:https://dev.mysql.com/downloads/mysql/)1,解压ZIP文件到指定目录下:如D:\mysql-8. ...
- Redis 之江湖遇险-复制运维及优化
一. 前言 上一篇Redis 之深入江湖-复制原理中说了复制的原理,那么在理解复制原理之后,还要知道在这复制功能的背后,还有哪些坑要注意一下,毕竟坑是要跳过去的,而不是跳进去的. 二. 读写分离的一些 ...
- redis-数据类型及命令
redis五大数据类型:string(字符串),hash(哈希,类似java的Map),list(列表),set(集合),zset(有序集合) 1.redis的键(key) keys 查询数据库中的k ...
- 解决Stm32出现error: #20: identifier "GPIO_InitTypeDef" is undefined异常
该错误是我在移植sd卡程序时出现的,错误如下: error:#20,查看错误,可以发现,这些变量都是系统定义过的,没有修改过.并且该变量也能成功跳转被找到.那么到底是什么原因呢?逛了一些帖子,尝试了好 ...
- FreeRTOS内存管理
简介 Freertos的内存管理分别在heap_1.c,heap_2.c,heap_3.c,heap_4.c,heap_5.c个文件中,选择合适的一种应用于嵌入式项目中即可. 本文的图片中 红色部分B ...
- ASP.NET Core 资源打包与压缩
ASP.NET Core 资源打包与压缩 在ASP.NET 中可以使用打包与压缩来提高Web应用程序页面加载的性能. 打包是将多个文件(CSS,JS等资源文件)合并或打包到单个文件.文件合并可减少We ...