CPU和GPU Tensorflow安装 [英] CPU and GPU Tensorflow Installation
问题描述
我对TensorFlow很陌生.
I'm very new with TensorFlow.
我想在CUDA gpu上运行我的代码.因此,在我安装了普通的TensorFlow之后,我已经安装了TensorFlow -gpu.
I want to run my code on my CUDA gpu. So I've installed TensorFlow -gpu, after I've installed normal TensorFlow.
如何告诉Python它需要基于gpu的TensorFlow?
How can I tell Python that it takes gpu based TensorFlow?
推荐答案
如果您安装了tensorflow-gpu,则实际上没有任何理由也需要tensorflow.如果没有gpu,它将直接在cpu上运行.
If you have tensorflow-gpu installed there really isn't any reason to also have tensorflow. Without the presence of a gpu it will just run on cpu anyway.
要具体使用哪个GPU:
To be specific in which GPU you use:
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
可以代替"0"
列出GPU(如果有多个),或者如果要使其在cpu上运行,则可以列出""
.
in place of "0"
you can either list GPUs (if you have multiple), or ""
if you want it to run on cpu.
或者,在会话中指定:
sess = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0}))
此外,您可以通过打开python控制台并键入以下命令来检查计算机优先使用的版本:
Furthermore you can check which version your computer prioritizes by opening python console and typing:
>>> import tensorflow
>>> tensorflow
<module 'tensorflow' from
'/home/.../python3.6/site- packages/tensorflow/__init__.py'>
^
|
here
这篇关于CPU和GPU Tensorflow安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!