Exemplo n.º 1
0
def get_stats_pb(img_dir):
    val = process_block.ValueComputeProcess(
        DS_NAME, os.path.join(os.path.dirname(__file__), '../stats/builtin'),
        os.path.join(os.path.dirname(__file__), '../stats/builtin/{}.npy').format(DS_NAME), func=get_stats).\
        run(img_dir=img_dir).val
    val_test = process_block.ValueComputeProcess(
        DS_NAME+'_test', os.path.join(os.path.dirname(__file__), '../stats/builtin'),
        os.path.join(os.path.dirname(__file__), '../stats/builtin/{}.npy'.format(DS_NAME)), func=get_stats).\
        run(img_dir=img_dir, is_test=True).val
    return val, val_test
Exemplo n.º 2
0
def get_dataset_stats(ds_name,
                      img_dir,
                      load_func=None,
                      file_list=None,
                      mean_val=([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])):
    if ds_name == 'inria':
        from data.inria import preprocess
        val = preprocess.get_stats_pb(img_dir)[0]
        print('Use {} mean std stats: {}'.format(ds_name, val))
    elif ds_name == 'deepglobe':
        from data.deepglobe import preprocess
        val = preprocess.get_stats_pb(img_dir)[0]
        print('Use {} mean std stats: {}'.format(ds_name, val))
    elif ds_name == 'deepgloberoad':
        from data.deepgloberoad import preprocess
        val = preprocess.get_stats_pb(img_dir)[0]
        print('Use {} mean std stats: {}'.format(ds_name, val))
    elif ds_name == 'deepglobeland':
        from data.deepglobeland import preprocess
        val = preprocess.get_stats_pb(img_dir)[0]
        print('Use {} mean std stats: {}'.format(ds_name, val))
    elif ds_name == 'mnih':
        from data.mnih import preprocess
        val = preprocess.get_stats_pb(img_dir)[0]
        print('Use {} mean std stats: {}'.format(ds_name, val))
    elif ds_name == 'spca':
        from data.spca import preprocess
        val = preprocess.get_stats_pb(img_dir)[0]
        print('Use {} mean std stats: {}'.format(ds_name, val))
    elif load_func:
        try:
            val = process_block.ValueComputeProcess(
                ds_name, os.path.join(os.path.dirname(__file__), '../data/stats/custom'),
                os.path.join(os.path.dirname(__file__), '../data/stats/custom/{}.npy'.format(ds_name)),
                func=load_func). \
                run(img_dir=img_dir, file_list=file_list).val
            print('Use {} mean std stats: {}'.format(ds_name, val))
        except ValueError:
            print(
                'Dataset {} is not supported, use default mean stats instead'.
                format(ds_name))
            return np.array(mean_val)
    else:
        try:
            val = misc_utils.load_file(
                os.path.join(
                    os.path.realpath(
                        os.path.join(os.path.dirname(__file__), '..')),
                    'data/stats/custom/{}.npy'.format(ds_name)))
            print('Use {} mean std stats: {}'.format(ds_name, val))
        except (FileNotFoundError, OSError):
            print(
                'Dataset {} is not supported, use default mean stats instead {}'
                .format(ds_name, mean_val))
            return np.array(mean_val)
    return val[0, :], val[1, :]
Exemplo n.º 3
0
    val = process_block.ValueComputeProcess(
        DS_NAME, os.path.join(os.path.dirname(__file__), '../stats/builtin'),
        os.path.join(os.path.dirname(__file__), '../stats/builtin/{}.npy'.format(DS_NAME)), func=get_stats).\
        run(img_dir=img_dir).val
    val_test = val
    return val, val_test


def get_images(data_dir):
    record_file_valid = os.path.join(data_dir, 'file_list_valid.txt')
    file_list = misc_utils.load_file(record_file_valid)
    rgb_files, gt_files = [], []
    for line in file_list:
        rgb_file, gt_file = line.strip().split(' ')
        rgb_files.append(os.path.join(data_dir, 'patches', rgb_file))
        gt_files.append(os.path.join(data_dir, 'patches', gt_file))
    return rgb_files, gt_files


if __name__ == '__main__':
    # save_dir = os.path.join(r'/hdd/mrs/deepglobe', 'pd{}_ol{}'.format(0, 0))
    # train, valid = get_image_gt(r'/hdd/deepglobe', ['Vegas', 'Paris', 'Shanghai', 'Khartoum'], valid_percent=0.4)
    # make_dataset(train, valid, save_dir)

    val = process_block.ValueComputeProcess(
        'DeepGlobe_cmatch', os.path.join(os.path.dirname(__file__), '../stats/custom'),
        os.path.join(os.path.dirname(__file__), '../stats/custom/{}_cmatch.npy'.format(DS_NAME)), func=get_stats). \
        run(img_dir='/hdd/mrs/deepglobe_cmatch/14p_pd0_ol0/patches').val
    val_test = val
    print(val)
Exemplo n.º 4
0
            if city_name in VAL_CITY and tile_id in VAL_IDS:
                rgb_files.append(rgb_filename)
                gt_files.append(gt_filename)
            else:
                # FIXME adhoc solution to make rgb and gt files have the same length
                rgb_files.append(rgb_filename)
                gt_files.append(rgb_filename)
    return rgb_files, gt_files


if __name__ == '__main__':
    '''ps = 512
    pd = 0
    ol = 0
    save_dir = os.path.join(r'/hdd/mrs/inria', 'ps{}_pd{}_ol{}'.format(ps, pd, ol))
    misc_utils.make_dir_if_not_exist(save_dir)
    patch_inria(data_dir=r'/media/ei-edl01/data/remote_sensing_data/inria',
                save_dir=save_dir,
                patch_size=(ps, ps),
                pad=pd, overlap=ol)'''

    func = get_stats
    from mrs_utils import process_block
    pb = process_block.ValueComputeProcess(DS_NAME,
                                           '../stats'.format(DS_NAME),
                                           '../stats/{}.npy'.format(DS_NAME),
                                           func=func)
    mean_val = pb.run(
        img_dir=r'/media/ei-edl01/data/remote_sensing_data/inria/images').val
    print(mean_val)