4

我正在尝试理解和调试我的代码。我尝试使用在 GPU 上在 tf2.0/tf.keras 下开发的 CNN 模型进行预测,但得到了那些错误消息。有人可以帮我解决吗?

这是我的环境配置

enviroments:
python 3.6.8
tensorflow-gpu 2.0.0-rc0
nvidia 418.x
CUDA 10.0
cuDNN 7.6+**

和日志文件,

2019-09-28 13:10:59.833892: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10.0
2019-09-28 13:11:00.228025: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2019-09-28 13:11:00.957534: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
2019-09-28 13:11:00.963310: E tensorflow/stream_executor/cuda/cuda_dnn.cc:329] Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
2019-09-28 13:11:00.963416: 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 mobilenetv2_1.00_192/Conv1/Conv2D}}]]
mobilenetv2_1.00_192/block_15_expand_BN/cond/then/_630/Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0=====>GPU Available:  True
=====> 4 Physical GPUs, 1 Logical GPUs

mobilenetv2_1.00_192/block_15_expand_BN/cond/then/_630/Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_15_depthwise_BN/cond/then/_644/Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_15_depthwise_BN/cond/then/_644/Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_15_project_BN/cond/then/_658/Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_15_project_BN/cond/then/_658/Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_16_expand_BN/cond/then/_672/Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_16_expand_BN/cond/then/_672/Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_16_depthwise_BN/cond/then/_686/Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_16_depthwise_BN/cond/then/_686/Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_16_project_BN/cond/then/_700/Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/block_16_project_BN/cond/then/_700/Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/Conv_1_bn/cond/then/_714/Const: (Const): /job:localhost/replica:0/task:0/device:GPU:0
mobilenetv2_1.00_192/Conv_1_bn/cond/then/_714/Const_1: (Const): /job:localhost/replica:0/task:0/device:GPU:0
Traceback (most recent call last):
  File "NSFW_Server.py", line 162, in <module>
    model.predict(initial_tensor)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training.py", line 915, in predict
    use_multiprocessing=use_multiprocessing)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training_arrays.py", line 722, in predict
    callbacks=callbacks)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/training_arrays.py", line 393, in model_iteration
    batch_outs = f(ins_batch)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/backend.py", line 3625, in __call__
    outputs = self._graph_fn(*converted_inputs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 1081, in __call__
    return self._call_impl(args, kwargs)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 1121, in _call_impl
    return self._call_flat(args, self.captured_inputs, cancellation_manager)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 1224, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/function.py", line 511, in call
    ctx=ctx)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/execute.py", line 67, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", 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 mobilenetv2_1.00_192/Conv1/Conv2D (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py:1751) ]] [Op:__inference_keras_scratch_graph_10727]

Function call stack:
keras_scratch_graph

编码

if __name__ == "__main__":

    print("=====>GPU Available: ", tf.test.is_gpu_available())
    tf.debugging.set_log_device_placement(True)

    gpus = tf.config.experimental.list_physical_devices('GPU')
    if gpus:
        try:
            # Currently, memory growth needs to be the same across GPUs

            tf.config.experimental.set_visible_devices(gpus[0], 'GPU')
            tf.config.experimental.set_memory_growth(gpus[0], True)
            logical_gpus = tf.config.experimental.list_logical_devices('GPU')
            print("=====>", len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
        except RuntimeError as e:
            # Memory growth must be set before GPUs have been initialized
            print(e)

    paras_path = "./paras/{}".format(int(2011))
    model = tf.keras.experimental.load_from_saved_model(paras_path)
    initial_tensor = np.zeros((1, INPUT_SHAPE, INPUT_SHAPE, 3))
    model.predict(initial_tensor)
4

3 回答 3

13

您必须检查您是否拥有正确版本的 CUDA + CUDNN + TensorFlow(还要确保您已全部安装)。

下面介绍了一些运行配置的示例(更新TENSORFLOW最新版本)

仅适用于 Windows 用户.dll:由于错误(扩展名不正确),CUDA、CUDNN 和 TF 的某些后期组合可能无法正常工作。要处理该特定情况,请查阅此链接:Tensorflow GPU 无法加载动态库 'cusolver64_10.dll'; dlerror: 未找到 cusolver64_10.dll

  1. Cuda 11.0+ CuDNN 8.0.4+ TensorFlow2.4.0

  2. Cuda 10.1+ CuDNN 7.6.5(通常 > 7.6) + TensorFlow 2.2.0/TensorFlow 2.3.0(TF >=2.1需要 CUDA >= 10.1)

  3. Cuda 10.1+ CuDNN 7.6.5(通常 > 7.6) + TensorFlow 2.1.0(TF >=2.1需要 CUDA >= 10.1)

  4. Cuda 10.0+ CuDNN 7.6.3 + / TensorFlow 1.13// 1.14TensorFlow 2.0

  5. Cuda 9.0+ CuDNN 7.0.5+ TensorFlow1.10

当您安装了不兼容的 TensorFlow/CuDNN 版本时,通常会出现此错误。就我而言,当我尝试将旧版 TensorFlow 与新版 CuDNN 一起使用时,就会出现这种情况。

**如果由于某种原因您收到类似的错误消息(之后没有任何反应):

依赖驱动进行ptx编译

解决方案:安装最新的nvidia驱动

于 2019-09-28T05:58:36.413 回答
0

对于遇到上述错误问题的人(对于Windows平台),我只是通过安装与系统中已安装的CUDA兼容的CuDNN版本来对其进行排序。

    • 要检查 CUDA 版本,请运行NVCC --version.
    • 下载合适的版本后,从 zip 文件中提取文件夹。
    • 转到解压缩文件夹的 bin 文件夹。复制并将cudnn64:7.dll其粘贴到 CUDA 的 bin 文件夹中。就我而言,安装 Cuda 的位置是C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin.
    • 这很可能会解决问题。

我的系统详情:

  1. 视窗 10
  2. CUDA 10.0
  3. TensorFlow 2.0
  4. GPU-英伟达 GTX 1060

我还发现这篇博客在 Windows 10 上安装具有 CUDA 和 GPU 支持的 TensorFlow。非常有用。

于 2021-02-09T08:04:55.683 回答
-1

检查此 TensorFlow GPU 指令页面上适用于您的操作系统的说明。它为我解决了 Ubuntu 16.04.6 LTS 和 Tensorflow 2.0 上的问题

于 2019-10-18T18:27:57.457 回答