tensorflow - 如何在tensorflow中设置特定的gpu?

标签 tensorflow tensorflow-gpu

我想指定 gpu 来运行我的进程。我将其设置如下:

import tensorflow as tf
with tf.device('/gpu:0'):
    a = tf.constant(3.0)
with tf.Session() as sess:
    while True:
        print sess.run(a)

但是它仍然在我的两个 gpu 中分配内存。
|    0      7479    C   python                         5437MiB 
|    1      7479    C   python                         5437MiB 

最佳答案

相信你需要设置CUDA_VISIBLE_DEVICES=1 .或者你想使用哪个 GPU。如果你只让一个 GPU 可见,你将把它称为 /gpu:0在 tensorflow 中,无论您将环境变量设置为什么。

有关该环境变量的更多信息:https://devblogs.nvidia.com/cuda-pro-tip-control-gpu-visibility-cuda_visible_devices/

关于tensorflow - 如何在tensorflow中设置特定的gpu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40069883/

相关文章:

tensorflow - tensorflow 中的索引比收集慢

macos - tensorflow Mac OS GPU支持

tensorflow - 分布式 Tensorflow : check failed: size>=0

c++ - 如何将 OpenCV Mat 设置为 Tensorflow Lite 输入和输出?

python - 为什么 Tensorflow 无法计算 reshape 参数的梯度?

python - tensorflow 2.0.0 : AttributeError: 'TensorSliceDataset' object has no attribute 'as_numpy_iterator'

python - 为什么tensorflow的max_pooling2d需要rank 4的输入?

python - Tensorflow/Keras 意思是图像减法

tensorflow-gpu - 在 Tensorflow 对象检测 API 中定义 GPU 选项

tensorflow - 了解 ResourceExhaustedError : OOM when allocating tensor with shape