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

问题描述 投票:0回答:1

我正在努力学习VGG16模型。但是现在,我得到了一个错误,

使用TensorFlow后端。 UnknownError:无法获得卷积算法。这可能是因为cuDNN无法初始化,因此请尝试查看上面是否打印了警告日志消息。 [[{{node conv2d_1 / convolution}} = 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”](conv2d_1 / convolution-0-TransposeNHWCToNCHW-LayoutOptimizer,conv2d_1 / kernel / read)]] [ [{{node dense_3 / Softmax / _211}} = _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_237_dense_3 / Softmax“,tensor_type = DT_FLOAT,_device =”/ job:localhost / replica:0 / task:0 / device:CPU:0“ ]]

这是我的系统版本,

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

nvcc:NVIDIA(R)Cuda编译器驱动程序版权所有(c)2005-2017 NVIDIA Corporation基于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)
tensorflow keras cudnn
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.