无法加载库 cudnn_cnn_infer64_8.dll。错误代码 126

Hse*_*ran 13 python tensorflow cudnn

Could not load library cudnn_cnn_infer64_8.dll. Error code 126
Please make sure cudnn_cnn_infer64_8.dll is in your library path!
Run Code Online (Sandbox Code Playgroud)

当我尝试将 TensorFlow 与 GPU 结合使用时,我不断收到此错误,我已根据说明多次安装了 CUDA、cuDNN 和所有驱动程序。但似乎没有任何作用。如果我使用笔记本,那么 TensorFlow 使用 CPU,通过 VS code 笔记本扩展,我可以使用 GPU,但当我尝试将其作为普通 python 文件运行时,它会在第一个纪元停止会话。出现上述错误。

完整的终端输出:

Found 14630 validated image filenames belonging to 3 classes.
Found 1500 validated image filenames belonging to 3 classes.
2021-11-08 11:03:58.000354: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-11-08 11:03:58.603592: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 2775 MB memory:  -> device: 0, name: NVIDIA GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1        
Epoch 1/10
2021-11-08 11:04:07.306011: I tensorflow/stream_executor/cuda/cuda_dnn.cc:366] Loaded cuDNN version 8300
Could not load library cudnn_cnn_infer64_8.dll. Error code 126
Please make sure cudnn_cnn_infer64_8.dll is in your library path!
E:\MyWorkSpace\animal_detect>
Run Code Online (Sandbox Code Playgroud)

代码片段:

import tensorflow as tf 
from tensorflow.keras.preprocessing.image import ImageDataGenerator 
from tensorflow.keras import layers 
from tensorflow.keras import Model 
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.applications.vgg16 import VGG16
import pandas as pd
import numpy as np

train_df = pd.read_csv('train.csv')
test_df = pd.read_csv('test.csv')
train_gen = ImageDataGenerator(rescale = 1./255.,rotation_range = 40, width_shift_range = 0.2, height_shift_range = 0.2, shear_range = 0.2, zoom_range = 0.2, horizontal_flip = True)
test_gen = ImageDataGenerator( rescale = 1.0/255. )
train_set = train_gen.flow_from_dataframe(train_df,x_col='loc',y_col='label',batch_size=20,target_size=(224,224))
test_set = train_gen.flow_from_dataframe(test_df,x_col='loc',y_col='label',batch_size=20,target_size=(224,224))
base_model = VGG16(input_shape = (224, 224, 3),
include_top = False,
weights = 'imagenet')
for layer in base_model.layers:
    layer.trainable = False
x = layers.Flatten()(base_model.output)
x = layers.Dense(512, activation='relu')(x)
x = layers.Dropout(0.5)(x)
x = layers.Dense(3, activation='sigmoid')(x)

model = tf.keras.models.Model(base_model.input, x)

model.compile(optimizer = tf.keras.optimizers.RMSprop(learning_rate=0.0001), loss = 'categorical_crossentropy',metrics = ['acc'])
vgghist = model.fit(train_set, validation_data = test_set, steps_per_epoch = 100, epochs = 10)
Run Code Online (Sandbox Code Playgroud)

相同的代码已用于 Jupyter-notebook、VS code 笔记本扩展以及普通的 python 文件

设备规格:

处理器:Intel i5 GPU:Nvidia Geforce 1050ti

Cuda版本:11.5 cuDNN版本:8.3

and*_*idu 37

对于仍然遇到此问题的用户,请确保您也已完成此步骤

在此输入图像描述

下载、解压并添加zlibwapi.dll到系统路径。祝你好运!

  • 我认为这是最正确的解决方案,因为它包含在官方 cuDNN 安装指南中。此外,无需降级 cuDNN 版本。 (3认同)
  • 谢谢,它成功了。我确实忽略了这个安装指南(那是我的错)。我已经为 cuda11.5 和 cudnn8.3 编译了 tf2.7,但在将 zlibwapi.dll 添加到系统路径之前无法使用 cudnn8.3。虽然 zlibwapi. dll不影响cudnn8.2的使用,但确实影响cudnn8.3的正确运行。 (2认同)

Lit*_*ain 17

和我一样的“错误”。尽管我已经用“Cuda版本:11.5 cuDNN版本:8.3”重新编译了tensorflow-gpu 2.6.0。当我将 cudnn 版本更改为 8.2 但保留 cuda 版本为 11.5 时,“错误”消失了。(也需要重新编译)所以我认为这个错误一定是在“cuDNN”上。

请参阅 androidu 的回答。它工作得很好。

  • 这为我解决了问题,谢谢!我选择了“下载 cuDNN v8.2.2(2021 年 7 月 6 日),适用于 CUDA 11.4” (6认同)
  • 它也对我有用:下载并安装 **CUDA Toolkit 11.5**,然后下载不兼容的 cuDNN v8.2.4(2021 年 9 月 2 日),对于 **CUDA 11.4**,将文件放置在正确的文件夹中,如 https 所示: //docs.nvidia.com/deeplearning/cudnn/install-guide/index.html,瞧,痛苦消失了!谢谢@小火车 (6认同)