Mas*_*nya 3 gpu machine-learning anaconda keras tensorflow
我的计算机安装了以下软件:Anaconda (3)、TensorFlow (GPU) 和 Keras。Anaconda 虚拟环境有两种,一种是 TensorFlow for Python 2.7,一种是 3.5,都是 GPU 版本,按照 TF 指令安装。(我之前在单独的环境中安装了 CPU 版本的 TensorFlow,但我已将其删除。)
当我运行以下命令时:
source activate tensorflow-gpu-3.5
python code.py
Run Code Online (Sandbox Code Playgroud)
并检查nvidia-smi它仅显示 Python 的 GPU 内存使用量为 3MiB,因此看起来 GPU 并未用于计算。(code.py是一个用 Keras 实现的简单深度 Q 学习算法)
有什么想法可能会出问题吗?
Windows 上的 TensorFlow
我花了几个小时才修复 Windows 上的 TensorFlow 安装问题,所以总结如下:
检查 TensorFlow-gpu 是否正常工作(使用此代码):
with tf.device('/gpu:0'):
a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
with tf.Session() as sess:
print(sess.run(c))
Run Code Online (Sandbox Code Playgroud)
要检查可用 CPU 或 GPU 的列表(使用此代码):
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
if tf.test.gpu_device_name():
print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
print("Please install GPU version of TF")
Run Code Online (Sandbox Code Playgroud)
使用 CUDA 和 cuDNN 在 Windows 上安装 Tensorflow GPU
指南概述
指南完整详细信息
确保
希望这有帮助:))