我正在尝试将 GPU 与 Tensorflow 结合使用,因此我安装了 CUDA 10.1、CUNN 7.6、TensorRT 6 和 Tensorflow-GPU 2.1.0。但是当我导入 tensorflow 来检查它是否可以检测到 gpu 时,它给出了以下错误
>>> import tensorflow as tf
2020-04-22 14:44:14.473830: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer.so.6'; dlerror: libnvinfer.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda-10.1/lib64
2020-04-22 14:44:14.473880: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'libnvinfer_plugin.so.6'; dlerror: libnvinfer_plugin.so.6: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda/lib64:/usr/local/cuda-10.1/lib64
2020-04-22 14:44:14.473887: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:30] Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
你能告诉我如何获取丢失的库吗?
谢谢你哈迪尔
答案1
这在 Ubuntu 19.10(以及可能的其他版本)中有效:
警告:这可能会破坏您的 NVIDIA 显卡驱动程序,因此请通过备份磁盘、ZFS 快照或其他方式后退步骤以启动。您已收到警告。
我能够启动图形版本,但 OpenGL 已损坏。下面是恢复方法的说明。
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1810/x86_64/cuda-repo-ubuntu1810_10.1.168-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1810_10.1.168-1_amd64.deb
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1810/x86_64/7fa2af80.pub
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo apt update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo dpkg -i nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt update
sudo apt-get install --no-install-recommends \
cuda-10-1 \
libcudnn7=7.6.4.38-1+cuda10.1 \
libcudnn7-dev=7.6.4.38-1+cuda10.1
# Install TensorRT. Requires that libcudnn7 is installed above.
sudo apt-get install -y --no-install-recommends
libnvinfer6=6.0.1-1+cuda10.1 \
libnvinfer-dev=6.0.1-1+cuda10.1 \
libnvinfer-plugin6=6.0.1-1+cuda10.1
正如我上面所说,我必须重新安装我的 NVIDIA 显卡驱动器:
sudo add-apt-repository ppa:graphics-drivers
sudo apt update
sudo apt -u dist-upgrade
然后重新启动并尝试导入 tensorflow 以及运行 OpenGL 应用程序。如果一切顺利,两者都应该可以正常工作。
答案2
我解决了
1.首先我们需要找到“libnvinfer.so”文件的位置
sudo find . -iname libnvinfer.so*
我得到的结果如下:
./usr/lib/x86_64-linux-gnu/libnvinfer.so ./usr/lib/x86_64-linux-gnu/libnvinfer.so.6 ./usr/lib/x86_64-linux-gnu/libnvinfer.so.7.2.1 ./usr/lib/x86_64-linux-gnu/libnvinfer.so.7 ./usr/lib/x86_64-linux-gnu/libnvinfer.so.6.0.1
所需文件位于/usr/lib/x86-linux-gnu
我们需要将该路径添加到 $LD_LIBRARY_PATH(环境变量)中
回显“导出LD_LIBRARY_PATH = / usr / lib / x86_64-linux-gnu:$ LD_LIBRARY_PATH”>>〜/ .bashrc
源 ~/.bashrc