Beispiel #1
0
def test_authentic_unet(rsr_data_dir,
                        test_data_dir,
                        input_size,
                        model_name,
                        num_classes,
                        ckdir,
                        city,
                        batch_size,
                        ds_name='inria',
                        GPU='0',
                        random_seed=1234):
    import re
    import scipy.misc
    import tensorflow as tf
    from network import unet
    from dataReader import image_reader
    from rsrClassData import rsrClassData

    def name_has_city(city_list, name):
        for city in city_list:
            if city in name:
                return True
        return False

    city = city.split(',')

    # set gpu
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = GPU
    tf.reset_default_graph()
    # environment settings
    np.random.seed(random_seed)
    tf.set_random_seed(random_seed)

    # data prepare step
    Data = rsrClassData(rsr_data_dir)
    (collect_files_test, meta_test) = Data.getCollectionByName(test_data_dir)

    # image reader
    coord = tf.train.Coordinator()

    # define place holder
    X = tf.placeholder(tf.float32,
                       shape=[None, input_size[0], input_size[1], 3],
                       name='X')
    y = tf.placeholder(tf.int32,
                       shape=[None, input_size[0], input_size[1], 1],
                       name='y')
    mode = tf.placeholder(tf.bool, name='mode')

    # initialize model
    model = unet.UnetModel_Origin({
        'X': X,
        'Y': y
    },
                                  trainable=mode,
                                  model_name=model_name,
                                  input_size=input_size)
    model.create_graph('X', num_classes)
    model.make_update_ops('X', 'Y')
    # set ckdir
    model.make_ckdir(ckdir)
    # set up graph and initialize
    config = tf.ConfigProto()

    result_dict = {}

    # run training
    with tf.Session(config=config) as sess:
        init = tf.global_variables_initializer()
        sess.run(init)

        saver = tf.train.Saver(var_list=tf.global_variables(), max_to_keep=1)

        if os.path.exists(model.ckdir) and tf.train.get_checkpoint_state(
                model.ckdir):
            latest_check_point = tf.train.latest_checkpoint(model.ckdir)
            saver.restore(sess, latest_check_point)
            print('loaded model from {}'.format(latest_check_point))

        threads = tf.train.start_queue_runners(coord=coord, sess=sess)
        for (image_name, label_name) in collect_files_test:
            #if city in image_name:
            if name_has_city(city, image_name):
                if ds_name == 'inria':
                    city_name = re.findall('[a-z\-]*(?=[0-9]+\.)',
                                           image_name)[0]
                    tile_id = re.findall('[0-9]+(?=\.tif)', image_name)[0]
                else:
                    city_name = os.path.basename(image_name)[:3]
                    tile_id = os.path.basename(image_name)[9:12]

                # load reader
                iterator_test = image_reader.image_label_iterator(
                    os.path.join(rsr_data_dir, image_name),
                    batch_size=batch_size,
                    tile_dim=meta_test['dim_image'][:2],
                    patch_size=input_size,
                    overlap=184,
                    padding=92)
                # run
                result = model.test('X', sess, iterator_test)
                pred_label_img = get_output_label(
                    result, (meta_test['dim_image'][0] + 184,
                             meta_test['dim_image'][1] + 184),
                    input_size,
                    meta_test['colormap'],
                    overlap=184,
                    output_image_dim=meta_test['dim_image'],
                    output_patch_size=(input_size[0] - 184,
                                       input_size[1] - 184))
                # evaluate
                truth_label_img = scipy.misc.imread(
                    os.path.join(rsr_data_dir, label_name))
                iou = iou_metric(truth_label_img, pred_label_img)
                result_dict['{}{}'.format(city_name, tile_id)] = iou
            coord.request_stop()
            coord.join(threads)
    return result_dict
Beispiel #2
0
def main(flags):
    # set gpu
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = flags.GPU
    # environment settings
    np.random.seed(flags.random_seed)
    tf.set_random_seed(flags.random_seed)

    # data prepare step
    Data = rsrClassData(flags.rsr_data_dir)
    (collect_files_test, meta_test) = Data.getCollectionByName(flags.test_data_dir)

    # image reader
    coord = tf.train.Coordinator()

    # define place holder
    X = tf.placeholder(tf.float32, shape=[None, flags.input_size[0], flags.input_size[1], 3], name='X')
    y = tf.placeholder(tf.int32, shape=[None, flags.input_size[0], flags.input_size[1], 1], name='y')
    mode = tf.placeholder(tf.bool, name='mode')

    # initialize model
    model = unet.UnetModel({'X':X, 'Y':y}, trainable=mode, model_name=flags.model_name, input_size=flags.input_size)
    model.create_graph('X', flags.num_classes)
    model.make_update_ops('X', 'Y')
    # set ckdir
    model.make_ckdir(flags.ckdir)
    # set up graph and initialize
    config = tf.ConfigProto()

    # run training
    start_time = time.time()
    with tf.Session(config=config) as sess:
        init = tf.global_variables_initializer()
        sess.run(init)

        saver = tf.train.Saver(var_list=tf.global_variables(), max_to_keep=1)

        if os.path.exists(model.ckdir) and tf.train.get_checkpoint_state(model.ckdir):
            latest_check_point = tf.train.latest_checkpoint(model.ckdir)
            saver.restore(sess, latest_check_point)

        threads = tf.train.start_queue_runners(coord=coord, sess=sess)
        try:
            for (image_name, label_name) in collect_files_test:
                if flags.city_name in image_name:
                    city_name = re.findall('[a-z\-]*(?=[0-9]+\.)', image_name)[0]
                    tile_id = re.findall('[0-9]+(?=\.tif)', image_name)[0]

                    # load reader
                    iterator_test = image_reader.image_label_iterator(
                        os.path.join(flags.rsr_data_dir, image_name),
                        batch_size=flags.batch_size,
                        tile_dim=meta_test['dim_image'][:2],
                        patch_size=flags.input_size,
                        overlap=0)
                    # run
                    result = model.test('X', sess, iterator_test)
                    pred_label_img = sis_utils.get_output_label(result, meta_test['dim_image'],
                                                                flags.input_size, meta_test['colormap'])
                    # evaluate
                    truth_label_img = scipy.misc.imread(os.path.join(flags.rsr_data_dir, label_name))
                    iou = sis_utils.iou_metric(truth_label_img, pred_label_img)

                    print('{}_{}: iou={:.2f}'.format(city_name, tile_id, iou*100))
        finally:
            coord.request_stop()
            coord.join(threads)

    duration = time.time() - start_time
    print('duration {:.2f} minutes'.format(duration/60))
def main(flags):
    # set gpu
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = flags.GPU
    # environment settings
    np.random.seed(flags.random_seed)
    tf.set_random_seed(flags.random_seed)

    # data prepare step
    Data = rsrClassData(flags.rsr_data_dir)
    (collect_files_test,
     meta_test) = Data.getCollectionByName(flags.test_data_dir)

    # image reader
    coord = tf.train.Coordinator()

    # define place holder
    X = tf.placeholder(
        tf.float32,
        shape=[None, flags.input_size[0], flags.input_size[1], 3],
        name='X')
    y = tf.placeholder(
        tf.int32,
        shape=[None, flags.input_size[0], flags.input_size[1], 1],
        name='y')
    mode = tf.placeholder(tf.bool, name='mode')

    # initialize model
    model = unet.UnetModel({
        'X': X,
        'Y': y
    },
                           trainable=mode,
                           model_name=flags.model_name,
                           input_size=flags.input_size)
    model.create_graph('X', flags.num_classes)
    model.make_update_ops('X', 'Y')
    # set ckdir
    model.make_ckdir(flags.ckdir)
    # set up graph and initialize
    config = tf.ConfigProto()

    # run training
    start_time = time.time()
    with tf.Session(config=config) as sess:
        init = tf.global_variables_initializer()
        sess.run(init)

        saver = tf.train.Saver(var_list=tf.global_variables(), max_to_keep=1)

        if os.path.exists(model.ckdir) and tf.train.get_checkpoint_state(
                model.ckdir):
            print('loading model from {}'.format(model.ckdir))
            latest_check_point = tf.train.latest_checkpoint(model.ckdir)
            saver.restore(sess, latest_check_point)

        threads = tf.train.start_queue_runners(coord=coord, sess=sess)
        tile_cnt = 0
        error_map = np.zeros(flags.input_size)
        fig = plt.figure(figsize=(20.0, 12.0))
        try:
            for (image_name, label_name) in collect_files_test:
                if flags.city_name in image_name:
                    tile_cnt += 1

                    city_name = re.findall('[a-z\-]*(?=[0-9]+\.)',
                                           image_name)[0]
                    tile_id = re.findall('[0-9]+(?=\.tif)', image_name)[0]
                    print('Evaluating {}_{}.tif'.format(city_name, tile_id))

                    # load reader
                    iterator_test = image_reader.image_label_iterator(
                        os.path.join(flags.rsr_data_dir, image_name),
                        batch_size=flags.batch_size,
                        tile_dim=meta_test['dim_image'][:2],
                        patch_size=flags.input_size,
                        overlap=0)
                    # run
                    result = model.test('X', sess, iterator_test)

                    # evaluate
                    label_img = scipy.misc.imread(
                        os.path.join(flags.rsr_data_dir, label_name))
                    error_map += evaluate_on_patch(result, label_img,
                                                   meta_test['dim_image'][:2],
                                                   flags.input_size)

                    plt.subplot(230 + tile_cnt)
                    plt.imshow(error_map / np.max(error_map), cmap='hot')
                    plt.colorbar()
                    plt.title('Error Map {}_{}'.format(city_name, tile_id))

            plt.suptitle('Patch Size = {}'.format(flags.input_size))
            dist, error = error_vs_dist(error_map)
            plt.subplot(236)
            plt.plot(dist, error, 'r.')
            plt.title('Error VS Dist ({})'.format(city_name))
            plt.xlabel('Dist to center of patch')
            plt.ylabel('#Errors')
            save_dir = sis_utils.make_task_img_folder(IMG_SAVE_DIR)
            plt.savefig(os.path.join(
                save_dir, 'M-{}_PS-{}'.format(flags.model_name,
                                              flags.input_size[0])),
                        bbox_inches='tight')
            plt.show()
        finally:
            coord.request_stop()
            coord.join(threads)

    duration = time.time() - start_time
    print('duration {:.2f} minutes'.format(duration / 60))
Beispiel #4
0
def test(flags, ep, ds, lr, save_dir):
    # set gpu
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = flags.GPU
    # environment settings
    np.random.seed(flags.random_seed)
    tf.set_random_seed(flags.random_seed)

    # data prepare step
    Data = rsrClassData(flags.rsr_data_dir)
    (collect_files_test, meta_test) = Data.getCollectionByName(flags.test_data_dir)

    # image reader
    coord = tf.train.Coordinator()

    # define place holder
    X = tf.placeholder(tf.float32, shape=[None, flags.input_size[0], flags.input_size[1], 3], name='X')
    y = tf.placeholder(tf.int32, shape=[None, flags.input_size[0], flags.input_size[1], 1], name='y')
    mode = tf.placeholder(tf.bool, name='mode')

    # initialize model
    flags.model_name = 'ResUnetShrinkInria_fr_resample_mean_reduced_EP-{}_DS-{}.0_LR-{}'.format(ep, ds, lr)
    model = unet.ResUnetModel_shrink({'X':X, 'Y':y}, trainable=mode, model_name=flags.model_name, input_size=flags.input_size)
    model.create_graph('X', flags.num_classes)
    model.make_update_ops('X', 'Y')
    # set ckdir
    model.make_ckdir(flags.ckdir)
    # set up graph and initialize
    config = tf.ConfigProto()

    # run training
    start_time = time.time()
    with tf.Session(config=config) as sess:
        init = tf.global_variables_initializer()
        sess.run(init)

        saver = tf.train.Saver(var_list=tf.global_variables(), max_to_keep=1)

        if os.path.exists(model.ckdir) and tf.train.get_checkpoint_state(model.ckdir):
            latest_check_point = tf.train.latest_checkpoint(model.ckdir)
            saver.restore(sess, latest_check_point)
            print('loaded {}'.format(latest_check_point))

        threads = tf.train.start_queue_runners(coord=coord, sess=sess)
        try:
            iou_record = {}
            for (image_name, label_name) in collect_files_test:
                c_names = flags.city_name.split(',')
                for c_name in c_names:
                    if c_name in image_name:
                        city_name = re.findall('[a-z\-]*(?=[0-9]+\.)', image_name)[0]
                        tile_id = re.findall('[0-9]+(?=\.tif)', image_name)[0]

                        # load reader
                        iterator_test = image_reader.image_label_iterator(
                            os.path.join(flags.rsr_data_dir, image_name),
                            batch_size=flags.batch_size,
                            tile_dim=meta_test['dim_image'][:2],
                            patch_size=flags.input_size,
                            overlap=0, padding=0,
                            image_mean=IMG_MEAN)
                        # run
                        result = model.test('X', sess, iterator_test)

                        pred_label_img = sis_utils.get_output_label(result,
                                                                    meta_test['dim_image'],
                                                                    flags.input_size,
                                                                    meta_test['colormap'], overlap=0,
                                                                    output_image_dim=meta_test['dim_image'],
                                                                    output_patch_size=flags.input_size,
                                                                    make_map=False)
                        # evaluate
                        truth_label_img = scipy.misc.imread(os.path.join(flags.rsr_data_dir, label_name))
                        iou = sis_utils.iou_metric(truth_label_img, pred_label_img * 255)

                        '''plt.subplot(121)
                        plt.imshow(truth_label_img)
                        plt.subplot(122)
                        plt.imshow(pred_label_img)
                        plt.show()'''

                        iou_record[image_name] = iou
                        print('{}_{}: iou={:.2f}'.format(city_name, tile_id, iou*100))
        finally:
            coord.request_stop()
            coord.join(threads)

    duration = time.time() - start_time
    print('duration {:.2f} minutes'.format(duration/60))
    np.save(os.path.join(save_dir, '{}.npy').format(model.model_name), iou_record)

    iou_mean = []
    for _, val in iou_record.items():
        iou_mean.append(val)
    print('{}: {}'.format(flags.model_name, np.mean(iou_mean)))
    return np.mean(iou_mean)
Beispiel #5
0
def test_and_save(flags, model_name, save_dir):
    # set gpu
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = flags.GPU
    # environment settings
    np.random.seed(flags.random_seed)
    tf.set_random_seed(flags.random_seed)

    # data prepare step
    Data = rsrClassData(flags.rsr_data_dir)
    (collect_files_test, meta_test) = Data.getCollectionByName(flags.test_data_dir)

    # image reader
    coord = tf.train.Coordinator()

    # define place holder
    X = tf.placeholder(tf.float32, shape=[None, flags.input_size[0], flags.input_size[1], 3], name='X')
    y = tf.placeholder(tf.int32, shape=[None, flags.input_size[0], flags.input_size[1], 1], name='y')
    mode = tf.placeholder(tf.bool, name='mode')

    # initialize model
    if 'appendix' in model_name:
        model = unet.UnetModel_Height_Appendix({'X':X, 'Y':y}, trainable=mode, model_name=model_name, input_size=flags.input_size)
    elif 'Res' in model_name:
        model = unet.ResUnetModel_Crop({'X': X, 'Y': y}, trainable=mode, model_name=model_name,
                                      input_size=flags.input_size)
    else:
        model = unet.UnetModel_Origin({'X':X, 'Y':y}, trainable=mode, model_name=model_name, input_size=flags.input_size)
    if 'large' in model_name:
        model.create_graph('X', flags.num_classes, start_filter_num=40)
    else:
        model.create_graph('X', flags.num_classes)
    model.make_update_ops('X', 'Y')
    # set ckdir
    model.make_ckdir(flags.ckdir)
    # set up graph and initialize
    config = tf.ConfigProto()

    # make fold if not exists
    save_path = os.path.join(save_dir, 'temp_save', model_name)
    if not os.path.exists(save_path):
        os.makedirs(save_path)
    else:
        return save_path

    # run training
    start_time = time.time()
    with tf.Session(config=config) as sess:
        init = tf.global_variables_initializer()
        sess.run(init)

        saver = tf.train.Saver(var_list=tf.global_variables(), max_to_keep=1)

        if os.path.exists(model.ckdir) and tf.train.get_checkpoint_state(model.ckdir):
            latest_check_point = tf.train.latest_checkpoint(model.ckdir)
            saver.restore(sess, latest_check_point)
            print('loaded {}'.format(latest_check_point))

        threads = tf.train.start_queue_runners(coord=coord, sess=sess)
        try:
            for (image_name, label_name) in collect_files_test:
                c_names = flags.city_name.split(',')
                for c_name in c_names:
                    if c_name in image_name:
                        city_name = re.findall('[a-z\-]*(?=[0-9]+\.)', image_name)[0]
                        tile_id = re.findall('[0-9]+(?=\.tif)', image_name)[0]

                        print('Scoring {}_{} using {}...'.format(city_name, tile_id, model_name))

                        # load reader
                        iterator_test = image_reader.image_label_iterator(
                            os.path.join(flags.rsr_data_dir, image_name),
                            batch_size=flags.batch_size,
                            tile_dim=meta_test['dim_image'][:2],
                            patch_size=flags.input_size,
                            overlap=184, padding=92,
                            image_mean=IMG_MEAN)
                        # run
                        result = model.test('X', sess, iterator_test, soft_pred=True)

                        pred_label_img = sis_utils.get_output_label(result,
                                                                    (meta_test['dim_image'][0]+184, meta_test['dim_image'][1]+184),
                                                                    flags.input_size,
                                                                    meta_test['colormap'], overlap=184,
                                                                    output_image_dim=meta_test['dim_image'],
                                                                    output_patch_size=(flags.input_size[0]-184, flags.input_size[1]-184),
                                                                    make_map=False, soft_pred=True)
                        file_name = os.path.join(save_path, '{}_{}.npy'.format(city_name, tile_id))
                        np.save(file_name, pred_label_img)
        finally:
            coord.request_stop()
            coord.join(threads)

    duration = time.time() - start_time
    print('duration {:.2f} minutes'.format(duration/60))
    return save_path
def main(flags):
    # set gpu
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = flags.GPU
    # environment settings
    np.random.seed(flags.random_seed)
    tf.set_random_seed(flags.random_seed)

    for city in ['bellingham', 'bloomington', 'innsbruck', 'sfo', 'tyrol-e']:
        if not os.path.exists('./temp'):
            os.makedirs('./temp')

        flags.city_name = city
        for m_name in MODEL_NAME:
            tf.reset_default_graph()

            # data prepare step
            Data = rsrClassData(flags.rsr_data_dir)
            (collect_files_test,
             meta_test) = Data.getCollectionByName(flags.test_data_dir)

            # image reader
            coord = tf.train.Coordinator()

            # define place holder
            X = tf.placeholder(
                tf.float32,
                shape=[None, flags.input_size[0], flags.input_size[1], 3],
                name='X')
            y = tf.placeholder(
                tf.int32,
                shape=[None, flags.input_size[0], flags.input_size[1], 1],
                name='y')
            mode = tf.placeholder(tf.bool, name='mode')

            # initialize model
            model = unet.UnetModel({
                'X': X,
                'Y': y
            },
                                   trainable=mode,
                                   model_name=m_name,
                                   input_size=flags.input_size)
            model.create_graph('X', flags.num_classes)
            model.make_update_ops('X', 'Y')
            # set ckdir
            model.make_ckdir(flags.ckdir)
            # set up graph and initialize
            config = tf.ConfigProto()

            # run training
            start_time = time.time()

            with tf.Session(config=config) as sess:
                init = tf.global_variables_initializer()
                sess.run(init)

                saver = tf.train.Saver(var_list=tf.global_variables(),
                                       max_to_keep=1)

                if os.path.exists(
                        model.ckdir) and tf.train.get_checkpoint_state(
                            model.ckdir):
                    print('loading model from {}'.format(model.ckdir))
                    latest_check_point = tf.train.latest_checkpoint(
                        model.ckdir)
                    saver.restore(sess, latest_check_point)

                threads = tf.train.start_queue_runners(coord=coord, sess=sess)
                for (image_name, ) in collect_files_test:
                    if flags.city_name in image_name:
                        city_name = re.findall('[a-z\-]*(?=[0-9]+\.)',
                                               image_name)[0]
                        tile_id = re.findall('[0-9]+(?=\.tif)', image_name)[0]
                        print('Evaluating {}_{} at patch size: {}'.format(
                            city_name, tile_id, flags.input_size))

                        # load reader
                        iterator_test = image_reader.image_label_iterator(
                            os.path.join(flags.rsr_data_dir, image_name),
                            batch_size=flags.batch_size,
                            tile_dim=meta_test['dim_image'][:2],
                            patch_size=flags.input_size,
                            overlap=0)
                        # run
                        result = model.test('X', sess, iterator_test)
                        raw_pred = patch_extractor.un_patchify(
                            result, meta_test['dim_image'], flags.input_size)

                        file_name = '{}_{}_{}.npy'.format(
                            m_name, city_name, tile_id)
                        np.save(os.path.join('./temp', file_name), raw_pred)
                coord.request_stop()
                coord.join(threads)

            duration = time.time() - start_time
            print('duration {:.2f} minutes'.format(duration / 60))

        for tile_num in range(36):
            output = np.zeros((5000, 5000, 2))
            for m_name in MODEL_NAME:
                raw_pred = np.load(
                    os.path.join(
                        './temp',
                        '{}_{}_{}.npy'.format(m_name, flags.city_name,
                                              tile_num + 1)))
                output += raw_pred

            # combine results
            labels_pred = sis_utils.get_pred_labels(output)
            output_pred = sis_utils.make_output_file(labels_pred,
                                                     meta_test['colormap'])
            scipy.misc.imsave(
                os.path.join(FIG_SAVE_DIR,
                             '{}{}.tif'.format(flags.city_name, tile_num + 1)),
                output_pred)

        shutil.rmtree('./temp')
Beispiel #7
0
def test_real_across_city(flags, MODEL_NAME, patch_size):
    # set gpu
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = flags.GPU
    tf.reset_default_graph()
    # environment settings
    np.random.seed(flags.random_seed)
    tf.set_random_seed(flags.random_seed)

    result_dict = {}

    for city in ['austin', 'chicago', 'kitsap', 'tyrol-w', 'vienna']:
        if not os.path.exists('./temp'):
            os.makedirs('./temp')

        flags.city_name = city
        for m_name in MODEL_NAME:
            tf.reset_default_graph()

            # data prepare step
            Data = rsrClassData(flags.rsr_data_dir)
            (collect_files_test,
             meta_test) = Data.getCollectionByName(flags.test_data_dir)

            # image reader
            coord = tf.train.Coordinator()

            # define place holder
            X = tf.placeholder(tf.float32,
                               shape=[None, patch_size[0], patch_size[1], 3],
                               name='X')
            y = tf.placeholder(tf.int32,
                               shape=[None, patch_size[0], patch_size[1], 1],
                               name='y')
            mode = tf.placeholder(tf.bool, name='mode')

            # initialize model
            model = unet.UnetModel_Origin({
                'X': X,
                'Y': y
            },
                                          trainable=mode,
                                          model_name=m_name,
                                          input_size=patch_size)
            model.create_graph('X', flags.num_classes)
            model.make_update_ops('X', 'Y')
            # set ckdir
            model.make_ckdir(flags.ckdir)
            # set up graph and initialize
            config = tf.ConfigProto()

            # run training
            start_time = time.time()

            with tf.Session(config=config) as sess:
                init = tf.global_variables_initializer()
                sess.run(init)

                saver = tf.train.Saver(var_list=tf.global_variables(),
                                       max_to_keep=1)

                if os.path.exists(
                        model.ckdir) and tf.train.get_checkpoint_state(
                            model.ckdir):
                    print('loading model from {}'.format(model.ckdir))
                    latest_check_point = tf.train.latest_checkpoint(
                        model.ckdir)
                    saver.restore(sess, latest_check_point)

                threads = tf.train.start_queue_runners(coord=coord, sess=sess)
                for (image_name, label_name) in collect_files_test:
                    if flags.city_name in image_name:
                        city_name = re.findall('[a-z\-]*(?=[0-9]+\.)',
                                               image_name)[0]
                        tile_id = re.findall('[0-9]+(?=\.tif)', image_name)[0]
                        print('Evaluating {}_{} at patch size: {}'.format(
                            city_name, tile_id, patch_size))

                        # load reader
                        iterator_test = image_reader.image_label_iterator(
                            os.path.join(flags.rsr_data_dir, image_name),
                            batch_size=flags.batch_size,
                            tile_dim=meta_test['dim_image'][:2],
                            patch_size=patch_size,
                            overlap=184,
                            padding=92)
                        # run
                        result = model.test('X', sess, iterator_test)
                        raw_pred = patch_extractor.un_patchify_shrink(
                            result, (meta_test['dim_image'][0] + 184,
                                     meta_test['dim_image'][1] + 184),
                            tile_dim_output=meta_test['dim_image'],
                            patch_size=patch_size,
                            patch_size_output=(patch_size[0] - 184,
                                               patch_size[1] - 184),
                            overlap=184)
                        file_name = '{}_{}_{}.npy'.format(
                            m_name.split('/')[-1], city_name, tile_id)
                        np.save(os.path.join('./temp', file_name), raw_pred)
                coord.request_stop()
                coord.join(threads)

            duration = time.time() - start_time
            print('duration {:.2f} minutes'.format(duration / 60))

        for tile_num in range(5):
            output = np.zeros((5000, 5000, 2))
            for m_name in MODEL_NAME:
                raw_pred = np.load(
                    os.path.join(
                        './temp', '{}_{}_{}.npy'.format(
                            m_name.split('/')[-1], city, tile_num + 1)))
                output += raw_pred

            # combine results
            pred_label_img = sis_utils.get_pred_labels(output)
            output_pred = sis_utils.make_output_file(pred_label_img,
                                                     meta_test['colormap'])
            # evaluate
            truth_label_img = scipy.misc.imread(
                os.path.join(flags.rsr_data_dir, 'inria', 'truth',
                             '{}{}.tif'.format(city, tile_num + 1)))
            iou = sis_utils.iou_metric(truth_label_img, output_pred)
            print('{}_{}: iou={:.2f}'.format(city, tile_id, iou * 100))

            result_dict['{}{}'.format(city, tile_id)] = iou

        shutil.rmtree('./temp')
    return result_dict