如何从R(带有Keras库)中最大化Tensorflow 2.0的GPU使用率?

我将R与Keras和tensorflow 2.0一起在GPU上使用。

将第二台显示器连接到我的GPU后,在深度学习脚本中收到此错误:

如何从R(带有Keras库)中最大化Tensorflow 2.0的GPU使用率?

我得出的结论是,GPU的内存不足,似乎是这样的解决方案:

import tensorflow as tf
from keras.backend.tensorflow_backend import set_session
config = tf.ConfigProto()
config.gpu_options.allow_growth = True  # dynamically grow the memory used on the GPU
config.log_device_placement = True  # to log device placement (on which device the operation ran)
                                    # (nothing gets printed in Jupyter,only if you run it standalone)
sess = tf.Session(config=config)
set_session(sess)  # set this TensorFlow session as the default session for Keras

根据此帖子: https://github.com/tensorflow/tensorflow/issues/7072#issuecomment-422488354

尽管R不接受此代码。 它说

  

来自Tensorflow的意外令牌。

     

tf.ConfigProto()错误:找不到函数“ tf.ConfigProto”

如果我从这篇文章中了解正确的话,似乎tensorflow 2.0不接受此代码: https://github.com/tensorflow/tensorflow/issues/33504

有人知道我如何使用Keras库和Tensorflow 2.0从我的R脚本中最大限度地利用GPU吗?

谢谢!

l5600666 回答:如何从R(带有Keras库)中最大化Tensorflow 2.0的GPU使用率?

要在keras 2.0中使用R中的tensorflowtensorflow来启用GPU内存增长,您需要在tf对象中找到正确的函数。

首先,找到您的GPU设备:

library(tensorflow)
gpu <- tf$config$experimental$get_visible_devices('GPU')[[1]]

然后启用该设备的内存增长:

tf$config$experimental$set_memory_growth(device = gpu,enable = TRUE)

通过键入tf$config$experimental$,然后在Rstudio中使用标签自动完成功能,可以找到更多相关功能。

由于这些功能被标记为实验性功能,因此将来可能会更改或移动位置。

本文链接:https://www.f2er.com/3055298.html

大家都在问