然而并没有什么东西┑( ̄Д  ̄)┍

0%

[TF]TensorFlow 2.1 安装指北

TensorFlow 2.1 于2020年1月9日发布,真正意义上的TF2完全体。

CPU版安装

1. 装软件依赖

软件依赖

  1. Python 3.5–3.7
  2. Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019

2. 通过pypi安装TensorFlow

1
pip install tensorflow

GPU版安装

1. 装软件依赖

软件依赖

  1. Python 3.5–3.7
  2. Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019
  3. NVIDIA GPU驱动>=418.x
  4. CUDA Toolkit=10.1.x #不能是10.2也不能是10.0
  5. cuDNN>=7.6

常规安装的话找对应的包下下来装就行。

推荐使用AnacondaChocolatey来快速安装:

1
2
3
4
5
6
7
8
9
# 这个是Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019
choco install vcredist140
# 只要不是在生产环境部署 都推荐用创建个虚拟环境再安装
conda create -n tf2 python=3.6
# 激活虚拟环境
activate tf2
# 然后是CUDA和cudnn,cudnn不用指定版本,conda会自动与CUDA匹配
conda install cudatoolkit=10.1 cudnn
# 你说,这几行代码能够搞定的事难道不香吗

tips:

  1. 配置anaconda的清华镜像源
  2. choco 支持系统的全局代理

2. 通过pypi安装TensorFlow

1
pip install tensorflow #嗯。。。TF2.1 CPU与GPU安装包合并了

推荐使用官方的pypi源,我用清华源的pypi镜像出现了找不到tensorboard的问题。

验证安装

试试以下代码

1
2
3
4
import tensorflow as tf
print(tf.__version__)
print(tf.config.list_physical_devices('CPU'))
print(tf.config.list_physical_devices('GPU'))

如果得到的结果是这样的,那么恭喜,可以开始hacking了~

1
2
3
4
5
6
7
8
9
10
(tf2) λ python
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 15:18:16) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> print(tf.__version__)
2.1.0
>>> print(tf.config.list_physical_devices('CPU'))
[PhysicalDevice(name='/physical_device:CPU:0', device_type='CPU')]
>>> print(tf.config.list_physical_devices('GPU')) # 如果这个输出不长这样说明GPU支持部分有问题
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

如果有问题,请参考官方的issue list