当前位置: 代码迷 >> 综合 >> UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to解决方案
  详细解决方案

UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to解决方案

热度:53   发布时间:2023-11-21 00:04:51.0

在使用tensorflow-gpu运行神经网络时出现UnknownError: Failed to get convolution algorithm错误。完成错误如下:

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.[[node conv0/conv0/Conv2D (defined at <ipython-input-3-e07526a69867>:55)  = Conv2D[T=DT_FLOAT, data_format="NCHW", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](Reshape, conv0/conv0/kernel/read)]]Caused by op 'conv0/conv0/Conv2D', defined at:File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\runpy.py", line 193, in _run_module_as_main"__main__", mod_spec)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\runpy.py", line 85, in _run_codeexec(code, run_globals)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\ipykernel_launcher.py", line 16, in <module>app.launch_new_instance()File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\traitlets\config\application.py", line 664, in launch_instanceapp.start()File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\ipykernel\kernelapp.py", line 583, in startself.io_loop.start()File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tornado\platform\asyncio.py", line 149, in startself.asyncio_loop.run_forever()File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\asyncio\base_events.py", line 442, in run_foreverself._run_once()File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\asyncio\base_events.py", line 1462, in _run_oncehandle._run()File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\asyncio\events.py", line 145, in _runself._callback(*self._args)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tornado\ioloop.py", line 690, in <lambda>lambda f: self._run_callback(functools.partial(callback, future))File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tornado\ioloop.py", line 743, in _run_callbackret = callback()File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tornado\gen.py", line 787, in innerself.run()File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tornado\gen.py", line 748, in runyielded = self.gen.send(value)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\ipykernel\kernelbase.py", line 361, in process_oneyield gen.maybe_future(dispatch(*args))File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tornado\gen.py", line 209, in wrapperyielded = next(result)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\ipykernel\kernelbase.py", line 268, in dispatch_shellyield gen.maybe_future(handler(stream, idents, msg))File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tornado\gen.py", line 209, in wrapperyielded = next(result)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\ipykernel\kernelbase.py", line 541, in execute_requestuser_expressions, allow_stdin,File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\tornado\gen.py", line 209, in wrapperyielded = next(result)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\ipykernel\ipkernel.py", line 300, in do_executeres = shell.run_cell(code, store_history=store_history, silent=silent)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cellreturn super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\IPython\core\interactiveshell.py", line 2858, in run_cellraw_cell, store_history, silent, shell_futures)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\IPython\core\interactiveshell.py", line 2886, in _run_cellreturn runner(coro)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\IPython\core\async_helpers.py", line 68, in _pseudo_sync_runnercoro.send(None)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\IPython\core\interactiveshell.py", line 3063, in run_cell_asyncinteractivity=interactivity, compiler=compiler, result=result)File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\IPython\core\interactiveshell.py", line 3254, in run_ast_nodesif (await self.run_code(code, result,  async_=asy)):File "D:\Users\lenovo\Anaconda3\envs\tensorflow-gpu\lib\site-packages\IPython\core\interactiveshell.py", line 3331, in run_codeexec(code_obj, self.user_global_ns, self.user_ns)File "<ipython-input-3-e07526a69867>", line 78, in <module>y_ = res_net(x_image, [2, 3, 2], 32, 10)File "<ipython-input-3-e07526a69867>", line 55, in res_netname = 'conv0')File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\layers\convolutional.py", line 417, in conv2dreturn layer.apply(inputs)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\base_layer.py", line 817, in applyreturn self.__call__(inputs, *args, **kwargs)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\layers\base.py", line 374, in __call__outputs = super(Layer, self).__call__(inputs, *args, **kwargs)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\engine\base_layer.py", line 757, in __call__outputs = self.call(inputs, *args, **kwargs)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\keras\layers\convolutional.py", line 194, in calloutputs = self._convolution_op(inputs, self.kernel)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\ops\nn_ops.py", line 868, in __call__return self.conv_op(inp, filter)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\ops\nn_ops.py", line 520, in __call__return self.call(inp, filter)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\ops\nn_ops.py", line 204, in __call__name=self.name)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 1044, in conv2ddata_format=data_format, dilations=dilations, name=name)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helperop_def=op_def)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_funcreturn func(*args, **kwargs)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\ops.py", line 3274, in create_opop_def=op_def)File "C:\Users\lenovo\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\ops.py", line 1770, in __init__self._traceback = tf_stack.extract_stack()

解决方法1:
在代码块中加入如下代码:

from tensorflow import ConfigProto
from tensorflow import InteractiveSessionconfig = ConfigProto()
config.gpu_options.allow_growth = True

并把with tf.Session() as sess:修改为:

with tf.Session(config=config) as sess:

解决方法2:
如果上述方法仍不能解决问题,则在代码块中添加如下代码:

import osos.environ['CUDA_VISIBLE_DEVICES'] = '/gpu:0'
  相关解决方案