コード例 #1
0
def main(unused_argv=None):
    dataset = ImagenetData(subset=FLAGS.subset)
    assert dataset.data_files()
    if tf.gfile.Exists(FLAGS.eval_dir):
        tf.gfile.DeleteRecursively(FLAGS.eval_dir)
    tf.gfile.MakeDirs(FLAGS.eval_dir)
    FLAGS.dataset_name = 'imagenet'
    FLAGS.num_examples = dataset.num_examples_per_epoch()
    inception_eval.evaluate(dataset)
コード例 #2
0
def main(_):
    # Load dataset
    tf.app.flags.FLAGS.data_dir = '/work/haeusser/data/imagenet/shards'
    dataset = ImagenetData(subset='validation')
    assert dataset.data_files()

    num_labels = dataset.num_classes() + 1
    image_shape = [FLAGS.image_size, FLAGS.image_size, 3]

    graph = tf.Graph()
    with graph.as_default():

        images, labels = image_processing.batch_inputs(
            dataset,
            32,
            train=True,
            num_preprocess_threads=16,
            num_readers=FLAGS.num_readers)

        # Set up semisup model.
        model = semisup.SemisupModel(semisup.architectures.inception_model,
                                     num_labels,
                                     image_shape,
                                     test_in=images)

        # Add moving average variables.
        for var in tf.get_collection('moving_vars'):
            tf.add_to_collection(tf.GraphKeys.MOVING_AVERAGE_VARIABLES, var)
        for var in slim.get_model_variables():
            tf.add_to_collection(tf.GraphKeys.MOVING_AVERAGE_VARIABLES, var)

        # Get prediction tensor from semisup model.
        predictions = tf.argmax(model.test_logit, 1)

        # Accuracy metric for summaries.
        names_to_values, names_to_updates = slim.metrics.aggregate_metric_map({
            'Accuracy':
            slim.metrics.streaming_accuracy(predictions, labels),
        })
        for name, value in names_to_values.iteritems():
            tf.summary.scalar(name, value)

        # Run the actual evaluation loop.
        num_batches = math.ceil(dataset.num_examples_per_epoch() /
                                float(FLAGS.eval_batch_size))

        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True
        slim.evaluation.evaluation_loop(
            master=FLAGS.master,
            checkpoint_dir=FLAGS.logdir,
            logdir=FLAGS.logdir,
            num_evals=num_batches,
            eval_op=names_to_updates.values(),
            eval_interval_secs=FLAGS.eval_interval_secs,
            session_config=config)