Tensorflow官网推荐使用的操作系统是Ubuntu 16.04或者18.04,我个人比较喜欢CentOS,所以就选择在CentOS 7上安装。
1、CentOS 7.6的安装(当前最新的64位版本)
安装的时候注意要安装开发环境:gcc和linux kernel源代码的.h文件在后面安装GPU的驱动要用
2、确定与Tensorflow对应的cuda、cuDNN版本
网址:https://tensorflow.google.cn/install/source, 这个是官网,信息比较权威(百度出来的内容很多都不准确,而且比较老。毕竟RTX2070是比较新的显卡)
从官网的信息可知在LINUX平台上,有如下的对应关系:
版本 | Python 版本 | 编译器 | 编译工具 | cuDNN | CUDA |
---|---|---|---|---|---|
tensorflow_gpu-1.13.0 | 2.7、3.3-3.6 | GCC 4.8 | Bazel 0.19.2 | 7.4 | 10.0 |
3、下载并安装CUDA 10和cuDNN
cuDNN: https://developer.nvidia.com/rdp/cudnn-archive Download cuDNN v7.4.2 (Dec 14, 2018), for CUDA 10.0
说明:1)、不需要另外安装RTX2070的驱动,已经包含在CUDA里面了。
2)、安装驱动的时候需要把X window关闭:一般就ps -eaf|grep X,找出来直接kill
4、Tensorflow_gpu安装
根据对应关系,只能用python 3.6。 我习惯用anaconda,在这里犯了不少错误,试了好几个版本,最后确定3.6的最新版本是Anaconda3-5.2.0-Linux-x86_64.sh tensorfow最新的1.13 gpu版本下载:https://files.pythonhosted.org/packages/7b/b1/0ad4ae02e17ddd62109cd54c291e311c4b5fd09b4d0678d3d6ce4159b0f0/tensorflow_gpu-1.13.1-cp36-cp36m-manylinux1_x86_64.whl
5、安装完成后,运行hello
[root@centos7 Downloads]# python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
/usr/local/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
from ._conv import register_converters as _register_converters
>>>
>>>
>>> hello = tensorflow.constant("Hello")
>>> session = tensorflow.Session()
2019-04-17 22:14:30.674969: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-04-17 22:14:31.813537: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:998] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-04-17 22:14:31.814127: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x55a818cf86c0 executing computations on platform CUDA. Devices:
2019-04-17 22:14:31.814155: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): GeForce RTX 2070, Compute Capability 7.5
2019-04-17 22:14:31.816052: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3192000000 Hz
2019-04-17 22:14:31.816643: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x55a818d64010 executing computations on platform Host. Devices:
2019-04-17 22:14:31.816661: I tensorflow/compiler/xla/service/service.cc:158] StreamExecutor device (0): <undefined>, <undefined>
2019-04-17 22:14:31.816846: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties:
name: GeForce RTX 2070 major: 7 minor: 5 memoryClockRate(GHz): 1.62
pciBusID: 0000:01:00.0
totalMemory: 7.76GiB freeMemory: 7.65GiB
2019-04-17 22:14:31.816877: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2019-04-17 22:14:31.817521: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-04-17 22:14:31.817535: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0
2019-04-17 22:14:31.817543: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N
2019-04-17 22:14:31.817675: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7438 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2070, pci bus id: 0000:01:00.0, compute capability: 7.5)
>>> print(hello)
Tensor("Const:0", shape=(), dtype=string)
>>> session.run(hello)
b'Hello'