深度学习是一个比较复杂的体系,今天记录一下开发环境的搭建步骤。

全新安装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开发环境的更多相关文章

  1. 在 Ubuntu 上安装 TensorFlow (官方文档的翻译)

    本指南介绍了如何在 Ubuntu 上安装 TensorFlow.这些指令也可能对其他 Linux 变体起作用, 但是我们只在Ubuntu 14.04 或更高版本上测试了(我们只支持)  这些指令. 一 ...

  2. 通过Anaconda在Ubuntu16.04上安装 TensorFlow(GPU版本)

    一. 安装环境 Ubuntu16.04.3 LST GPU: GeForce GTX1070 Python: 3.5 CUDA Toolkit 8.0 GA1 (Sept 2016) cuDNN v6 ...

  3. 从零开始在ubuntu上配置深度学习开发环境

    从零开始在ubuntu上配置深度学习开发环境 昨天一不小心把原来配置好的台式机的开发环境破坏了,调了半天没有调回来,索性就重装一次ubuntu系统.这篇文章主要记录一个简单的.‘傻瓜式’教程. 一.U ...

  4. 【转】使用virtualenv在ubuntu上搭建python 3开发环境

    ubuntu 13.04默认的python版本是2.7的,想在其上做python3的开发会遇到问题.比如要使用pip安装软件包时,默认安装的就是python2的包.如果想安装python3的包,就需要 ...

  5. 在Ubuntu上建立Arm Linux 开发环境

    我使用的是友善2410的板子,以前都是用Fedora,现在家里的电脑被我转为Linux专用的了,装的是Ubuntu.但是嵌入式还是要玩的,在装载过程中也遇到一些小麻烦.在此记录一下,一来自己比较健忘, ...

  6. 使用virtualenv在ubuntu上搭建python 3开发环境

    ubuntu 13.04默认的python版本是2.7的,想在其上做python3的开发会遇到问题.比如要使用pip安装软件包时,默认安装的就是python2的包.如果想安装python3的包,就需要 ...

  7. 入门系列之在Ubuntu上安装Drone持续集成环境

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由小铁匠米兰的v 发表于云+社区专栏 介绍 Drone是一个流行的持续集成和交付平台.它集成了许多流行的版本控制存储库服务,如GitHu ...

  8. 在Ubuntu上搭建kindle gtk开发环境

    某个角度上说,kindle很类似android,同样的Linux内核,同样的Java用户层.不过kindle更注重简单.节能.稳定.Amazon一向认为,功能过多会分散人们阅读时候的注意力. Kind ...

  9. 在windows上安装common lisp开发环境

    (2014.1写于CSDN的文章) 最近对lisp非常感兴趣,因此在google中搜索了“common lisp install windows”, 想装一个开发环境玩玩. 第一条结果就是 “Gett ...

  10. Ubuntu下安装C/C++开发环境【!!!有更新!!!Ubuntu14.10下使用eclipse搭建C语言开发环境】

    (1)第一步安装Eclipse,有两种方法,使用软件市场搜索就可以得到,安装就可以 另外一种是使用终端安装,命令例如以下: sudo su进入root模式 输入password 然后 输入:sudo ...

随机推荐

  1. React Gatsby 最新教程

    React Gatsby 最新教程 https://www.gatsbyjs.com/docs/quick-start/ https://www.gatsbyjs.com/docs/tutorial/ ...

  2. Dell Display Manager for Mac

    Dell Display Manager for Mac DDM for macOS solution https://www.dell.com/community/Monitors/DDM-for- ...

  3. ECMAScript 2021 新特性

    ECMAScript 2021 新特性 refs https://codeburst.io/exciting-features-of-javascript-es2021-es12-1de8adf655 ...

  4. GitHub rename the default branch from master to main

    GitHub rename the default branch from master to main master => main Repository default branch Cho ...

  5. free open movie API all in one

    free open movie API all in one movie API TMDb API The Movie Database https://www.themoviedb.org/docu ...

  6. vs code & macOS services

    vs code & macOS services Mac OS X, Open Folder With VS Code (right click) https://github.com/Mic ...

  7. js & while & do while

    js & while & do while https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Stat ...

  8. git 强制提交 & 覆盖 origin/master

    git 强制提交 & 覆盖 origin/master git 强制提交本地分支覆盖远程分支 # git push origin 分支名 --force # local $ git push ...

  9. C++面试题集合(持续更新)

    C++面试中常被问到的几个知识点: 1. 基本概念 多态是什么,C++通过什么实现的多态.虚函数是什么,纯虚类是什么.重载是什么,重写是什么.重载运算符怎么写.new和malloc有什么区别.公有继承 ...

  10. Github上优秀的.NET Core开源项目的集合

    内容包括:库.工具.框架.模板引擎.身份认证.数据库.ORM框架.图片处理.文本处理.机器学习.日志.代码分析.教程等. Github地址:https://github.com/jasonhua95/ ...