在keras上使用gpu的方法

在keras上使用gpu的方法,第1张

80

Yes you can run keras models on GPU. Few things you will have to check first.

your system has GPU (Nvidia. As AMD doesn't work yet)

You have installed the GPU version of tensorflow 

You have installed CUDA  installation instructions

Verify that tensorflow is running with GPU  check if GPU is working

sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

OR

from tensorflow.python.client import device_libprint(device_lib.list_local_devices())

output will be something like this:

[  name: "/cpu:0"device_type: "CPU",  name: "/gpu:0"device_type: "GPU"]

Once all this is done your model will run on GPU:

To Check if keras(>=2.1.1) is using GPU:

from keras import backend as K

K.tensorflow_backend._get_available_gpus()

All the best.

gpu擅长处理计算密集型任务,可并行运作。在深度学习的训练过程中,包含了大量重复性的计算,利用 gpu 的特性可显著提高训练的效率。

先升级显卡驱动确保后面不会因为显卡驱动版本低这个问题被卡住。

NVIDIA CUDA是一种由NVIDIA推出的通用并行计算架构,该架构使GPU能够解决复杂的计算问题。

NVIDIA cuDNN是用于深度神经网络的gpu加速库,可以集成到更高级别的机器学习框架中,如Tensorflow、caffe。

tensorflow-gpu是tensorflow的gpu版本,但是它必须通过 cuda 和 cudnn 来调用电脑的 gpu。

使用以下方法可以一次性安装CUDA、cuDNN、tensorflow-gpu

在gpu可用的情况下默认使用的是gpu,通过为CUDA指定一个不存在的gpu可切换回cpu模式

设置当前使用的GPU设备仅为0号设备 设备名称为'/gpu:0'

设置当前使用的GPU设备为1,0号两个设备,这里的顺序表示优先使用1号设备,然后使用0号设备

tf.ConfigProto一般用在创建session的时候,用来对session进行参数配置,而tf.GPUOptions可以作为设置tf.ConfigProto时的一个参数选项,一般用于限制GPU资源的使用。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/bake/11571862.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存