TensorFlow DLL文件缺失解决方案

前言:

最近在用TensorFlow做车牌识别的项目,在训练模型时发现了如下问题,那就是xxx.dll not found.(本人是windwos电脑,可能Windows电脑问题比较多,如果cuda环境变量一项配置有问题就可能导致程序无法执行),今天就以cudnn64_7.dll 文件not found 为例,讲解如何解决这一类问题。

问题描述和分析

在用gpu训练模型时,为了验证gpu是否可用,执行了如下程序。

import tensorflow as tf
import os

os.environ["CUDA_VISIBLE_DEVICES"] = "0"
print(tf.__version__)
a = tf.constant(1.)
b = tf.constant(2.)
print(a + b)
print('GPU:', tf.test.is_gpu_available())

然后执行以上的代码后,发现报了如下错误:

D:\Users\Administrator\Anaconda3\python.exe E:/hyperlpr-train/tensorflowGpu.py
2021-05-14 18:50:06.283947: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2.2.0
2021-05-14 18:50:13.818450: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2021-05-14 18:50:13.835941: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce RTX 2070 SUPER computeCapability: 7.5
coreClock: 1.815GHz coreCount: 40 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 417.29GiB/s
2021-05-14 18:50:13.836128: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-05-14 18:50:13.839458: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-05-14 18:50:13.841704: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-05-14 18:50:13.842960: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-05-14 18:50:13.845417: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-05-14 18:50:13.847722: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-05-14 18:50:13.850513: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2021-05-14 18:50:13.850618: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2021-05-14 18:50:14.143759: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-05-14 18:50:14.154386: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x25d93ccb3c0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-05-14 18:50:14.154570: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-05-14 18:50:14.154697: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-14 18:50:14.154785: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      
tf.Tensor(3.0, shape=(), dtype=float32)
WARNING:tensorflow:From E:/hyperlpr-train/tensorflowGpu.py:9: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2021-05-14 18:50:15.852497: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce RTX 2070 SUPER computeCapability: 7.5
coreClock: 1.815GHz coreCount: 40 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 417.29GiB/s
2021-05-14 18:50:15.853123: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-05-14 18:50:15.853210: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-05-14 18:50:15.853294: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-05-14 18:50:15.853383: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-05-14 18:50:15.853471: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-05-14 18:50:15.853560: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-05-14 18:50:16.070937: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found
2021-05-14 18:50:16.071049: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2021-05-14 18:50:16.138353: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-14 18:50:16.138450: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2021-05-14 18:50:16.138505: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2021-05-14 18:50:16.139480: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x25da4d20b10 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-05-14 18:50:16.139596: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce RTX 2070 SUPER, Compute Capability 7.5
GPU: False

报错的日志很长,我们做一下过滤,你会发现核心提示错误如下,图中我已近标出。
在这里插入图片描述
认真看图中标记的1,2,3部分,你会发现,在第一部分中,cudart64_101.dll,cublas64_10.dll,cufft64_10.dll,curand64_10.dll,cusolver64_10.dll,cusparse64_10.dll文件都存在,并且 Successfully opened dynamic library,唯独第二部分的cudnn64_7.dll打开失败,所以导致GPU也无法使用,所以在第三步中显示了GPU: False。打开失败原因吗,在第二部分中已经显示的非常清楚,Could not load dynamic library 'cudnn64_7.dll'; dlerror: cudnn64_7.dll not found,随之也给出了参考解决方案:Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.Skipping registering GPU devices...

既然知道是cudnn64_7.dll文件缺失,那好办,只需要下载cudnn64_7.dll文件就好了。

解决方案

1. 推荐解决方案,重新下载CUDA和与之对应的CUDNN.

一般情况下,如下问题基本都能解决,如果你的window和我一样变态,我推荐你可以尝试一下第二种方案。

2. 搜索缺失DLL系列并安装
比如我这里缺失的是cudnn64_7.dll,那么我就下载cudnn64_7.dll文件即可。下面是我在网上搜罗的好心人分享的各种dll文件的链接地址:

此外,以下四个cndnn6/7/8/9版本都有,链接为https://pan.baidu.com/s/10Bm48r7-qruAAzh9-wgPig#list/path=%2F,提取码:bsir

下载完毕之后,我们只需把对应的xxx.dll文件放在对应的目录下即可。一般都是放在如下俩个目录:

  1. C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin
  2. C:\Windows\System32

好了,执行一下第一步中的代码(验证代码更具自己的实际情况而定,我这里就是验证GPU是否可用),果然,GPU是可以用的,看看成功后的日志如下:

D:\Users\Administrator\Anaconda3\python.exe E:/hyperlpr-train/tensorflowGpu.py
2021-05-14 19:27:19.226930: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2.2.0
2021-05-14 19:27:20.746048: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2021-05-14 19:27:20.761813: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce RTX 2070 SUPER computeCapability: 7.5
coreClock: 1.815GHz coreCount: 40 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 417.29GiB/s
2021-05-14 19:27:20.762000: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-05-14 19:27:20.764550: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-05-14 19:27:20.766331: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-05-14 19:27:20.767209: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-05-14 19:27:20.769296: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-05-14 19:27:20.771242: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-05-14 19:27:20.824569: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2021-05-14 19:27:20.999286: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-05-14 19:27:20.999775: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-05-14 19:27:21.005884: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x29e89bb5040 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-05-14 19:27:21.006029: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2021-05-14 19:27:21.006383: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce RTX 2070 SUPER computeCapability: 7.5
coreClock: 1.815GHz coreCount: 40 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 417.29GiB/s
2021-05-14 19:27:21.006567: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-05-14 19:27:21.006661: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-05-14 19:27:21.006756: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-05-14 19:27:21.006846: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-05-14 19:27:21.006938: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-05-14 19:27:21.007029: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-05-14 19:27:21.007119: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2021-05-14 19:27:21.007403: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-05-14 19:28:38.869252: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-14 19:28:38.869782: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2021-05-14 19:28:38.870114: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2021-05-14 19:28:38.966406: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6620 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2070 SUPER, pci bus id: 0000:01:00.0, compute capability: 7.5)
2021-05-14 19:28:39.014094: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x29ec10ed830 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2021-05-14 19:28:39.014219: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce RTX 2070 SUPER, Compute Capability 7.5
tf.Tensor(3.0, shape=(), dtype=float32)
WARNING:tensorflow:From E:/hyperlpr-train/tensorflowGpu.py:9: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2021-05-14 19:28:40.552702: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:01:00.0 name: GeForce RTX 2070 SUPER computeCapability: 7.5
coreClock: 1.815GHz coreCount: 40 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 417.29GiB/s
2021-05-14 19:28:40.552888: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2021-05-14 19:28:40.552980: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2021-05-14 19:28:40.553066: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2021-05-14 19:28:40.553149: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2021-05-14 19:28:40.553236: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2021-05-14 19:28:40.553325: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2021-05-14 19:28:40.553411: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2021-05-14 19:28:40.553693: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2021-05-14 19:28:40.553790: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2021-05-14 19:28:40.553879: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2021-05-14 19:28:40.553934: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2021-05-14 19:28:40.554219: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/device:GPU:0 with 6620 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2070 SUPER, pci bus id: 0000:01:00.0, compute capability: 7.5)
GPU: True

这里我提供一下各种dll文件下载的地址,进入官网,自己自行搜索自己缺少的dll文件。直接在网站https://www.dll-files.com/search/下载:
在这里插入图片描述

友情提示:

需要特别提示的是,有些缺少DLL文件并不一定是安装了相应的DLL文件就能解决的。有时候需要降低自己的tensorflow版本使tensorflow与其它的函数库相匹配才可以。

  • 6
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值