无法获得卷积算法。这可能是因为cuDNN无法初始化

时间:2019-03-03 19:56:10

标签: tensorflow keras cudnn

我正在尝试学习VGG16模型。但是现在,我遇到了类似的错误,

  

使用TensorFlow后端。   UnknownError:无法获得卷积算法。这可能是   由于cuDNN无法初始化,因此请尝试查看是否有警告   日志消息已打印在上方。 [[{{node conv2d_1 / convolution}} =   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”](conv2d_1 / convolution-0-TransposeNHWCToNCHW-LayoutOptimizer,   conv2d_1 /内核/读取)]] [[{{node density_3 / Softmax / _211}} =   _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_237_dense_3 / Softmax”,   tensor_type = DT_FLOAT,   _device =“ / job:localhost /副本:0 /任务:0 /设备:CPU:0”]]

这是我的系统版本,

  • Windows 10
  • Tensorflow 1.10.0
  • Python 3.6.7
  • cuDNN和CUDA;
  • NVIDIA GeForce GTX 1050TI
  • Keras,使用TensorFlow backend.2.2.4
  

nvcc:NVIDIA(R)Cuda编译器驱动程序版权所有(c)2005-2017 NVIDIA   公司基于Fri_Sep__1_21:08:32_Central_Daylight_Time_2017建立   Cuda编译工具,版本9.0,V9.0.176

如果您需要代码;

from keras.models import Sequential
from keras.layers.core import Flatten, Dense, Dropout
from keras.layers.convolutional import Conv2D, MaxPooling2D, ZeroPadding2D
from keras.optimizers import SGD
import cv2, numpy as np


def VGG_16(weights_path=None):
    model = Sequential()
    model.add(ZeroPadding2D((1,1), input_shape=(224, 224, 3), data_format='channels_last'))
    model.add(Conv2D(64, kernel_size=(3, 3), strides=1, activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(64, kernel_size=(3, 3), strides=1, activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2), data_format='channels_last'))

    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(128, kernel_size=(3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(128, kernel_size=(3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2), data_format='channels_last'))

    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, kernel_size=(3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, kernel_size=(3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(256, kernel_size=(3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2), data_format='channels_last'))

    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, kernel_size=(3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, kernel_size=(3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, kernel_size=(3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2), data_format='channels_last'))

    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, kernel_size=(3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, kernel_size=(3, 3), activation='relu'))
    model.add(ZeroPadding2D((1,1)))
    model.add(Conv2D(512, kernel_size=(3, 3), activation='relu'))
    model.add(MaxPooling2D((2,2), strides=(2,2), data_format='channels_last'))

    model.add(Flatten())
    model.add(Dense(4096, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(4096, activation='relu'))
    model.add(Dropout(0.5))
    model.add(Dense(1000, activation='softmax'))

    if weights_path:
        model.load_weights(weights_path)

    return model

if __name__ == "__main__":
    from keras.applications.vgg16 import decode_predictions
    im = cv2.resize(cv2.imread('karisik_meyveler.jpg'), (224, 224)).astype(np.float32)
    im[:,:,0] -= 103.939
    im[:,:,1] -= 116.779
    im[:,:,2] -= 123.68
    im = im.transpose((1,0,2))
    im = np.expand_dims(im, axis=0)

    # Test pretrained model
    model = VGG_16('vgg16_weights_tf_dim_ordering_tf_kernels.h5')
    sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
    model.compile(optimizer=sgd, loss='categorical_crossentropy')
    out = model.predict(im)
    predictions = decode_predictions(out)

错误弹出;

UnknownError Traceback (most recent call last)
<ipython-input-1-9b64406a16ce> in <module>()
     69     sgd = SGD(lr=0.1, decay=1e-6, momentum=0.9, nesterov=True)
     70     model.compile(optimizer=sgd, loss='categorical_crossentropy')
---> 71     out = model.predict(im)
     72     predictions = decode_predictions(out)

1 个答案:

答案 0 :(得分:0)

解决方案:检查NVIDIA驱动程序的更新并进行更新。