在Ubuntu上安装TensorFlow-GPU开发环境
深度学习是一个比较复杂的体系,今天记录一下开发环境的搭建步骤。
全新安装Ubuntu 20.10,系统默认安装的是python3,查看python的版本;
mango@ubuntu:~$ python3 --version
Python 3.8.6
接下来我们安装pip3
mango@ubuntu:~$ sudo apt-get update
mango@ubuntu:~$ sudo apt-get upgrade
mango@ubuntu:~$ sudo apt install python3-pip
检测安装的pip版本信息
mango@ubuntu:~$ pip --version
pip 20.1.1 from /usr/lib/python3/dist-packages/pip (python 3.8)
安装OpenBLAS
mango@ubuntu:~$ sudo apt install build-essential cmake git unzip \pkg-config libopenblas-dev liblapack-dev
安装Numpy、SciPy和Matplotlib,方便进行机器学习或科学计算
mango@ubuntu:~$ sudo apt install python3-numpy python3-scipy python3-matplotlib python3-yaml
安装HDF5,用来高效的二进制格式来保存数值数据的大文件。它可以让你将Keras模型快速高效地保存到磁盘。
mango@ubuntu:~$ sudo apt install libhdf5-serial-dev python3-h5py
安装Graphviz和pydot-ng,这两个包可以将Keras模型可视化
mango@ubuntu:~$ sudo apt install graphviz
mango@ubuntu:~$ sudo pip3 install pydot-ng
打开software&updates,安装显卡驱动

安装重启之后查看显卡型号及支持的CUDA的版本

去https://developer.nvidia.com/zh-cn/cuda-downloads下载对应版本的CUDA工具包

按照如下的步骤进行安装
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pinsudo
mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda-repo-ubuntu2004-11-1-local_11.1.0-455.23.05-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2004-11-1-local_11.1.0-455.23.05-1_amd64.deb
sudo apt-key add /var/cuda-repo-ubuntu2004-11-1-local/7fa2af80.pub
sudo apt-get update
sudo apt-get -y install cuda
去https://developer.nvidia.com/zh-cn/cudnn下载对应版本的cuDNN,分别下载x86_64对应的运行时库和开发人员库的deb包

分别安装运行时库和开发人员库
sudo dpkg -i libcudnn8_8.1.1.33-1+cuda11.2_amd64.deb
sudo dpkg -i libcudnn8-dev_8.1.1.33-1+cuda11.2_amd64.deb
由于Keras已经内置于tensorflow2中,我们直接安装tensorflow即可
mango@ubuntu:~$ sudo pip3 install tensorflow-gpu -i https://mirrors.aliyun.com/pypi/simple
测试tensorflow2
import tensorflow as tf
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10, activation='softmax')
])
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5)
model.evaluate(x_test, y_test, verbose=2)
执行结果
2021-03-28 16:09:23.765265: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-03-28 16:09:36.281358: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-03-28 16:09:36.302026: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1
2021-03-28 16:09:36.548766: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-03-28 16:09:36.565114: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1720] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: GeForce GTX 965M computeCapability: 5.2
coreClock: 1.15GHz coreCount: 8 deviceMemorySize: 1.96GiB deviceMemoryBandwidth: 74.65GiB/s
2021-03-28 16:09:36.565233: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0
2021-03-28 16:09:36.821405: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11
2021-03-28 16:09:36.821485: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11
2021-03-28 16:09:36.903521: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10
2021-03-28 16:09:36.963249: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10
2021-03-28 16:09:36.963863: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcusolver.so.10'; dlerror: libcusolver.so.10: cannot open shared object file: No such file or directory
2021-03-28 16:09:37.022882: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11
2021-03-28 16:09:37.038066: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8
2021-03-28 16:09:37.038165: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1757] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2021-03-28 16:09:37.038929: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-03-28 16:09:37.040468: I tensorflow/compiler/jit/xla_gpu_device.cc:99] Not creating XLA devices, tf_xla_enable_xla_devices not set
2021-03-28 16:09:37.040562: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1261] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-03-28 16:09:37.040594: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1267]
2021-03-28 16:09:37.934591: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2)
2021-03-28 16:09:38.020144: I tensorflow/core/platform/profile_utils/cpu_utils.cc:112] CPU Frequency: 2599990000 Hz
Epoch 1/5
1875/1875 [] - 3s 924us/step - loss: 0.4852 - accuracy: 0.8609
Epoch 2/5
1875/1875 [] - 2s 890us/step - loss: 0.1477 - accuracy: 0.9570
Epoch 3/5
1875/1875 [] - 2s 865us/step - loss: 0.1033 - accuracy: 0.9681
Epoch 4/5
1875/1875 [] - 2s 862us/step - loss: 0.0865 - accuracy: 0.9726
Epoch 5/5
1875/1875 [==============================] - 2s 845us/step - loss: 0.0754 - accuracy: 0.9763
313/313 - 0s - loss: 0.0753 - accuracy: 0.9764
在Ubuntu上安装TensorFlow-GPU开发环境的更多相关文章
- 在 Ubuntu 上安装 TensorFlow (官方文档的翻译)
本指南介绍了如何在 Ubuntu 上安装 TensorFlow.这些指令也可能对其他 Linux 变体起作用, 但是我们只在Ubuntu 14.04 或更高版本上测试了(我们只支持) 这些指令. 一 ...
- 通过Anaconda在Ubuntu16.04上安装 TensorFlow(GPU版本)
一. 安装环境 Ubuntu16.04.3 LST GPU: GeForce GTX1070 Python: 3.5 CUDA Toolkit 8.0 GA1 (Sept 2016) cuDNN v6 ...
- 从零开始在ubuntu上配置深度学习开发环境
从零开始在ubuntu上配置深度学习开发环境 昨天一不小心把原来配置好的台式机的开发环境破坏了,调了半天没有调回来,索性就重装一次ubuntu系统.这篇文章主要记录一个简单的.‘傻瓜式’教程. 一.U ...
- 【转】使用virtualenv在ubuntu上搭建python 3开发环境
ubuntu 13.04默认的python版本是2.7的,想在其上做python3的开发会遇到问题.比如要使用pip安装软件包时,默认安装的就是python2的包.如果想安装python3的包,就需要 ...
- 在Ubuntu上建立Arm Linux 开发环境
我使用的是友善2410的板子,以前都是用Fedora,现在家里的电脑被我转为Linux专用的了,装的是Ubuntu.但是嵌入式还是要玩的,在装载过程中也遇到一些小麻烦.在此记录一下,一来自己比较健忘, ...
- 使用virtualenv在ubuntu上搭建python 3开发环境
ubuntu 13.04默认的python版本是2.7的,想在其上做python3的开发会遇到问题.比如要使用pip安装软件包时,默认安装的就是python2的包.如果想安装python3的包,就需要 ...
- 入门系列之在Ubuntu上安装Drone持续集成环境
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由小铁匠米兰的v 发表于云+社区专栏 介绍 Drone是一个流行的持续集成和交付平台.它集成了许多流行的版本控制存储库服务,如GitHu ...
- 在Ubuntu上搭建kindle gtk开发环境
某个角度上说,kindle很类似android,同样的Linux内核,同样的Java用户层.不过kindle更注重简单.节能.稳定.Amazon一向认为,功能过多会分散人们阅读时候的注意力. Kind ...
- 在windows上安装common lisp开发环境
(2014.1写于CSDN的文章) 最近对lisp非常感兴趣,因此在google中搜索了“common lisp install windows”, 想装一个开发环境玩玩. 第一条结果就是 “Gett ...
- Ubuntu下安装C/C++开发环境【!!!有更新!!!Ubuntu14.10下使用eclipse搭建C语言开发环境】
(1)第一步安装Eclipse,有两种方法,使用软件市场搜索就可以得到,安装就可以 另外一种是使用终端安装,命令例如以下: sudo su进入root模式 输入password 然后 输入:sudo ...
随机推荐
- Linux bash fi
Linux bash fi if..else..fi allows to make choice based on the success or failure of a command. if..e ...
- shit 环信 IM SDK & IM SDK & web
shit 环信 IM SDK & IM SDK & web 环信 IM SDK, 采坑大全 自己写 UI appkey 是否正确 password 是字符串,不是 数字 HTTPS 是 ...
- how to copy to clipboard using windows cmd
how to copy to clipboard using windows cmd Windows clipboard command line https://www.labnol.org/sof ...
- 远程过程调用框架——gRPC
gRPC是一款基于http协议的远程过程调用(RPC)框架.出自google.这个框架可以用来相对简单的完成如跨进程service这样的需求开发. 资料参考: https://blog.csdn.ne ...
- 按键显示器(判断键盘监听器获得的值为普通Key还中modifiers)
1 import sys 2 from PyQt5 import QtWidgets,QtCore 3 from PyQt5.QtCore import Qt 4 from PyQt5.uic.pro ...
- Spring 注解(二)注解工具类
本文转载自Spring 注解(二)注解工具类 导语 首先回顾一下 AnnotationUtils 和 AnnotatedElementUtils 这两个注解工具类的用法: @Test @GetMapp ...
- 深入剖析 ConcurrentHashMap
自建博客地址:https://bytelife.net,欢迎访问! 本文为博客自动同步文章,为了更好的阅读体验,建议您移步至我的博客 本文作者: Jeffrey 本文链接: https://bytel ...
- 【Notes】现代图形学入门_02
跟着闫令琪老师的课程学习,总结自己学习到的知识点 课程网址GAMES101 B站课程地址GAMES101 课程资料百度网盘[提取码:0000] 光栅化 着色(Shading) 在图形学中,着色的定义可 ...
- Oracle数据库的函数
一.字符函数upper和lower (1).upper和lower upper把小写的字符转换成大小的字符 ,lower把大写字符变成小写字符 . select upper('yes') from d ...
- python进阶(6)深拷贝和浅拷贝
深拷贝和浅拷贝 不管对于浅拷贝.还是深拷贝,针对不可变对象str.int.tuple(有点特殊).boolean,它的内存地址是不变的,拷贝的仅仅是值 import copy a = 1 b = co ...