【报错】
首先报错:
could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
尝试解决:
https://blog.csdn.net/weixin_44754046/article/details/97663626
在最开头添加:
import tensorflow as tf
config = tf.ConfigProto(gpu_options=tf.GPUOptions(allow_growth=True))
sess = tf.Session(config=config)
可以适当的使用GPU,But!
后又报错:
failed to run cuBLAS routine cublasSgemm_v2: CUBLAS_STATUS_EXECUTION_FAILED
尝试解决:
https://tbr8.org/how-to-solve-failed-to-run-cublas-routine-cublassgemm-v2-cublas-status-execution-failed-problem/
一般遇到这个问题都是cuda=9.0的,说要打补丁,心里oso,但是我是cudu10 没有补丁可以打,因为官方只有一个文件可下载,没有补丁。
排查过程:
1.注意:我在使用以下做验证的时候,会发现自己在使用GPU2070,也就是说环境应该没有问题。
import tensorflow as tf
with tf.device('/cpu:0'):
a = tf.constant([1.0, 2.0, 3.0], shape=[3], name='a')
b = tf.constant([1.0, 2.0, 3.0], shape=[3], name='b')
with tf.device('/gpu:0'):
c = a + b
# 注意:allow_soft_placement=True表明:计算设备可自行选择,如果没有这个参数,会报错。
# 因为不是所有的操作都可以被放在GPU上,如果强行将无法放在GPU上的操作指定到GPU上,将会报错。
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True, log_device_placement=True))
# sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
sess.run(tf.global_variables_initializer())
print(sess.run(c))
# 打印所有的设备
from tensorflow.python.client import device_lib
#print(device_lib.list_local_devices())
2.再看下自己使用的是GPU还是CPU版本,都是使用GPU2070
# 查看所使用的tensorflow是GPU还是CPU版本
import os
from tensorflow.python.client import device_lib
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "99"
if __name__ == "__main__":
print(device_lib.list_local_devices())
3.最后认真看报错,发现在node,是在用xception这个网络的时候可分离卷积这里也提示报错。
x = SeparableConv2D(128, (3, 3), padding='same', use_bias=False)(x)
所以我猜测会不会是因为这个网络。
所以我试了几层cnn网络,ok,可以训练,不报错。
那么问题来了,会不会是因为版本太低造成的,因为朋友说cuda 10 至少是tf=1.13和对应的keras,而我是tf=1.8 keras=2.1.5,可以尝试下提高下