使用tf2.1时,cuda和cudnn都安装好了,报错
Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
最开始以为是cudnn版本问题,试了各种方法,包括用conda重新装,不过推荐大家安装tensorflow-gpu可以用conda,可以默认安装cuda和cudnn,省心。不过这个错误不是这个原因导致的。
解决办法是在代码中加入下面代码:
pus = tf.config.experimental.list_physical_devices('GPU')
if gpus:try:# Currently, memory growth needs to be the same across GPUsfor gpu in gpus:tf.config.experimental.set_memory_growth(gpu, True)logical_gpus = tf.config.experimental.list_logical_devices('GPU')print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")except RuntimeError as e:# Memory growth must be set before GPUs have been initializedprint(e)