我正在运行一个 Keras 模型,提交截止日期为 36 小时,如果我在 cpu 上训练我的模型大约需要 50 小时,有没有办法在 gpu 上运行 Keras?
我正在使用 Tensorflow 后端并在我的 Jupyter 笔记本上运行它,但没有安装 anaconda.
解决方案是的,您可以在 GPU 上运行 keras 模型.您必须先检查几件事.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
对于 TF >v2.0
sess = tfpat.v1.Session(config=tfpat.v1.ConfigProto(log_device_placement=True))
(感谢@nbro 和@Ferro 在评论中指出这一点)
或
from tensorflow.python.client import device_lib打印(device_lib.list_local_devices())输出将是这样的:
[名称:/cpu:0"设备类型:CPU",名称:/gpu:0"设备类型:GPU"]完成所有这些后,您的模型将在 GPU 上运行:
要检查 keras(>=2.1.1) 是否正在使用 GPU:
from keras import backend as KK.tensorflow_backend._get_available_gpus()一切顺利.
I'm running a Keras model, with a submission deadline of 36 hours, if I train my model on the cpu it will take approx 50 hours, is there a way to run Keras on gpu?
I'm using Tensorflow backend and running it on my Jupyter notebook, without anaconda installed.
解决方案Yes you can run keras models on GPU. Few things you will have to check first.
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
for TF > v2.0
sess = tfpat.v1.Session(config=tfpat.v1.ConfigProto(log_device_placement=True))
(Thanks @nbro and @Ferro for pointing this out in the comments)
OR
from tensorflow.python.client import device_lib print(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 上运行 Keras 模型吗?
发布评论