tensoflow-gpu 2.0 卷积报错:Failed to get convolution algorithm

报错信息如下:

2019-11-12 10:59:51.914183: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
2019-11-12 10:59:51.914268: W tensorflow/core/common_runtime/base_collective_executor.cc:216] BaseCollectiveExecutor::StartAbort Unknown: 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 conv1/convolution}}]]
Traceback (most recent call last):
  File "demo.py", line 134, in <module>
    main()
  File "demo.py", line 117, in main
    results = model.predict(faces)
  File "/home/l/anaconda3/envs/age-gender/lib/python3.6/site-packages/keras/engine/training.py", line 1462, in predict
    callbacks=callbacks)
  File "/home/l/anaconda3/envs/age-gender/lib/python3.6/site-packages/keras/engine/training_arrays.py", line 324, in predict_loop
    batch_outs = f(ins_batch)
  File "/home/l/anaconda3/envs/age-gender/lib/python3.6/site-packages/tensorflow_core/python/keras/backend.py", line 3740, in __call__
    outputs = self._graph_fn(*converted_inputs)
  File "/home/l/anaconda3/envs/age-gender/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1081, in __call__
    return self._call_impl(args, kwargs)
  File "/home/l/anaconda3/envs/age-gender/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1121, in _call_impl
    return self._call_flat(args, self.captured_inputs, cancellation_manager)
  File "/home/l/anaconda3/envs/age-gender/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1224, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager)
  File "/home/l/anaconda3/envs/age-gender/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 511, in call
    ctx=ctx)
  File "/home/l/anaconda3/envs/age-gender/lib/python3.6/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 "", line 3, in raise_from
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 conv1/convolution (defined at /home/l/anaconda3/envs/age-gender/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py:1751) ]] [Op:__inference_keras_scratch_graph_10671]

Function call stack:
keras_scratch_graph

解决方法,在开头增加如下代码:

# 不加这几句,则CONV 报错
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)

你可能感兴趣的:(环境配置)