如何最大化 R(使用 Keras 库)中 Tensorflow 2.0 的 GPU 使用率?
how can I maximize the GPU usage of Tensorflow 2.0 from R (with Keras library)?
我在 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
根据这个post:
https://github.com/tensorflow/tensorflow/issues/7072#issuecomment-422488354
虽然这个代码不被R接受。
它说
unexpecterd token from Tensorflow.
Error in tf.ConfigProto() : could not find function "tf.ConfigProto"
如果我从这个post理解正确的话,tensorflow 2.0似乎不接受这个代码:
https://github.com/tensorflow/tensorflow/issues/33504
有谁知道如何使用 Keras 库和 Tensorflow 2.0 从我的 R 脚本中最大化 GPU 使用率?
谢谢!
要在 tensorflow
2.0 中使用 keras
或 tensorflow
启用 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 中使用选项卡自动完成功能找到更多相关功能。
由于这些功能被标记为实验性功能,它们将来可能会更改或移动位置。
我在 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
根据这个post: https://github.com/tensorflow/tensorflow/issues/7072#issuecomment-422488354
虽然这个代码不被R接受。 它说
unexpecterd token from Tensorflow.
Error in tf.ConfigProto() : could not find function "tf.ConfigProto"
如果我从这个post理解正确的话,tensorflow 2.0似乎不接受这个代码: https://github.com/tensorflow/tensorflow/issues/33504
有谁知道如何使用 Keras 库和 Tensorflow 2.0 从我的 R 脚本中最大化 GPU 使用率?
谢谢!
要在 tensorflow
2.0 中使用 keras
或 tensorflow
启用 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 中使用选项卡自动完成功能找到更多相关功能。
由于这些功能被标记为实验性功能,它们将来可能会更改或移动位置。