TensorFlow GPU

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)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容