0
点赞
收藏
分享

微信扫一扫

Tensorflow 2.3 GPU安装

以下 64 位系统支持 TensorFlow:

  • Ubuntu 16.04 或更高版本
  • Windows 7 或更高版本
  • macOS 10.12.6(Sierra) 或更高版本(不支持GPU)
  • Raspbian 9.0 或更高版本

安装Python版本要求

Python 3.5 — 3.7

下载 ANACONDA 对 Python版本和第三方库进行管理
Tensorflow 2.3 GPU安装_tensorflow

Tensorflow GPU 版本安装

  • 安装GPU版本必须有GPU硬件的支持。
  • TensorFlow 对 NVIDIA 显卡的支持较为完备
  • 可以使用 conda 来安装GPU 版本

对于 NVIDIA 显卡,要求其 CUDA Compute Capability 不低于 3.5。
算力参考:​​​https://developer.nvidia.com/cuda-gpus​​​Tensorflow 2.3 GPU安装_python_02
驱动版本:NVIDIA驱动程序需 418.x 或更高版本。
可在命令行汇总执行查看驱动版本:

nvidia-smi

(python37) C:\Users\78694>nvidia-smi
Fri Jan 21 00:31:07 2022
±----------------------------------------------------------------------------+
| NVIDIA-SMI 471.41 Driver Version: 471.41 CUDA Version: 11.4 |
|-------------------------------±---------------------±---------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce … WDDM | 00000000:01:00.0 On | N/A |
| 0% 27C P8 19W / 290W | 1823MiB / 8192MiB | 21% Default |
| | | N/A |
±------------------------------±---------------------±---------------------+

或者打开NVIDIA控制面板 在菜单栏→帮助 选择 系统信息
Tensorflow 2.3 GPU安装_python_03
可以查看到NVIDIA的硬件详细信息
Tensorflow 2.3 GPU安装_深度学习_04

GPU版本有两个依赖库,对于 tensorflow2.3来说

  • CUDA的版本需要是10.1
  • cudnn版本号需要不小于 7.6

在安装GPU版本的依赖库时,建议设置conda的国内镜像源,可以加速依赖库的下载

anaconda prompt 命令行,执行:

conda install cudatoolkit=10.1
conda install cudnn=7.6.5

Tensorflow 2.3 GPU安装_依赖库_05

tensorflow安装:

pip install tensorflow-gpu==2.3.0 -i https://pypi.douban.com/simple

Tensorflow 2.3 GPU安装_tensorflow_06
在cmd中 输入 python 进入python 编译环境后,输入以下命令测试 tensorflow GPU版本是否安装成功

import tensorflow as tf
tf.__version__

tf.test.is_gpu_available()

Tensorflow 2.3 GPU安装_python_07
Tensorflow 2.3 GPU安装_依赖库_08

注:

环境:显卡3070Ti安装

使用 ANACONDA 安装Python3.7版本

conda create -n tensorflow ;python=3.7

切换到 刚创建的 python3.7环境中

conda activate tensorflow

查看 cudnn 和 cudatoolkit 可用的版本

conda search cudnn

conda search cudatoolkit

anaconda prompt 命令行,执行:

conda install ;cudatoolkit=11.4.2
conda install ;cudnn=8.2.0.53

查看 tensorflow-gpu 所有的版本

conda search tensorflow-gpu

使用 conda 安装Tensorflow 2.3

conda install tensorflow-gpu=2.3.0

Tensorflow 2.3 GPU安装_依赖库_09
在cmd中 输入 python 进入python 编译环境后,输入以下命令测试 tensorflow GPU版本是否安装成功

import tensorflow as tf
tf.__version__

tf.config.list_physical_devices('GPU')

(python37) C:\Users\78694>python
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:35:01) [MSC v.1916 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import tensorflow as tf
2022-01-21 12:51:00.487045: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
>>> tf.version
‘2.3.0’
>>>
>>> tf.config.list_physical_devices(‘GPU’)
2022-01-21 12:51:02.207078: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library nvcuda.dll
2022-01-21 12:51:02.229313: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1716] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: NVIDIA GeForce RTX 3070 Ti computeCapability: 8.6
coreClock: 1.77GHz coreCount: 48 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 566.30GiB/s
2022-01-21 12:51:02.233328: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudart64_101.dll
2022-01-21 12:51:02.494197: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll
2022-01-21 12:51:02.692815: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cufft64_10.dll
2022-01-21 12:51:02.717066: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library curand64_10.dll
2022-01-21 12:51:02.861897: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusolver64_10.dll
2022-01-21 12:51:02.999753: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cusparse64_10.dll
2022-01-21 12:51:03.150352: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll
2022-01-21 12:51:03.152222: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1858] Adding visible gpu devices: 0
[PhysicalDevice(name=’/physical_device:GPU:0’, device_type=‘GPU’)]
>>>

举报

相关推荐

0 条评论