未知错误:无法获取卷积算法

UnknownError: Failed to get convolution algorithm(未知错误:无法获取卷积算法)

本文介绍了未知错误:无法获取卷积算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完全错误:

未知错误:无法获取卷积算法。这可能是 因为cuDNN初始化失败,所以请尝试查看是否有警告 上面打印了日志消息。[OP:Conv2D]

软件包安装命令:

conda install -c anaconda keras-gpu

它已安装:

  • 张力板2.0.0 pyhb38c66f_1
  • TensorFlow 2.0.0 GPU_py37h57d29ca_0
  • TensorFlow-BASE 2.0.0 GPU_py37h390e234_0
  • TensorFlow-Estiator 2.0.0 pyh2649769_0
  • TensorFlow-GPU 2.0.0 h0d30ee6_0蟒蛇
  • cudatoolkit 10.0.130 0
  • cudnn 7.6.5 cuda10.0_0
  • Keras-Applications 1.0.8 py_0
  • keras-base 2.2.4py37_0
  • Keras-GPU 2.2.4 0蟒蛇
  • keras-预处理1.1.0py_1

我已尝试从NVIDIA网站安装CUDA-TOOLKIT,但没有解决问题,因此建议与CONDA命令相关。

一些博客建议安装Visual Studio,但是如果我有Spyder IDE,有什么需要吗?

编码:

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Convolution2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dense

classifier = Sequential()

classifier.add(Convolution2D(32, 3, 3, input_shape = (64, 64, 3), activation = 'relu'))

classifier.add(MaxPooling2D(pool_size = (2, 2)))

classifier.add(Convolution2D(32, 3, 3, activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))

classifier.add(Flatten())

classifier.add(Dense(units = 128, activation = 'relu'))
classifier.add(Dense(units = 1, activation = 'sigmoid'))

classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])

from tensorflow.keras.preprocessing.image import ImageDataGenerator

train_datagen = ImageDataGenerator(rescale = 1./255,
                                   shear_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255)

training_set = train_datagen.flow_from_directory('dataset/training_set',
                                                 target_size = (64, 64),
                                                 batch_size = 4,
                                                 class_mode = 'binary')

test_set = test_datagen.flow_from_directory('dataset/test_set',
                                            target_size = (64, 64),
                                            batch_size = 4,
                                            class_mode = 'binary')

classifier.fit_generator(training_set,
                         steps_per_epoch = 8000,
                         epochs = 25,
                         validation_data = test_set,
                         validation_steps = 2000)

执行下面的代码后,我收到错误:

classifier.fit_generator(training_set,
                             steps_per_epoch = 8000,
                             epochs = 25,
                             validation_data = test_set,
                             validation_steps = 2000)

编辑1:回溯

Traceback (most recent call last):

  File "D:Machine LearningMachine Learning A-Z Template FolderPart 8 - Deep LearningSection 40 - Convolutional Neural Networks (CNN)cnn.py", line 70, in <module>
    validation_steps = 2000)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine	raining.py", line 1297, in fit_generator
    steps_name='steps_per_epoch')

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine	raining_generator.py", line 265, in model_iteration
    batch_outs = batch_function(*batch_data)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine	raining.py", line 973, in train_on_batch
    class_weight=class_weight, reset_metrics=reset_metrics)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine	raining_v2_utils.py", line 264, in train_on_batch
    output_loss_metrics=model._output_loss_metrics)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine	raining_eager.py", line 311, in train_on_batch
    output_loss_metrics=output_loss_metrics))

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine	raining_eager.py", line 252, in _process_single_batch
    training=training))

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine	raining_eager.py", line 127, in _model_loss
    outs = model(inputs, **kwargs)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasenginease_layer.py", line 891, in __call__
    outputs = self.call(cast_inputs, *args, **kwargs)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasenginesequential.py", line 256, in call
    return super(Sequential, self).call(inputs, training=training, mask=mask)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine
etwork.py", line 708, in call
    convert_kwargs_to_constants=base_layer_utils.call_context().saving)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasengine
etwork.py", line 860, in _run_internal_graph
    output_tensors = layer(computed_tensors, **kwargs)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkerasenginease_layer.py", line 891, in __call__
    outputs = self.call(cast_inputs, *args, **kwargs)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonkeraslayersconvolutional.py", line 197, in call
    outputs = self._convolution_op(inputs, self.kernel)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonops
n_ops.py", line 1134, in __call__
    return self.conv_op(inp, filter)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonops
n_ops.py", line 639, in __call__
    return self.call(inp, filter)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonops
n_ops.py", line 238, in __call__
    name=self.name)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonops
n_ops.py", line 2010, in conv2d
    name=name)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonopsgen_nn_ops.py", line 1031, in conv2d
    data_format=data_format, dilations=dilations, name=name, ctx=_ctx)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythonopsgen_nn_ops.py", line 1130, in conv2d_eager_fallback
    ctx=_ctx, name=name)

  File "C:AnacondaenvsMLlibsite-packages	ensorflow_corepythoneagerexecute.py", line 67, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)

  File "<string>", line 3, in raise_from

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. [Op:Conv2D]

推荐答案

以下代码解决了该问题:

import tensorflow as tf
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
    try:
        for gpu in gpus:
            tf.config.experimental.set_memory_growth(gpu, True)

    except RuntimeError as e:
        print(e)

这篇关于未知错误:无法获取卷积算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:未知错误:无法获取卷积算法

基础教程推荐