GPU 未被 TensorFlow 捕获
GPU not captured by TensorFlow
我在 Windows 的 Anaconda 虚拟环境中使用 pip install tensorflow
安装了 tensorflow
。
我试过测试GPU是否开启,输入
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
得到了
Num GPUs Available: 0
我的系统确实启用了 CUDA 和 CUDNN,因为我在安装 PyTorch GPU 版本时没有遇到问题。如何为 TensorFlow 启用 GPU?
首先,使用
卸载tensorflow
pip uninstall tensorflow
安装tensorflow-gpu
版本,
pip install tensorflow-gpu==2.2.0
如果使用 pip 不起作用,您可以尝试 conda install command.
conda install -c anaconda tensorflow-gpu
这将自动安装 CUDA & cuDNN.
希望这能解决您的问题。
使用pip uninstall tensorflow
删除cpu版本的tensorflow并安装tensorflow的gpu版本,pip install tensorflow-gpu
。
您也可以查看本教程link。
可以归纳为以下步骤:
- 卸载旧的 tensorflow
- 安装tensorflow-gpu pip安装tensorflow-gpu
- 安装 Nvidia 显卡和驱动程序(您可能已经安装)
- 下载并安装 CUDA
- 下载并安装 cuDNN
- 用你的程序验证。
我在 Windows 的 Anaconda 虚拟环境中使用 pip install tensorflow
安装了 tensorflow
。
我试过测试GPU是否开启,输入
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
得到了
Num GPUs Available: 0
我的系统确实启用了 CUDA 和 CUDNN,因为我在安装 PyTorch GPU 版本时没有遇到问题。如何为 TensorFlow 启用 GPU?
首先,使用
卸载tensorflowpip uninstall tensorflow
安装tensorflow-gpu
版本,
pip install tensorflow-gpu==2.2.0
如果使用 pip 不起作用,您可以尝试 conda install command.
conda install -c anaconda tensorflow-gpu
这将自动安装 CUDA & cuDNN.
希望这能解决您的问题。
使用pip uninstall tensorflow
删除cpu版本的tensorflow并安装tensorflow的gpu版本,pip install tensorflow-gpu
。
您也可以查看本教程link。
可以归纳为以下步骤:
- 卸载旧的 tensorflow
- 安装tensorflow-gpu pip安装tensorflow-gpu
- 安装 Nvidia 显卡和驱动程序(您可能已经安装)
- 下载并安装 CUDA
- 下载并安装 cuDNN
- 用你的程序验证。