Ejemplo n.º 1
0
def validate_network(sess):

    with tf.name_scope('validation'):
        images, masks = list_files(FLAGS.valid)
        dataset = create_dataset(image_files=images,
                                 mask_files=masks,
                                 batch_size=32)
        iterator = dataset.make_initializable_iterator()
        images, masks = iterator.get_next()
        tensors = build_network(name=FLAGS.name,
                                reuse=True,
                                train=False,
                                images=images,
                                masks=masks,
                                iou=True)

    def validate_fn():
        sess.run(iterator.initializer)
        while True:
            try:
                sess.run(tensors.update_iou)
            except tf.errors.OutOfRangeError:
                break
        iou_val = sess.run(tensors.mean_iou)
        return iou_val

    return validate_fn
Ejemplo n.º 2
0
def score_networks(sess):
    with tf.name_scope('score'):
        follow_dataset = score_dataset('following_images')
        target_dataset = score_dataset('patrol_with_targ')
        image_files = os.path.join(FLAGS.evaluate, '*/images/*.jpeg')
        mask_files = os.path.join(FLAGS.evaluate, '*/masks/*.png')
        image_files, mask_files = glob_list_dir(image_files, mask_files)
        concat_dataset = create_dataset(image_files,
                                        mask_files,
                                        batch_size=32,
                                        mask_fmt='png')

    follow_fn = score_network('follow', sess, follow_dataset)
    target_fn = score_network('target', sess, target_dataset)
    concat_fn = score_network('concat', sess, concat_dataset)

    def score_fn():
        target_iou = target_fn()
        follow_iou = follow_fn()
        print('iou:', follow_iou, target_iou)
        final_iou = (follow_fn() + target_fn()) / 2
        weight = concat_fn()
        return final_iou, weight

    return score_fn
Ejemplo n.º 3
0
def score_dataset(name):
    path = os.path.join(FLAGS.evaluate, name)
    images, masks = list_files(path)
    dataset = create_dataset(image_files=images,
                             mask_files=masks,
                             is_train=False,
                             batch_size=32)
    return dataset
Ejemplo n.º 4
0
def score_datasets():
    follow_dataset = score_dataset('following_images')
    target_dataset = score_dataset('patrol_with_targ')
    image_files = os.path.join(FLAGS.evaluate, '*/images/*.jpeg')
    mask_files = os.path.join(FLAGS.evaluate, '*/masks/*.png')
    image_files, mask_files = glob_list_dir(image_files, mask_files)
    concat_dataset = create_dataset(image_files,
                                    mask_files,
                                    batch_size=32,
                                    mask_fmt='png')

    return follow_dataset, target_dataset, concat_dataset
Ejemplo n.º 5
0
def train_network(sess):
    images, masks = list_files(FLAGS.train)
    dataset = create_dataset(image_files=images,
                             mask_files=masks,
                             is_train=True)
    iterator = dataset.make_initializable_iterator()
    images, masks = iterator.get_next()

    with tf.name_scope('train'):
        tensors = build_network(FLAGS.name,
                                images=images,
                                masks=masks,
                                train=True,
                                iou=True)

    def train_fun(epoch):
        total_loss, counter = 0, 0
        sess.run(iterator.initializer)
        while True:
            try:
                loss, _, _ = sess.run(
                    [tensors.loss, tensors.train_op, tensors.update_iou])
                total_loss += loss
                counter += 1
                if counter % 10 == 0:
                    train_iou = sess.run(tensors.mean_iou)
                    log_info('[%s] %d samples processed, loss [%f] iou [%f]' %
                             (timestamp(), counter * FLAGS.batch_size,
                              total_loss / counter, train_iou))
            except tf.errors.OutOfRangeError:
                break
        train_iou = sess.run(tensors.mean_iou)
        average_loss = total_loss / counter
        log_info('[%s] epoch [%d] training completed' % (timestamp(), epoch))
        return train_iou, average_loss

    return train_fun