TensorFlow GPU
一、TensorFlow-GPU环境配置
0.查看自己的显卡是否支持GPU计算加速
显卡查看:https://www.geforce.com/hardware/technology/cuda/supported-gpus
CUDA安装:https://www.cnblogs.com/wanyu416/p/9536853.html
cuDNN下载:https://developer.nvidia.com/cudnn
1.安装TensorFlow-GPU
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ TensorFlow-GPU
2.安装时出现ERROR: Cannot uninstall 'wrapt'问题的解决方案
pip install -U --ignore-installed wrapt enum34 simplejson netaddr
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu
3.导入时出现ImportError: Could not find 'cudart64_100.dll'问题的解决方案
https://blog.csdn.net/qq_29027865/article/details/93236034
4.查看设备信息
https://blog.csdn.net/qq_34022601/article/details/90449789
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"
if __name__ == "__main__":
print(device_lib.list_local_devices())
二、使用GPU加速计算
1.指定计算设备
with tf.device('/gpu:0'):
需要加速计算图节点
2.初始化cuDNN
init = tf.global_variables_initializer()
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)
session.run(init)