TensorFlow2.x报错Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED解决方法

报错内容:

2021-05-17 00:00:13.698656: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
2021-05-17 00:00:13.699083: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
2021-05-17 00:00:13.699229: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
2021-05-17 00:00:13.699579: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_ALLOC_FAILED
Traceback (most recent call last):
File “C:/Users/Administrator/Desktop/style_transfer/123.py”, line 104, in
images = hub_module(tf.constant(content_img), tf.constant(style_image))[0]
File “C:\Anaconda\lib\site-packages\tensorflow\python\saved_model\load.py”, line 486, in _call_attribute
return instance.call(*args, **kwargs)
File “C:\Anaconda\lib\site-packages\tensorflow\python\eager\function.py”, line 1605, in call
return self._call_impl(args, kwargs)
File “C:\Anaconda\lib\site-packages\tensorflow\python\eager\function.py”, line 1645, in _call_impl
return self._call_flat(args, self.captured_inputs, cancellation_manager)
File “C:\Anaconda\lib\site-packages\tensorflow\python\saved_model\load.py”, line 100, in _call_flat
return super(_WrapperFunction, self)._call_flat(args, captured_inputs,
File “C:\Anaconda\lib\site-packages\tensorflow\python\eager\function.py”, line 1745, in _call_flat
return self._build_call_outputs(self._inference_function.call(
File “C:\Anaconda\lib\site-packages\tensorflow\python\eager\function.py”, line 593, in call
outputs = execute.execute(
File “C:\Anaconda\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.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 transformer/contract/conv1/Conv2D (defined at C:\Anaconda\lib\site-packages\tensorflow_hub\module_v2.py:106) ]] [Op:__inference_pruned_1903]

Function call stack:
pruned

Process finished with exit code 1

报错原因:

cuDNN初始化失败,这是由于无法获取卷积算法造成的

解决方法:

复制以下3行代码到程序的开始即可:

physical_devices = tf.config.experimental.list_physical_devices('GPU')
assert len(physical_devices) > 0, "Not enough GPU hardware devices available"
tf.config.experimental.set_memory_growth(physical_devices[0], True)

如果文章解决您多年未解之谜,请一键三连!

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DK数据工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值