报错:tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm.

UnknownError: Failed to get convolution algorithm.

运行sess.run()
错误行标定这一行:sess.run(optimizer, feed_dict={ x: batch_x, y: batch_y, keep_prob: dropout }
显示错误信息:tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm.

分析原因和解决方案
方法一:IDE运行加载多次代码,tensorflow-cpu 与tensorflow-gpu有相同接口,卷积时,可能调了不匹配的那一个。可以重启再重新运行即可(我是重启后运行正常)

方法二:在代码中添加gpu的配置说明

import os
os.environ["CUDA_VISIBLE_DEVICES"] = '0' #use GPU with ID=0
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.5 # maximun alloc gpu50% of MEM
config.gpu_options.allow_growth = True #allocate dynamically

结果:

2020-01-17 14:28:01.382158: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-01-17 14:28:12.010206: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-01-17 14:28:12.010391: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 
2020-01-17 14:28:12.010503: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N 
2020-01-17 14:28:12.040409: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2108 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1060 3GB, pci bus id: 0000:01:00.0, compute capability: 6.1)
2020-01-17 14:28:13.049929: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_100.dll
2020-01-17 14:28:14.220136: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll

你可能感兴趣的:(AI,gpu,tensorflow)