环境配置为Ubuntu16.04、tensorflow 1.13.1、cuda10、cudnn7.6.4。
在运行tensorflow代码时报错
UnknownError (see above for traceback): 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.
在tensorflow、cuda、cudnn版本正确对应下,在代码中添加如下代码:
import os
os.environ['CUDA_VISIBLE_DEVICES'] = "0"
config = tf.ConfigProto()
config.allow_soft_placement=True # 如果你指定的设备不存在,允许TF自动分配设备
config.gpu_options.per_process_gpu_memory_fraction=0.9 #分配一部分显存给程序使用,避免内存溢出
config.gpu_options.allow_growth = True #按需分配显存
with tf.Session(config=config) as sess:
#你的代码