Please make sure cudnn_cnn_infer64_8.dll is in your library path

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!

I keep getting this error when I try to use TensorFlow with GPU, I've installed CUDA, cuDNN, and all the drivers multiple times according to the instructions. But nothing seems to work.
If I use notebook then TensorFlow uses the CPU, with VS code notebook extension i can use the gpu but it stops the session at 1st epoch, when I tried to run it as a normal python file. the above error occurred.

Complete terminal output:


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>

The code snippet:


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)

the same code has been used for Jupyter-notebook, VS code notebook extension and as a normal python file

Device specifications:

processor: Intel i5
gpu: Nvidia Geforce 1050ti

Cuda version: 11.5
cuDNN version: 8.3


Problem description

The error message of tensorflow in Windows environment is:

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!

My CUDA version is 11.5 and cudnn version is 11.5.

resolvent

I reinstalled CUDA 11.5 and the corresponding cudnn, and repeatedly confirmed that the two versions were consistent, but the problem could not be solved.
Find CUDA path, cudnn_ cnn_ infer64_ 8.dll file exists, but tensorflow cannot be imported.
This file is responsible for the underlying operation of CNN, so the problem is not solved and the model cannot run.
There are two solutions:

  • With CUDA version 11.5, installcuDNN v8.2.2 (July 6th, 2021), for CUDA 11.4。 The original problem was caused by the mismatch between cudnn and CUDA. Why does the official version still not match? Maybe this is called a bug!
  • Use windll (path) to import the file path manually, but this method is not recommended because it needs to be imported manually every time CNN needs to be run.

It should be noted that if your CUDA version is not 11.5, but this problem still occurs, please check the following two points:

  • Does your graphics card support the current CUDA version
  • Does CUDA version match cudnn version

Toplist

Latest post

TAGs