python - Tensorflow GPU 未使用,但明显可用

标签 python tensorflow keras

我最近使用过

os.environ["CUDA_VISIBLE_DEVICES"]="-1"

禁用我的 GPU 在 tensorflow 中的使用。但是,当我在终端中使用 unset CUDA_VISIBLE_DEVICES 重新启用它时。下次我运行时出现此错误

tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation Conv_1_bn_1/gamma/Initializer/ones: Could not satisfy explicit device specification '' because the node {{colocation_node Conv_1_bn_1/gamma/Initializer/ones}} was colocated with a group of nodes that required incompatible device '/job:localhost/replica:0/task:0/device:GPU:0'. All available devices [/job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0].

Root Member(assigned_device_name_index_=-1 requested_device_name_='/job:localhost/replica:0/task:0/device:GPU:0' assigned_device_name_='/job:localhost/replica:0/task:0/device:CPU:0' resource_device_name_='/device:GPU:0' supported_device_types_=[CPU, XLA_CPU] possible_devices_=[]

我知道我的 GPU 可以从

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

返回

.......

incarnation: 351568001108855942
physical_device_desc: "device: XLA_CPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 5729157120
locality {
  bus_id: 1
  links {
  }
}

我还尝试卸载并重新安装tensorflow和tensorflowgpu。我将非常感谢任何和所有的帮助 - 谢谢。

最佳答案

为了解决这个问题,我现在将这行代码放在顶部

sess = tf.Session(config=tf.ConfigProto(device_count={'GPU': 1}))

从现在开始我只会使用禁用 GPU

{'GPU': 0}

我强烈建议使用它作为 os.environ 的替代品

关于python - Tensorflow GPU 未使用,但明显可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59347961/

相关文章:

python - 以 xticks 为中心的 Pyplot 箱线图

python - 将微秒转换为人类可读的时间

python - 在 Python 中使用数据框值填充预定义字符串?

python - 类型错误 : Value passed to parameter 'a' has DataType not in list of allowed values

python - 运行 keras multi_gpu_model 时预测出错

python - 从 OpenCV 将数据加载到 CNN

python - 如何设置 gunicorn 来查找 flask 应用程序?

python - 如何让这段RL代码获得GPU支持?

tensorflow - TensorFlow 使用什么缓存模型?

machine-learning - Keras:引入批量标准化后 NaN 训练损失