Пример #1
0
def main():
    image_paths = get_image_path_list()
    label_paths = get_label_path_list()
    classes = get_classes_matrix(label_paths)
    image_paths = get_data_subset(image_paths, classes)
    label_paths = get_data_subset(label_paths, classes)
    paths = {'color':image_paths,
             'gray' :image_paths,
             'label':label_paths}
    # prepare images
    image_dict = {}
    for t, p in paths.items():
        with ex.optionset(t) as o:
            images= o.load_and_resize_images(p)
            images= o.pad_images_and_equalize_sizes(images)
            images=o.reshape_images(images)
            write_idx_file(o.options['filename'].format(**o.options), images)
            image_dict[t] = images


    # create samples
    class_samples = create_samples(image_dict['label'])
    # reduce number of background samples
    np.random.shuffle(class_samples[0])
    class_samples[0] = class_samples[0][:500000]
    write_samples_to_idx(np.vstack(tuple(class_samples)), ex.options['all_samples_filename'].format(**ex.options))
Пример #2
0
def write_samples_to_idx(samples, filename):
    np.random.shuffle(samples)
    write_idx_file(filename, samples, byteswap=False)