我想它应该和with tf.device("/gpu:0")
一起使用,但是我应该把它放在哪里呢?我不认为是:
with tf.device("/gpu:0"):
tf.app.run()
所以我应该把它放在tf.app
函数的main()
函数中,还是放在我用来做估计器的模型函数中?
编辑:如果这有帮助,这是我的main()
函数:
def main(unused_argv):
"""Code to load training folds data pickle or generate one if not present"""
# Create the Estimator
mnist_classifier = tf.estimator.Estimator(
model_fn=cnn_model_fn2, model_dir="F:/python_machine_learning_codes/tmp/custom_age_adience_1")
# Set up logging for predictions
# Log the values in the "Softmax" tensor with label "probabilities"
tensors_to_log = {"probabilities": "softmax_tensor"}
logging_hook = tf.train.LoggingTensorHook(
tensors=tensors_to_log, every_n_iter=100)
# Train the model
train_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": train_data},
y=train_labels,
batch_size=64,
num_epochs=None,
shuffle=True)
mnist_classifier.train(
input_fn=train_input_fn,
steps=500,
hooks=[logging_hook])
# Evaluate the model and print results
"""Code to load eval fold data pickle or generate one if not present"""
eval_logs = {"probabilities": "softmax_tensor"}
eval_hook = tf.train.LoggingTensorHook(
tensors=eval_logs, every_n_iter=100)
eval_input_fn = tf.estimator.inputs.numpy_input_fn(
x={"x": eval_data},
y=eval_labels,
num_epochs=1,
shuffle=False)
eval_results = mnist_classifier.evaluate(input_fn=eval_input_fn, hooks=[eval_hook])
如您所见,这里没有会话的显式声明,那么我到底应该将with tf.device("/gpu:0")
放在哪里呢?
我想知道使用
tf.contrib.distribute
来指定设备放置策略是否有效。您可以将其放在模型函数的开头,即定义模型时,应编写:
不过,我希望tensorflow会自动为您的模型使用gpu。您可能需要检查是否正确检测到它:
有了估计器
也不是说
所以…不幸的是,tensorflow web中没有完整的文档。 我在尝试RunConfig的不同选项
试着处理这个…实际上我正在处理你的任务,如果我有进展,我会把它贴在这里。
请看这里: https://github.com/tensorflow/models/blob/master/official/wide_deep/wide_deep.py 在本例中,他们将上面显示的代码与.replace语句一起使用,以确保模型在CPU上运行。
相关问题 更多 >
编程相关推荐