如何在Python 3.6 x64中使用TensorFlow GPU版本而不是CPU版本?
import tensorflow as tf
Python正在使用我的CPU进行计算
我可以注意到,因为我有一个错误:
您的CPU支持该TensorFlow二进制文件未编译使用的指令:AVX2
我已经安装了tensorflow和tensorflow gpu。
如何切换到GPU版本?
遵循这个教程Tensorflow GPU我做到了,它工作得很完美。
注意!-安装9.0版!Tensorflow-gpu不支持更新版本
步骤:
pip安装tensorflow gpu
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
如果你有Nvidia,安装tensorflow GPU的“新”方法是使用Anaconda。也适用于Windows。一行。
conda create --name tf_gpu tensorflow-gpu
这是3个命令的快捷方式,如果您愿意,或者您已经有了conda环境,不需要创建一个,您可以单独执行。
>
激活环境conda激活TFGPU
安装tensorflow GPUconda安装tensorflow GPU
您可以使用conda环境。
请按照最新版本的留档中的步骤操作。注意:GPU和CPU功能现在组合在一个单张量流包中
pip install tensorflow
# OLDER VERSIONS pip install tensorflow-gpu
https://www.tensorflow.org/install/gpu
这是安装驱动程序和CUDA(如果需要)的绝佳指南:https://www.quantstart.com/articles/installing-tensorflow-22-on-ubuntu-1804-with-an-nvidia-gpu/