Keras,Tensorflow无法打开CUDA库libcudnn.so。 LD_LIBRARY_PATH:

时间:2016-10-26 09:33:47

标签: tensorflow keras mnist cudnn

我已经安装了CUDA 8.0并将cuDNN文件复制到Install CUDA (GPUs on Linux)所说的目录中。

我运行mnist_cnn.py并获得以下信息:

Using TensorFlow backend.
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:105] Couldn't open CUDA library libcudnn.so. LD_LIBRARY_PATH: 
I tensorflow/stream_executor/cuda/cuda_dnn.cc:3448] Unable to load cuDNN DSO
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
X_train shape: (60000, 28, 28, 1)
60000 train samples

最后

Traceback (most recent call last):
  File "mnist_cnn.py", line 65, in <module>
    model.add(Dropout(0.25))
  File "/home/nsknsl/.local/lib/python3.5/site-packages/keras/models.py", line 308, in add
    output_tensor = layer(self.outputs[0])
  File "/home/nsknsl/.local/lib/python3.5/site-packages/keras/engine/topology.py", line 514, in __call__
    self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
  File "/home/nsknsl/.local/lib/python3.5/site-packages/keras/engine/topology.py", line 572, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/home/nsknsl/.local/lib/python3.5/site-packages/keras/engine/topology.py", line 149, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
  File "/home/nsknsl/.local/lib/python3.5/site-packages/keras/layers/core.py", line 90, in call
    x = K.in_train_phase(K.dropout(x, self.p, noise_shape), x)
  File "/home/nsknsl/.local/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 1304, in in_train_phase
    x = tf.python.control_flow_ops.cond(tf.cast(_LEARNING_PHASE, 'bool'),
AttributeError: module 'tensorflow.python' has no attribute 'control_flow_ops'
Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7ff2a70e4ba8>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 532, in __del__
AttributeError: 'NoneType' object has no attribute 'TF_DeleteStatus'

那么如何加载cuDNN DSO?

2 个答案:

答案 0 :(得分:5)

如评论中所述,如果您还没有,则需要运行以下命令来设置环境变量:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda

您也可以将这些命令添加到〜/ .bashrc的末尾,以便下次登录时执行。

自: https://www.tensorflow.org/versions/master/install/install_linux#nvidia_requirements_to_run_tensorflow_with_gpu_support

答案 1 :(得分:0)

  1. 首先,请确保您已经安装了cudnn。安装Cuda后,应单独完成安装。

  2. 然后你需要找到你的'libcudnn.so'的路径。通过: sudo find /usr/ -name 'libcudnn.so'

  3. 对我来说,我得到/usr/local/cuda-8.0/targets/x86_64-linux/lib

    1. 您还需要找到通过使用装载良好的库(例如libcufft.so)找到库的路径。 sudo find /usr/ -name 'libcufft.so' 对我来说,我得到/usr/lib

    2. 现在将文件复制到正确的位置: sudo cp /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcud* /usr/lib

    3. 退出之前的Tensorflow会话并启动一个新会话 去测试。它对我有用:)