gpt4 book ai didi

python - 未知错误 : Failed to get convolution algorithm

转载 作者:行者123 更新时间:2023-12-05 02:09:26 26 4
gpt4 key购买 nike

完整错误:

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]

用于包安装的命令:

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-estimator 2.0.0 pyh2649769_0
  • tensorflow-gpu 2.0.0 h0d30ee6_0 python
  • cudatoolkit 10.0.130 0
  • cudnn 7.6.5 cuda10.0_0
  • keras-应用程序 1.0.8 py_0
  • keras-base 2.2.4 py37_0
  • keras-gpu 2.2.4 0 python
  • keras 预处理 1.1.0 py_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 Learning\Machine Learning A-Z Template Folder\Part 8 - Deep Learning\Section 40 - Convolutional Neural Networks (CNN)\cnn.py", line 70, in <module>
validation_steps = 2000)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 1297, in fit_generator
steps_name='steps_per_epoch')

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\training_generator.py", line 265, in model_iteration
batch_outs = batch_function(*batch_data)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 973, in train_on_batch
class_weight=class_weight, reset_metrics=reset_metrics)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py", line 264, in train_on_batch
output_loss_metrics=model._output_loss_metrics)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py", line 311, in train_on_batch
output_loss_metrics=output_loss_metrics))

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py", line 252, in _process_single_batch
training=training))

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py", line 127, in _model_loss
outs = model(inputs, **kwargs)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
outputs = self.call(cast_inputs, *args, **kwargs)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\sequential.py", line 256, in call
return super(Sequential, self).call(inputs, training=training, mask=mask)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 708, in call
convert_kwargs_to_constants=base_layer_utils.call_context().saving)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 860, in _run_internal_graph
output_tensors = layer(computed_tensors, **kwargs)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
outputs = self.call(cast_inputs, *args, **kwargs)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\keras\layers\convolutional.py", line 197, in call
outputs = self._convolution_op(inputs, self.kernel)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 1134, in __call__
return self.conv_op(inp, filter)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 639, in __call__
return self.call(inp, filter)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 238, in __call__
name=self.name)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 2010, in conv2d
name=name)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\ops\gen_nn_ops.py", line 1031, in conv2d
data_format=data_format, dilations=dilations, name=name, ctx=_ctx)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\ops\gen_nn_ops.py", line 1130, in conv2d_eager_fallback
ctx=_ctx, name=name)

File "C:\Anaconda\envs\ML\lib\site-packages\tensorflow_core\python\eager\execute.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)

关于python - 未知错误 : Failed to get convolution algorithm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59873568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com