【发布时间】:2018-02-01 15:37:40
【问题描述】:
我已经安装了 CUDA 和 cuDNN,但是最后一个不起作用,在 theano 中给出了很多错误消息。现在我在 Keras/Tensorflow 中训练中等大小的深度卷积网络,没有收到任何 cuDNN 错误消息。如何检查是否正在使用 cuDNN?
【问题讨论】:
标签: tensorflow keras cudnn
我已经安装了 CUDA 和 cuDNN,但是最后一个不起作用,在 theano 中给出了很多错误消息。现在我在 Keras/Tensorflow 中训练中等大小的深度卷积网络,没有收到任何 cuDNN 错误消息。如何检查是否正在使用 cuDNN?
【问题讨论】:
标签: tensorflow keras cudnn
tl;dr:如果 tensorflow-gpu 有效,则使用 CuDNN。
TensorFlow 的预构建二进制文件(至少从 1.3 版开始)链接到 CuDNN 库。如果缺少 CuDNN,则会出现错误消息告诉您 ImportError: Could not find 'cudnn64_7.dll'. TensorFlow requires that this DLL be installed...。
根据TensorFlow install documentation for version 1.5,即使您从源代码构建,也必须安装 CuDNN 以支持 GPU。在 CuDNN 不可用的情况下,TensorFlow 代码中仍有很多回退——据我所知,它在以前的版本中曾经是可选的。
需要安装一个特殊的 GPU 版本的 TensorFlow 才能使用 GPU(和 CuDNN)。确保安装的 python 包是tensorflow-gpu 而不仅仅是tensorflow。
您可以使用conda list tensorflow(或仅pip list,如果您不使用anaconda)列出包含“tensorflow”的包,但请确保您激活了正确的环境。
当您在支持 GPU 的情况下运行脚本时,它们将像这样开始:
Using TensorFlow backend.
2018- ... C:\tf_jenkins\...\gpu\gpu_device.cc:1105] Found device 0 with properties:
name: GeForce GTX 1080 major: 6 minor: 1 memoryClockRate(GHz): 1.7845
要测试它,只需在控制台中输入:
import tensorflow as tf
tf.Session()
要检查您是否从 Python 环境中“看到”了 CuDNN 并由此验证正确的 PATH 变量,您可以尝试以下操作:
import ctypes
ctypes.WinDLL("cudnn64_7.dll") # use the file name of your cudnn version here.
【讨论】:
您可能还想了解 GPU 优化的 Keras 层。
它们明显更快: https://keras.io/layers/recurrent/#cudnnlstm
我们看到从 LSTM 到 CuDNNLSTM Keras 层有 10 倍的改进。
注意: 我们还看到机器上的 VMS(虚拟内存)使用量增加了 10 倍。所以需要权衡取舍。
【讨论】: