tensorflow 在 gpu 上训练时报如下错误

Failed to get convolution algorithm. This is probably because cuDNN failed to initialize

 

解决办法

加上如下代码

import os
import tensorflow as tf
from tensorflow import ConfigProto
from tensorflow import InteractiveSession

# 注意如果还报错,加在代码开头试试
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
# os.environ['CUDA_VISIBLE_DEVICES'] = '/gpu:0'
config = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)
# session = tf.Session(config=config)

这是 GPU 显存不够了,上面代码意思是对 GPU 进行按需分配

 

 

 

参考资料:

https://blog.csdn.net/tsyccnh/article/details/102938368

https://www.cnblogs.com/xiaxuexiaoab/p/12388388.html

https://www.jianshu.com/p/e13aa15f35da  tensorflow2.0卷积报错:Failed to get convolution algorithm. This is probably because cuDNN failed to i...