Failed to get convolution algorithm. This is probably because cuDNN failed to initialize 해결하기, feat. 케라스 창시자에게 배우는 딥러닝

Failed to get convolution algorithm. This is probably because cuDNN failed to initialize 해결하기, feat. 케라스 창시자에게 배우는 딥러닝

케라스 책을 따라하다 보면 나오는 에러에 대한 트러블 슈팅

Failed to get convolution algorithm. This is probably because cuDNN failed to initialize

케라스 창시자에게 배우는 딥러닝 책 진도를 쭉쭉 나가는 중이었다. 챕터5의 CNN코드를 돌리던 중 다음과 같은 에러가 등장했다.

1
2
3
(0) Unknown: Failed to get convolution algorithm. 
This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
[[{{node conv2d_1/convolution}}]] [[metrics/acc/Mean/_99]]

황금같은 쉬는 날에 cudnn과 CUDA의 꼬임으로 인한 에러인 줄 알고 굉장히 낙담했다. 실제로 저 에러를 복사해다가 구글에 붙여넣어서 답을 찾아보니 다시 설치하라는 의견이 많았다.

하지만 정말 귀찮아서 내 설치 환경을 다시 살펴보고 이상이 있으면 수정하기로 했다.

일단 내가 설치한 CUDA와 CuDnn 환경은 저번 글들에 나와 있다.

ubuntu 딥러닝 서버 구축기 01
ubuntu 딥러닝 서버 구축기 02
ubuntu 딥러닝 서버 구축기 03

CUDA와 CuDNN의 호환성은 문제가 없었다. 그렇다면 뭐가 문제였을까? 하던 중에 Python의 버젼을 살펴봤다.
콘다 가상환경에 올리고 쓰고 있었는데 python버전을 확인해보니 python 3.7버전이었다.

여러 글들을 보다보니 python 3.6버전이 keras와 궁합이 잘 맞는다는 것을 알게되었다.

그래서 바로

1
conda create -n [환경 이름] python=3.6

가상환경을 만들어주고 만든 가상환경을 jupyter kernelspec에 넣어주었다.
jupyter kernelspec 추가하기

python 3.6으로 갈아끼워 준 뒤에

1
2
3
4
5
6
model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
1
2
3
model.add(layers.Flatten())
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from keras.datasets import mnist
from keras.utils import to_categorical

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
# train_images = train_images.reshape((60000, 28, 28, 1))

train_images = train_images.reshape((60000, 28,28, 1))
train_images = train_images.astype('float32')/255

test_images = test_images.reshape((10000, 28, 28, 1))
test_images = test_images.astype('float32')/255

train_labels = to_categorical(train_labels)
test_labels = to_categorical(test_labels)

model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit(train_images, train_labels,
epochs=5, batch_size=64)

코드를 돌렸더니 잘 돌아간다!!!

Failed to get convolution algorithm. This is probably because cuDNN failed to initialize 해결하기, feat. 케라스 창시자에게 배우는 딥러닝

http://tkdguq05.github.io/2020/01/01/keras-trouble-shooting/

Author

SangHyub Lee, Jose

Posted on

2020-01-01

Updated on

2023-12-08

Licensed under

Comments