tensorflow - 如何打印和写入"预测"进入文件?

时间:2017-04-01 03:26:32

标签: tensorflow deep-learning

with tf.Graph().as_default():
    .............
    .............
    .............
    image = image_preprocessing_fn(image, eval_image_size, eval_image_size)

    images, labels = tf.train.batch(
        [image, label],
        batch_size=FLAGS.batch_size,
        num_threads=FLAGS.num_preprocessing_threads,
        capacity=5 * FLAGS.batch_size)

    logits, _ = network_fn(images)
    predictions = tf.argmax(logits, 1) ######this predictions!!!!!!!!!!!!!!
    labels = tf.squeeze(labels)

    # Define the metrics:
    names_to_values, names_to_updates = slim.metrics.aggregate_metric_map({
        'Accuracy': slim.metrics.streaming_accuracy(predictions, labels),
        'Predictions': slim.metrics.streaming_precision(predictions, labels),
        'Recall@5': slim.metrics.streaming_recall_at_k(
            logits, labels, 5)
    })

    # Print the summaries to screen.
    for name, value in names_to_values.iteritems():
      summary_name = 'eval/%s' % name
      op = tf.summary.scalar(summary_name, value, collections=[])
      op = tf.Print(op, [value], summary_name)
      tf.add_to_collection(tf.GraphKeys.SUMMARIES, op)

我尝试了很多方法,但是我无法打印或写下预测"。 我想打印模型的测试结果("预测")并将其写入aaa.txt,以及如何?

代码,请参阅:https://github.com/tensorflow/models/blob/master/slim/eval_image_classifier.py

感谢。

0 个答案:

没有答案