【发布时间】:2019-11-21 19:30:20
【问题描述】:
我在 GPU 上使用带有 Keras 和 tensorflow 2.0 的 R。
将第二台显示器连接到我的 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 使用率?
谢谢!
【问题讨论】:
-
@Axeman 太棒了!它返回 PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')。当我使用 tf$config$experimental$set_memory_growth(device = 0, enable = TRUE) 它说 Unrecognized device: 0.0
-
@Axeman 非常感谢!!这就是解决方案!
-
@Axeman 优雅的解决方案通过gpu解决它
标签: r tensorflow2.0 tf.keras