예제 #1
0
def read_from_list(file, data_path):
    ids = []
    with open(file, 'r') as phase_input:
        lines = phase_input.readlines()
        for line in lines:
            splt = line.split('/')[1]
            ids.append(splt)
    train_data = osp.join(data_path, 'train')
    image_folder = osp.join(train_data, 'images')
    mask_folder = osp.join(train_data, 'masks')

    samples = {}
    for id in ids:
        id = id[:-1]
        samples[id] = Sample()
        samples[id].image_fp = osp.join(image_folder, id + '.png')
        samples[id].mask_fp = osp.join(mask_folder, id + '.png')
    return samples
예제 #2
0
def get_all_samples(root_path, has_target=True):
    samples = {}

    image_folder = osp.join(root_path, 'images')
    image_files = glob.glob(osp.join(image_folder, '*.png'))

    for image_file in image_files:
        sample_id = get_file_id(image_file)
        samples[sample_id] = Sample()
        samples[sample_id].image_fp = image_file

    if has_target:
        mask_folder = osp.join(root_path, 'masks')
        mask_files = glob.glob(osp.join(mask_folder, '*.png'))

        for mask_file in mask_files:
            sample_id = get_file_id(mask_file)
            assert sample_id in samples, 'get all samples, wrong mask id'

            samples[sample_id].mask_fp = mask_file

    return samples