Esempio n. 1
0
    def __init__(self,
                 checkpoint_path,
                 logits,
                 im_shape,
                 num_channels,
                 ind_to_label,
                 moving_average_decay,
                 batch_size=1):
        """
        checkpoint_path: path to model checkpoint file
        logits is a function taking a tensor -> float array
        logits must take a single tensor argument

        ind_to_label is object such that ind_to_label[ind] = label
        """
        self.im_shape = im_shape
        self.num_channels = num_channels
        self.batch_size = batch_size
        self.g = tf.Graph()
        with self.g.as_default():
            self.sess = tf.Session()
            self.checkpoint_step = checkpoint_path.split('-')[-1]
            self.checkpoint_path = checkpoint_path
            self.images_placeholder = tf.placeholder(
                "float", shape=[im_shape[0], im_shape[1], num_channels])
            self.logits = logits(self.images_placeholder)
            self.saver = utils.get_saver(moving_average_decay,
                                         nontrainable_restore_names="bn_")
            self.ind_to_label = ind_to_label

        # restore the model's parameters
        self.saver.restore(self.sess, checkpoint_path)
def evaluate():
    """Eval captcha model for a number of steps."""
    with tf.Graph().as_default():
        # Get images and labels for captchas
        eval_data = FLAGS.eval_data == 'test'
        images, all_labels = inputs(eval_data=eval_data)
        # split the labels
        print(images)
        labels = tf.split(1, 6, all_labels)

        # Build a Graph that computes the logits predictions from the
        # inference model.
        logits, _ = inference_captcha_mean_subtracted(images, False, False)
        print(logits[0])
        print(labels[0])
        ls = [tf.reshape(label, [FLAGS.batch_size]) for label in labels]
        print(ls)

        # Calculate predictions.
        top_k_ops = [
            tf.nn.in_top_k(logit, label, 1)
            for logit, label in zip(logits, ls)
        ]

        # Restore the moving average version of the learned variables for eval.
        saver = get_saver(MOVING_AVERAGE_DECAY, "bn_")

        # Build the summary operation based on the TF collection of Summaries.
        summary_op = tf.merge_all_summaries()

        graph_def = tf.get_default_graph().as_graph_def()
        summary_writer = tf.train.SummaryWriter(FLAGS.eval_dir,
                                                graph_def=graph_def)

        while True:
            eval_once(saver, summary_writer, top_k_ops, summary_op)
            if FLAGS.run_once:
                break
            time.sleep(FLAGS.eval_interval_secs)
Esempio n. 3
0
    def __init__(self, checkpoint_path, logits, im_shape, num_channels, ind_to_label, moving_average_decay, batch_size=1):
        """
        checkpoint_path: path to model checkpoint file
        logits is a function taking a tensor -> float array
        logits must take a single tensor argument

        ind_to_label is object such that ind_to_label[ind] = label
        """
        self.im_shape = im_shape
        self.num_channels = num_channels
        self.batch_size = batch_size
        self.g = tf.Graph()
        with self.g.as_default():
            self.sess = tf.Session()
            self.checkpoint_step = checkpoint_path.split('-')[-1]
            self.checkpoint_path = checkpoint_path
            self.images_placeholder = tf.placeholder("float", shape=[im_shape[0], im_shape[1], num_channels])
            self.logits = logits(self.images_placeholder)
            self.saver = utils.get_saver(moving_average_decay, nontrainable_restore_names="bn_")
            self.ind_to_label = ind_to_label

        # restore the model's parameters
        self.saver.restore(self.sess, checkpoint_path)
def evaluate():
    """Eval captcha model for a number of steps."""
    with tf.Graph().as_default():
        # Get images and labels for captchas
        eval_data = FLAGS.eval_data == 'test'
        images, all_labels = inputs(eval_data=eval_data)
        # split the labels
        print(images)
        labels = tf.split(1, 6, all_labels)

        # Build a Graph that computes the logits predictions from the
        # inference model.
        logits, _ = inference_captcha_mean_subtracted(images, False, False)
        print(logits[0])
        print(labels[0])
        ls = [tf.reshape(label, [FLAGS.batch_size]) for label in labels]
        print(ls)

        # Calculate predictions.
        top_k_ops = [tf.nn.in_top_k(logit, label, 1) for logit, label in zip(logits, ls)]

        # Restore the moving average version of the learned variables for eval.
        saver = get_saver(MOVING_AVERAGE_DECAY, "bn_")

        # Build the summary operation based on the TF collection of Summaries.
        summary_op = tf.merge_all_summaries()

        graph_def = tf.get_default_graph().as_graph_def()
        summary_writer = tf.train.SummaryWriter(FLAGS.eval_dir,
                                                graph_def=graph_def)

        while True:
            eval_once(saver, summary_writer, top_k_ops, summary_op)
            if FLAGS.run_once:
                break
            time.sleep(FLAGS.eval_interval_secs)