8

で使うはずだったwith tf.device("/gpu:0")のですが、どこに置くのですか?私はそれがだとは思わない:

with tf.device("/gpu:0"):
    tf.app.run()

main()では、それを の関数tf.app、または推定器に使用するモデル関数に入れる必要がありますか?

編集:これが役立つ場合、これは私の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")

4

3 に答える 3

0

tf.contrib.distributeを使用してデバイス配置戦略を指定できるかどうか疑問に思いました。

def main(unused_argv):
    """Code to load training folds data pickle or generate one if not present"""

    strategy = tf.contrib.distribute.OneDeviceStrategy(device='/gpu:0')
    config = tf.estimator.RunConfig(train_distribute=strategy)

    # Create the Estimator
    mnist_classifier = tf.estimator.Estimator(
        model_fn=cnn_model_fn2,
        config=config,
        model_dir="F:/python_machine_learning_codes/tmp/custom_age_adience_1")

    ......
于 2018-11-10T09:55:59.840 に答える