Python 如何在GPU上显式运行张量流估计器

Python 如何在GPU上显式运行张量流估计器,python,tensorflow,Python,Tensorflow,我发现,为了在GPU上使用估计器模型,我需要以下代码: # Create a tf.estimator.RunConfig to ensure the model is run on CPU, which # trains faster than GPU for this model. run_config = tf.estimator.RunConfig().replace( session_config=tf.ConfigProto(device_count={'GPU': 0}

我发现,为了在GPU上使用估计器模型,我需要以下代码:

# Create a tf.estimator.RunConfig to ensure the model is run on CPU, which
# trains faster than GPU for this model.
run_config = tf.estimator.RunConfig().replace(
      session_config=tf.ConfigProto(device_count={'GPU': 0},
                                    inter_op_parallelism_threads=inter_op,
intra_op_parallelism_threads=intra_op))
代码来源:

这是正确的吗?因为我犯了错误:

NameError: name 'inter_op' is not defined

UPD:国际米兰应该是什么样的?如何选择它的价值

您需要在使用变量之前定义变量,并将GPU计数设置为非零数

inter_op = 10
intra_op = 10
session_config=tf.ConfigProto(device_count={'GPU': 1},
                              inter_op_parallelism_threads=inter_op,
                              intra_op_parallelism_threads=intra_op))

你需要定义inter_op。它应该是你想要的并行线程数。我知道,但是怎么做呢?它是什么样子的?可能是线程的重复。好吧。第二,我的问题不是完全重复的,因为主要的问题是在GPU上运行,而不是线程变量的含义是什么?它们为什么等于10秒?任务管理器显示,我的GPU使用率仅为2%。看来我的方法不行work@JamesFlash我编辑了我的答案以选择您需要多少GPU。