tensorflow报错:Failed to get convolution algorithm.This is probably because cuDNN failed to initialize

系统:ubuntu16.04
显卡:RTX2060
NVIDIA 驱动:440.100
CUDA版本: 10.0.130
cudnn版本: 7.4.2
tensorflow版本:tensorflow-gpu 1.13.1

使用tensorflow的卷积层时报如下错误:

2020-07-08 01:00:52.181618: E tensorflow/stream_executor/cuda/cuda_dnn.cc:334] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
2020-07-08 01:00:52.183245: E tensorflow/stream_executor/cuda/cuda_dnn.cc:334] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
Traceback (most recent call last):
  File "/home/zk/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call
    return fn(*args)
  File "/home/zk/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1319, in _run_fn
    options, feed_dict, fetch_list, target_list, run_metadata)
  File "/home/zk/anaconda3/envs/python37/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
	 [[{
     {
     node Conv2D}}]]

其中更关键的信息可能是这一句Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR

解决方案:
可能是内存分配问题,使用如下代码

import tensorflow as tf
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5)
config = tf.ConfigProto(gpu_options=gpu_options)
config.gpu_options.allow_growth = True
session = tf.Session(config=config)

其中0.5为GPU使用率,可按照自己的情况调节
参考自algorithm - 无法创建cudnn句柄:CUDNN STATUS INTERNAL ERROR

你可能感兴趣的:(ubuntu,tensorflow,深度学习)