无法在GPU上训练Keras卷积网络 [英] cannot train Keras convolution network on GPU
问题描述
我可以使用keras.datasets.fashion_mnist
数据集训练带有Dense
层的Keras网络.但是,当我尝试训练卷积网络时,出现了错误.
I can train a Keras network with Dense
layer using keras.datasets.fashion_mnist
dataset. However, when I tried to train a convolutional network, I got an error.
这是代码的一部分:
from tensorflow.keras.layers import *
model = keras.Sequential([
Convolution2D(16, (3,3), activation='relu', input_shape=(28,28,1)),
MaxPooling2D(pool_size=(2,2)),
Flatten(),
Dense(16, activation='relu'),
Dense(10, activation='softmax')
])
model.compile(optimizer=tf.train.AdamOptimizer(),
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=5)
及其在尝试适应时的错误.
and its error when I tried to fit.
UnknownError:无法获得卷积算法.这可能是 由于cuDNN无法初始化,因此请尝试查看是否有警告 日志消息已打印在上方. [[{{node conv2d/Conv2D}} = Conv2D [T = DT_FLOAT,data_format ="NCHW",膨胀= [1,1,1,1], padding ="VALID",步幅= [1、1、1、1],use_cudnn_on_gpu = true, _device ="/job:localhost/replica:0/task:0/device:GPU:0"](培训/TFOptimizer/gradients/conv2d/Conv2D_grad/Conv2DBackpropFilter-0-TransposeNHWCToNCHW-LayoutOptimizer, conv2d/Conv2D/ReadVariableOp)]] [[{{node loss/dense_1_loss/broadcast_weights/assert_broadcastable/AssertGuard/Assert/Switch_2/_69}} = _Recvclient_terminated = false,recv_device ="/job:localhost/副本:0/task:0/device:CPU:0", send_device ="/job:localhost/副本:0/task:0/device:GPU:0", send_device_incarnation = 1,tensor_name ="edge_112_l ... t/Switch_2", tensor_type = DT_INT32, _device ="/job:localhost/replica:0/task:0/device:CPU:0"]]
UnknownError: 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/Conv2D}} = Conv2D[T=DT_FLOAT, data_format="NCHW", dilations=[1, 1, 1, 1], padding="VALID", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](training/TFOptimizer/gradients/conv2d/Conv2D_grad/Conv2DBackpropFilter-0-TransposeNHWCToNCHW-LayoutOptimizer, conv2d/Conv2D/ReadVariableOp)]] [[{{node loss/dense_1_loss/broadcast_weights/assert_broadcastable/AssertGuard/Assert/Switch_2/_69}} = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device_incarnation=1, tensor_name="edge_112_l...t/Switch_2", tensor_type=DT_INT32, _device="/job:localhost/replica:0/task:0/device:CPU:0"]]
我在C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
中有cudnn64_7.dll
,并且PATH
已经包含该文件夹.
I have cudnn64_7.dll
in C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
and the PATH
is already contain that folder.
推荐答案
我认为此链接可以解决您的问题,这是因为您安装的cnDNN版本与在tensorflow中编译的cuDNN版本不兼容.
I think this link would solve your problem, its because the cnDNN version you installed is not compatible with the cuDNN version that compiled in tensorflow.
这篇关于无法在GPU上训练Keras卷积网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!