Exemple #1
0
def do_eval(sess):
    """Runs one evaluation against the full epoch of data.

  Args:
    sess: The session in which the model has been trained.
    eval_correct: The Tensor that returns the number of correct predictions.
 
  """
    left_batch_eval, right_batch_eval, lidar_batch_eval = simladar.inputs(
        eval_data=True)
    logits_eval = simladar.inference(left_batch_eval, right_batch_eval)
    loss_eval = simladar.eval_loss(logits_eval, lidar_batch_eval)

    # And run one epoch of eval.
    rmse = sess.run(loss_eval)
    return rmse
Exemple #2
0
def evaluate():
    """Eval CIFAR-10 for a number of steps."""
    # with tf.Graph().as_default(),tf.device('/cpu:0') as g:
    with tf.device('/cpu:0') as g:

        global_step = tf.Variable(0, trainable=False)
        # # Get images and labels for CIFAR-10.
        # eval_data = FLAGS.eval_data == 'test'
        # images, labels = cifar10.inputs(eval_data=eval_data)

        left_batch_validate, right_batch_validate, lidar_batch_validate = simladar.inputs(
            eval_data=True)

        # Build a Graph that computes the logits predictions from the
        # inference model.
        # logits = cifar10.inference(images)

        keep_prob = tf.constant(1.)  #dropout (keep probability)

        pred_validate = simladar.inference(left_batch_validate,
                                           right_batch_validate, keep_prob)

        # Calculate predictions.
        # top_k_op = tf.nn.in_top_k(logits, labels, 1)
        valid_op = tf.sqrt(
            tf.reduce_mean(
                tf.square(tf.sub(lidar_batch_validate, pred_validate))))

        # Restore the moving average version of the learned variables for eval.
        variable_averages = tf.train.ExponentialMovingAverage(
            simladar.MOVING_AVERAGE_DECAY)
        variables_to_restore = variable_averages.variables_to_restore()
        saver = tf.train.Saver(variables_to_restore)

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

        summary_writer = tf.train.SummaryWriter(FLAGS.eval_dir, g)

        while True:
            eval_once(saver, summary_writer, valid_op, summary_op)
            if FLAGS.run_once:
                break
            time.sleep(FLAGS.eval_interval_secs)
Exemple #3
0
def train():
    """Train CIFAR-10 for a number of steps."""
    with tf.Graph().as_default():
        global_step = tf.Variable(0, trainable=False)

        # Get images and labels .
        left_batch, right_batch, lidar_batch = simladar.inputs()

        # Build a Graph that computes the logits predictions from the
        # inference model.
        logits = simladar.inference(left_batch, right_batch)

        # Calculate loss.
        loss = simladar.loss(logits, lidar_batch)

        # Build a Graph that trains the model with one batch of examples and
        # updates the model parameters.
        train_op = simladar.train(loss, global_step)

        # Create a saver.
        saver = tf.train.Saver(tf.all_variables())

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

        # Build an initialization operation to run below.
        init = tf.initialize_all_variables()

        # Start running operations on the Graph.
        sess = tf.Session(config=tf.ConfigProto(
            log_device_placement=FLAGS.log_device_placement))
        sess.run(init)

        # Start the queue runners.
        tf.train.start_queue_runners(sess=sess)

        summary_writer = tf.train.SummaryWriter(FLAGS.train_dir, sess.graph)

        for step in xrange(FLAGS.max_steps):
            start_time = time.time()
            _, loss_value = sess.run([train_op, loss])
            duration = time.time() - start_time

            assert not np.isnan(loss_value), 'Model diverged with loss = NaN'

            if step % 10 == 0:
                num_examples_per_step = FLAGS.batch_size
                examples_per_sec = num_examples_per_step / duration
                sec_per_batch = float(duration)

                format_str = (
                    '%s: step %d, loss = %.2f (%.1f examples/sec; %.3f '
                    'sec/batch)')
                print(format_str % (datetime.now(), step, loss_value,
                                    examples_per_sec, sec_per_batch))

            if step % 100 == 0:
                # eval_rmse = do_eval(sess)
                # print('eval rmse: ',eval_rmse )
                summary_str = sess.run(summary_op)
                summary_writer.add_summary(summary_str, step)

            # Save the model checkpoint periodically.
            if step % 1000 == 0 or (step + 1) == FLAGS.max_steps:
                checkpoint_path = os.path.join(FLAGS.train_dir, 'model.ckpt')
                saver.save(sess, checkpoint_path, global_step=step)
def train():
    """Train CIFAR-10 for a number of steps."""
    with tf.Graph().as_default():
        global_step = tf.Variable(0, trainable=False)

        # Get images and labels .
        left_batch, right_batch, lidar_batch = simladar.inputs()
        keep_prob = tf.constant(DROPOUT_PROB)  #dropout (keep probability)

        # Build a Graph that computes the logits predictions from the
        # inference model.
        logits = simladar.inference(left_batch, right_batch, keep_prob)

        # Calculate loss.
        loss = simladar.loss(logits, lidar_batch)

        # Build a Graph that trains the model with one batch of examples and
        # updates the model parameters.
        train_op = simladar.train(loss, global_step)

        # Create a saver.
        saver = tf.train.Saver(tf.global_variables())

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

        # Build an initialization operation to run below.
        init = tf.global_variables_initializer()

        # Start running operations on the Graph.
        config = tf.ConfigProto()
        config.gpu_options.allow_growth = True
        config.log_device_placement = FLAGS.log_device_placement
        sess = tf.Session(config=config)
        sess.run(init)

        # load model
        checkpoint = tf.train.get_checkpoint_state(FLAGS.save_dir)

        if checkpoint and checkpoint.model_checkpoint_path:
            saver.restore(sess, checkpoint.model_checkpoint_path)
            print("Successfully loaded:", checkpoint.model_checkpoint_path)
            # print("global step: ", global_step.eval())
        else:
            print("Could not find old network weights")

        # Start the queue runners.
        tf.train.start_queue_runners(sess=sess)

        # summary_writer = tf.train.SummaryWriter(FLAGS.save_dir, sess.graph)
        summary_writer = tf.summary.FileWriter(FLAGS.save_dir, sess.graph)
        for step in xrange(FLAGS.max_steps):
            start_time = time.time()
            _, loss_value = sess.run([train_op, loss])
            duration = time.time() - start_time

            assert not np.isnan(loss_value), 'Model diverged with loss = NaN'

            if step % 10 == 0:
                num_examples_per_step = FLAGS.batch_size
                examples_per_sec = num_examples_per_step / duration
                sec_per_batch = float(duration)

                format_str = (
                    '%s: step %d, loss = %.2f (%.1f examples/sec; %.3f '
                    'sec/batch)')
                print(format_str % (datetime.now(), step, loss_value,
                                    examples_per_sec, sec_per_batch))

            if step % 100 == 0:
                # eval_rmse = do_eval(sess)
                # print('eval rmse: ',eval_rmse )
                summary_str = sess.run(summary_op)
                summary_writer.add_summary(summary_str, step)

            # Save the model checkpoint periodically.
            if step % 1000 == 0 or (step + 1) == FLAGS.max_steps:
                checkpoint_path = os.path.join(FLAGS.save_dir, 'model.ckpt')
                saver.save(sess, checkpoint_path, global_step=step)