报错内容:
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)
如果文章解决您多年未解之谜,请一键三连!