我有一个非常强大的Windows (运行Windows 10),它有112 16内存,16核和3 X Geforce RTX2070 (不支持SLI等)。它正在运行CuDNN 7.5 + Tensorflor 1.13 +Python3.7
我的问题是,每当我尝试运行Keras模型进行训练或对矩阵进行预测时,我都会得到下面的错误。一开始,我认为只有同时运行更多的程序才会发生这种情况,但情况并非如此,现在我只运行一个Keras实例时也会出现错误(通常--但并不总是这样)。
2019-06-15 19:33:17.878911: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115]创建了TensorFlow设备(/job:localhost/TensorFlow:0/TensorFlow:0/ device : GPU :2和6317 MB内存) ->物理GPU(设备: 2,名称: GeForce RTX 2070,pci总线id: 0000:44:00.0,计算能力: 7.5) 2019-06-15 19:23.423911:I tensorflow/stream_executor/dso_loader.cc:152]成功地在本地打开CUDA库cublas64_100.dll 2019-06-15 19:33:23.744678: e cublas64_100.dll未能创建cublas句柄: CUBLAS_STATUS_ALLOC_FAILED 2019-06-15 19:33:23.748069: e tensorflow/stream_executor/cuda/cuda_blas.cc创建cublas句柄失败: tensorflow/stream_executor/cuda/cuda_blas.cc:510] 2019-06-15 19:33:23.751235: e tensorflow/stream_executor/cuda/cuda_dnn.cc:334]未能创建cublas句柄: CUBLAS_STATUS_ALLOC_FAILED 2019-06-15 19:33:25.267137: e tensorflow/stream_executor/cuda/cuda_dnn.cc:334]无法创建cudnn句柄: CUDNN_STATUS_ALLOC_FAILED 2019-06-15 :33:25.270582E tensorflow/stream_executor/cuda/cuda_dnn.cc:334]无法创建cudnn句柄: CUDNN_STATUS_ALLOC_FAILED异常:未能得到卷积算法。这可能是因为cuDNN未能初始化,所以尝试查看上面是否打印了警告日志消息。[{节点卷积}][{节点密度3/Sigmoid}}]
发布于 2019-06-15 19:43:57
将以下内容添加到代码中
from keras.backend.tensorflow_backend import set_session
import tensorflow as tf
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)
sess = tf.Session(config=config)
set_session(sess) # set this TensorFlow session as the default session for Keras发布于 2020-02-26 16:22:45
在Tensorflow 2.0和更高版本上,您可以这样解决这个问题:
os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'或
physical_devices = tf.config.experimental.list_physical_devices('GPU')
if len(physical_devices) > 0:
tf.config.experimental.set_memory_growth(physical_devices[0], True)https://stackoverflow.com/questions/56613536
复制相似问题