尝试导入 tensorflow GPU 时出错

error when trying to import tensorflow GPU

这是我用来检查 tf.gpu 是否正常工作的代码

import tensorflow as tf 
if tf.test.gpu_device_name(): 
    print('Default GPU Device:{}'.format(tf.test.gpu_device_name()))
else:
   print("Please install GPU version of TF")

这是错误

Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/errors
for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
2020-11-22 21:53:40.971514: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-11-22 21:53:40.971756: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

要在 Tensorflow 上使用 GPU,您必须安装 Tensorflow 的 gpu 版本

python -m pip install tensorflow-gpu

确保您也使用 64 位版本的 python,因为它只能使用这些参数。

编辑:

从 Tensorflow 2.0+ 开始,CPU 和 GPU 版本的 Tensorflow 已经打包在一起。

要让 Tensorflow 与您的 GPU 一起工作,您需要下载 cuDNN。根据您的 CUDA 版本,您需要将一些头文件和一些 dll 文件放在您安装 CUDA 的文件位置。