错误:
未知错误:无法获取卷积算法。这可能是 因为 cuDNN 初始化失败,所以请尝试查看是否有警告 日志消息打印在上面。[操作:Conv2D]
用于软件包安装的命令:
conda install -c anaconda keras-gpu
安装:
- 张量流 2.0.0
- 库达工具包 10.0.130 0
- 库德恩 7.6.5
- cuda10.0_0
Keras-GPU 2.2.4 0
tf.test.is_gpu_available()
返回True
未知错误:无法获取卷积算法。这可能是 因为 cuDNN 初始化失败,所以请尝试查看是否有警告 日志消息打印在上面。[操作:Conv2D]
通常,出现此问题是由于安装的 CUDA 和 cuDNN 驱动程序不兼容。请参阅经过测试的 Linux 和 CPU 构建配置。
如果tf.test.is_gpu_available()
返回True
意味着安装没有问题。
因此,在下一步中,您可以通过允许 GPU 内存增长来尝试 GPU 内存资源管理。
这可以通过调用来完成tf.config.experimental.set_memory_growth
,它尝试仅分配运行时分配所需的 GPU 内存:它开始分配很少的内存,随着程序运行并且需要更多 GPU 内存,我们扩展分配给 TensorFlow 进程的 GPU 内存区域。
要为特定 GPU 启用内存增长,请在分配任何张量或执行任何操作之前使用以下代码。
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
# Currently, memory growth needs to be the same across GPUs
for 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 initialized
print(e)
启用内存增长的另一种方法是将环境变量TF_FORCE_GPU_ALLOW_GROWTH
设置为true
。此配置特定于平台。
在此方法中,使用tf.config.experimental.set_virtual_device_configuration
配置虚拟 GPU 设备,并对要在 GPU 上分配的总内存设置硬限制。
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
# Restrict TensorFlow to only allocate 1GB of memory on the first GPU
try:
tf.config.experimental.set_virtual_device_configuration(
gpus[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)])
logical_gpus = tf.config.experimental.list_logical_devices('GPU')
print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:
# Virtual devices must be set before GPUs have been initialized
print(e)
欲了解更多详情,请参阅此处
这里有一个建议,您可以尝试安装tensorflow-gpu
而不是keras-gpu
。