tensorflow - 以编程方式获取 Tensorflow 操作的设备布局

标签 tensorflow

我想编写一个断言,以确保我的图中的某些操作将在特定设备上运行。如何以编程方式确定操作的设备布局,以便我可以编写这样的断言?

最佳答案

您可以使用

确保操作在特定设备上运行
with tf.device('/gpu:0'):

在操作定义之前(有关详细信息,请参阅 here)。

编辑:

每个可用的 GPU 都有自己的索引:“/gpu:0”、“/gpu:1”、“/gpu:2”等。这样您就可以将特定操作绑定(bind)到特定 GPU。当您导入tensorflow时,它会打印出哪些GPU可用以及它们分配的索引。

(例如,它打印:创建 TensorFlow 设备 (/gpu:0) -> (设备: 0, 名称: GeForce GTX 1070, pci 总线 id: ...))

关于tensorflow - 以编程方式获取 Tensorflow 操作的设备布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43171456/

相关文章:

tensorflow - 带有 Tensorflow 后端的 Keras 的 K.function 方法是否适用于网络层?

python - 如何将不带引号的字符串转换为python中的字典

machine-learning - 无法访问 TensorFlow Adam 优化器命名空间

python - tensorflow 对多个图像进行分类

python - Tensorflow 似乎在使用系统内存而不是 GPU,并且程序在 global_variable_inititializer() 之后停止

tensorflow - 在 Tensorflow 中使用 `tf.estimator.Estimator` 保存的模型进行预测

tensorflow - 训练损失为 Nan - 但训练数据均在范围内且不为空

python - Keras:修复使用 model.fit 时的 "IndexError: list index out of range"错误

python - 类型错误 : concat() got multiple values for argument 'axis'

python - Tensorflow + google ml-engne 本地预测 : How CSV quotes should be processed?