【问题标题】:error when trying to import tensorflow GPU尝试导入 tensorflow GPU 时出错
【发布时间】:2020-11-22 20:03:52
【问题描述】:

这是我用来检查 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


    【解决方案1】:

    要使用 GPU 和 Tensorflow,您必须安装 GPU 版本的 Tensorflow

    python -m pip install tensorflow-gpu

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

    编辑:

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

    要让 Tensorflow 与您的 GPU 配合使用,您需要下载 cuDNN。根据您拥有的 CUDA 版本,您需要在安装 CUDA 的文件位置放置一些头文件和一些 dll 文件。

    【讨论】:

    • 如果您使用的是 tensorflow 2.0 或更高版本,您只需要安装 tensorflow。它会自动安装 CPU 和 GPU 模块。
    • @GerryP 我很抱歉,我忘记了 Tensorflow 现在打包了它们。我会相应地编辑我的答案。
    猜你喜欢
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    • 2019-09-29
    • 2021-10-21
    相关资源
    最近更新 更多