NotFoundError: No algorithm worked! when using Conv2D

2023-12-14 17:20

本文主要是介绍NotFoundError: No algorithm worked! when using Conv2D,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

NotFoundError: No algorithm worked! when using Conv2D

文章目录

      • NotFoundError: No algorithm worked! when using Conv2D
        • 报错信息
        • 系统及环境信息
        • 代码
        • 解决方案
        • 分析原因
        • 参考及引用

报错信息

2021-07-27 15:40:41.637309: W tensorflow/core/framework/op_kernel.cc:1763] OP_REQUIRES failed at conv_ops.cc:1106 : Not found: No algorithm worked!
Traceback (most recent call last):
File “E:/app/PyCharm/bigwhite/class11/LeNet-5.py”, line 36, in
model.fit(X_train, y_train, epochs=5000, batch_size=4096)
File “D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\tensorflow\python\keras\engine\training.py”, line 1100, in fit
tmp_logs = self.train_function(iterator)
File “D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\tensorflow\python\eager\def_function.py”, line 828, in call
result = self._call(*args, **kwds)
File “D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\tensorflow\python\eager\def_function.py”, line 888, in _call
return self._stateless_fn(*args, **kwds)
File “D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\tensorflow\python\eager\function.py”, line 2942, in call
return graph_function._call_flat(
File “D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\tensorflow\python\eager\function.py”, line 1918, in _call_flat
return self._build_call_outputs(self._inference_function.call(
File “D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\tensorflow\python\eager\function.py”, line 555, in call
outputs = execute.execute(
File “D:\ProgramData\Anaconda3\envs\py38\lib\site-packages\tensorflow\python\eager\execute.py”, line 59, in quick_execute
tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.NotFoundError: No algorithm worked!
[[node sequential/conv2d/Conv2D (defined at E:/app/PyCharm/bigwhite/class11/LeNet-5.py:36) ]] [Op:__inference_train_function_666]

Function call stack:
train_function

系统及环境信息

OS: Windows 10
TensorFlow version: 2.4.1(gpu)
Python version: 3.8
CUDA/cuDNN version: Cuda is 11.1, cuDNN is 8.0.4
GPU model and memory: GeForce GTX 3060

代码
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import AveragePooling2D
from tensorflow.keras.layers import Flatten(X_train, y_train), (X_test, y_test) = mnist.load_data()X_train = X_train.reshape(60000, 28, 28, 1)/255.0
X_test = X_test.reshape(10000, 28, 28, 1)/255.0y_train = to_categorical(y_train, 10)
y_test = to_categorical(y_test, 10)model = Sequential()
model.add(Conv2D(filters=6, kernel_size=(5, 5), strides=(1, 1), input_shape=(28, 28, 1), padding='valid', activation='relu'))
model.add(AveragePooling2D(pool_size=(2, 2)))
model.add(Conv2D(filters=16, kernel_size=(5, 5), strides=(1, 1), padding='valid', activation='relu'))
model.add(AveragePooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(units=120, activation='relu'))
model.add(Dense(units=84, activation='relu'))
model.add(Dense(units=10, activation='softmax'))model.compile(loss='categorical_crossentropy', optimizer=SGD(lr=0.05), metrics=['accuracy'])
model.fit(X_train, y_train, epochs=5000, batch_size=4096)loss, acc = model.evaluate(X_test, y_test, )print(f"loos:{loss}, acc:{acc}")
解决方案

加入以下代码可解决我的问题:

import tensorflow as tf
physical_devices = tf.config.list_physical_devices('GPU')
tf.config.experimental.set_memory_growth(physical_devices[0], True)

也有一个高赞解决方案,这应该是使用迁移工具升级的代码,实质上也是使用了tensorflow.compat.v1兼容包来提供在TensorFlow 2.x环境中执行1.x的代码,我的TensorFlow2.4.1似乎没有compat:

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSessionconfig = ConfigProto()
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)
分析原因

根据其他人的回答

[1] yasirroni : In my case, this error appears because the memory is full. Try to check nvidia-smi via terminal. In my case, I use cloud server using jupyter. Shutdown all kernels (not only close the file, but shutdown), and restarting solve the issue.

[2] otaviomguerra : A code from other issue helped me to find a way to limit tensorflow GPU memory usage and solved the issue, please see:

the code is:

gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
# Restrict TensorFlow to only allocate 4GB of memory on the first GPU
try:tf.config.experimental.set_virtual_device_configuration(gpus[0],[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=4096)])logical_gpus = tf.config.experimental.list_logical_devices('GPU')print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
except RuntimeError as e:# Virtual devices must be set before GPUs have been initializedprint(e)

用中文解释一下:就是在原有的程序,会在调用tensorflow的时候,立刻使得内存爆满,所以给GPU内存加上一些限制就可以

下图是我原程序运行时,GPU的使用信息,可以看到cuda和GPU内存利用率在一瞬间都接近100%了
GPU-info

参考及引用

stackoverflow : how to solve no algorithm worked keras error
https://github.com/tensorflow/tensorflow/issues/43174

这篇关于NotFoundError: No algorithm worked! when using Conv2D的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/493380

相关文章

【tensorflow 使用错误】tensorflow2.0 过程中出现 Error : Failed to get convolution algorithm

如果在使用 tensorflow 过程中出现 Error : Failed to get convolution algorithm ,这是因为显卡内存被耗尽了。 解决办法: 在代码的开头加入如下两句,动态分配显存 physical_device = tf.config.experimental.list_physical_devices("GPU")tf.config.experiment

Build Min Heap Using Array

Build min-heap using Array. 思路1:首先明白heap的底层implementation就是array,从0开始的parent和left,right的关系为, 如果现在的node index为i,那么parent index就是 (i-1)/2;   left  为2*i+1, right为 2*i+2;          ( i-1 ) / 2

Implement Set using Array.

参考链接:http://faculty.washington.edu/moishe/javademos/ch03%20Code/jss2/ArraySet.java 被Pivotal的面试官给问到了,trick的地方在于remove的那一块,要把最后的元素跟自己remove的元素进行互换,然后count--;还有,自动扩容那块,构造函数需要两个,一个默认的,一个是可以限定side的。然后扩容的时

纪念一下自己的Coursera Princeton Algorithm的课程第一个assignment

今天终于完成了第一个Union-Find的assignment,之前觉得特别的难,可是最后自己也搞定了。而且是100%满分。 自己后来plot了一下自己的分数,也许这就是学习曲线吧。刚开始不会,到后来中期显著提高,但是要到100%,那就要经历更多的波折,甚至是下降都有可能。最后才能达到100%满分。 我觉得最有用的还是下面这段源代码: /*************************

Implement Rand10() Using Rand7()

Given a function rand7 which generates a uniform random integer in the range 1 to 7, write a function rand10 which generates a uniform random integer in the range 1 to 10. Do NOT use system's Math.ra

C# 使用中点查找矩形的角(Find Corners of Rectangle using mid points)

考虑一个矩形 ABCD,我们给出了边 AD 和 BC 中点(分别为 p 和 q)的坐标以及它们的长度 L(AD = BC = L)。现在给定参数,我们需要打印 4 个点 A、B、C 和 D 的坐标。 例子:  输入:p = (1, 0)         q = (1, 2)         L = 2 输出:(0,0),(0,2),(2,2),(2,0) 解释: 打

[Algorithm][综合训练][栈和排序][加减]详细讲解

目录 1.栈和排序1.题目链接2.算法原理详解 && 代码实现 2.加减1.题目链接2.算法原理详解 && 代码实现 1.栈和排序 1.题目链接 栈和排序 2.算法原理详解 && 代码实现 解法:栈 + 贪心 -> 每次尽可能先让当前需要的最大值弹出去vector<int> solve(vector<int>& a) {int n = a.size();vect

[Algorithm][综合训练][四个选项][接雨水]详细讲解

目录 1.四个选项1.题目链接2.算法原理详解 && 代码实现 2.接雨水1.题目链接2.算法原理详解 && 代码实现 1.四个选项 1.题目链接 四个选项 2.算法原理详解 && 代码实现 解法:DFS(暴搜) + 剪枝 + Hash 剪枝: 填某个数的时候,要看看还有没有剩余次数填某个数的时候,符不符合若干题的选项必须相同 #include <iostr

General Algorithm

Y or N Silly Board Game String Sorting Find the smallest char in a string Integer Sorting Pairs Y or N Silly Board Game 2 opponents: A&B. To represent a board by String[] board = ne

Tensorflow 中train和test的batchsize不同时, 如何设置: tf.nn.conv2d_transpose

大家可能都知道, 在tensorflow中, 如果想实现测试时的batchsize大小随意设置, 那么在训练时, 输入的placeholder的shape应该设置为[None, H, W, C]. 具体代码如下所示: # Placeholders for input data and the targetsx_input = tf.placeholder(dtype=tf.float32, s