def create_train_gen(): """ this generates the training data in order, for postprocessing. Do not use this for actual training. """ data_gen_train = ra.realtime_fixed_augmented_data_gen(train_indices, 'train', ds_transforms=ds_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes) return load_data.buffered_gen_mp(data_gen_train, buffer_size=GEN_BUFFER_SIZE)
def create_test_gen(): data_gen_test = ra.realtime_fixed_augmented_data_gen( test_indices, "test", ds_transforms=ds_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes, processor_class=ra.LoadAndProcessFixedPysexGen1CenteringRescaling, ) return load_data.buffered_gen_mp(data_gen_test, buffer_size=GEN_BUFFER_SIZE)
def create_train_gen(): """ this generates the training data in order, for postprocessing. Do not use this for actual training. """ data_gen_train = ra.realtime_fixed_augmented_data_gen( train_indices, "train", ds_transforms=ds_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes, processor_class=ra.LoadAndProcessFixedPysexGen1CenteringRescaling, ) return load_data.buffered_gen_mp(data_gen_train, buffer_size=GEN_BUFFER_SIZE)
print "Load model parameters" layers.set_param_values(l6, analysis['param_values']) print "Create generators" # set here which transforms to use to make predictions augmentation_transforms = [] for zoom in [1 / 1.2, 1.0, 1.2]: for angle in np.linspace(0, 360, 10, endpoint=False): augmentation_transforms.append(ra.build_augmentation_transform(rotation=angle, zoom=zoom)) augmentation_transforms.append(ra.build_augmentation_transform(rotation=(angle + 180), zoom=zoom, shear=180)) # flipped print " %d augmentation transforms." % len(augmentation_transforms) augmented_data_gen_valid = ra.realtime_fixed_augmented_data_gen(valid_indices, 'train', augmentation_transforms=augmentation_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes, ds_transforms=ds_transforms) valid_gen = load_data.buffered_gen_mp(augmented_data_gen_valid, buffer_size=1) augmented_data_gen_test = ra.realtime_fixed_augmented_data_gen(test_indices, 'test', augmentation_transforms=augmentation_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes, ds_transforms=ds_transforms) test_gen = load_data.buffered_gen_mp(augmented_data_gen_test, buffer_size=1) approx_num_chunks_valid = int(np.ceil(num_valid * len(augmentation_transforms) / float(CHUNK_SIZE))) approx_num_chunks_test = int(np.ceil(num_test * len(augmentation_transforms) / float(CHUNK_SIZE))) print "Approximately %d chunks for the validation set" % approx_num_chunks_valid print "Approximately %d chunks for the test set" % approx_num_chunks_test if DO_VALID: print
def create_test_gen(): data_gen_test = ra.realtime_fixed_augmented_data_gen(test_indices, 'test', ds_transforms=ds_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes) return load_data.buffered_gen_mp(data_gen_test, buffer_size=GEN_BUFFER_SIZE)
augmentation_params = { 'zoom_range': (1.0 / 1.3, 1.3), 'rotation_range': (0, 360), 'shear_range': (0, 0), 'translation_range': (-4, 4), 'do_flip': True, } augmented_data_gen = ra.realtime_augmented_data_gen(num_chunks=NUM_CHUNKS, chunk_size=CHUNK_SIZE, augmentation_params=augmentation_params, ds_transforms=ds_transforms, target_sizes=input_sizes) post_augmented_data_gen = ra.post_augment_brightness_gen(augmented_data_gen, std=0.5) train_gen = load_data.buffered_gen_mp(post_augmented_data_gen, buffer_size=GEN_BUFFER_SIZE) y_train = np.load("data/solutions_train.npy") train_ids = load_data.train_ids test_ids = load_data.test_ids # split training data into training + a small validation set num_train = len(train_ids) num_test = len(test_ids) num_valid = num_train // 10 # integer division num_train -= num_valid y_valid = y_train[num_train:] y_train = y_train[:num_train]
def create_valid_gen(): data_gen_valid = ra.realtime_fixed_augmented_data_gen(valid_indices, 'train', ds_transforms=ds_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes, processor_class=ra.LoadAndProcessFixedPysexCenteringRescaling) return load_data.buffered_gen_mp(data_gen_valid, buffer_size=GEN_BUFFER_SIZE)
def create_valid_gen(): data_gen_valid = ra.realtime_fixed_augmented_data_gen( valid_indices, "train", ds_transforms=ds_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes ) return load_data.buffered_gen_mp(data_gen_valid, buffer_size=GEN_BUFFER_SIZE)
'shear_range': (0, 0), 'translation_range': (-4, 4), 'do_flip': True, } augmented_data_gen = ra.realtime_augmented_data_gen( num_chunks=NUM_CHUNKS, chunk_size=CHUNK_SIZE, augmentation_params=augmentation_params, ds_transforms=ds_transforms, target_sizes=input_sizes) post_augmented_data_gen = ra.post_augment_brightness_gen(augmented_data_gen, std=0.5) train_gen = load_data.buffered_gen_mp(post_augmented_data_gen, buffer_size=GEN_BUFFER_SIZE) y_train = np.load("data/solutions_train.npy") train_ids = load_data.train_ids test_ids = load_data.test_ids # split training data into training + a small validation set num_train = len(train_ids) num_test = len(test_ids) num_valid = num_train // 10 # integer division num_train -= num_valid y_valid = y_train[num_train:] y_train = y_train[:num_train]
def create_test_gen(): data_gen_test = ra.realtime_fixed_augmented_data_gen(test_indices, 'test', ds_transforms=ds_transforms, chunk_size=CHUNK_SIZE, target_sizes=input_sizes, processor_class=ra.LoadAndProcessFixedPysexCenteringRescaling) return load_data.buffered_gen_mp(data_gen_test, buffer_size=GEN_BUFFER_SIZE)
augmentation_params = { 'zoom_range': (1.0 / 1.3, 1.3), 'rotation_range': (0, 360), 'shear_range': (0, 0), 'translation_range': (-4, 4), 'do_flip': True, } augmented_data_gen = ra.realtime_augmented_data_gen(num_chunks=N_TRAIN/BATCH_SIZE, chunk_size=BATCH_SIZE, augmentation_params=augmentation_params, ds_transforms=ds_transforms, target_sizes=input_sizes) post_augmented_data_gen = ra.post_augment_brightness_gen(augmented_data_gen, std=0.5) #train_gen = post_augmented_data_gen train_gen = load_data.buffered_gen_mp(post_augmented_data_gen, buffer_size=GEN_BUFFER_SIZE) #augmentation buffering will not work with the keras .fit, works with fit_generator input_gen = input_generator(train_gen) ''' def create_train_gen(): """ this generates the training data in order, for postprocessing. Do not use this for actual training. """ data_gen_train = ra.realtime_fixed_augmented_data_gen(train_indices, 'train', ds_transforms=ds_transforms, chunk_size=N_TRAIN, target_sizes=input_sizes) return load_data.buffered_gen_mp(data_gen_train, buffer_size=GEN_BUFFER_SIZE) ''' def create_valid_gen(): data_gen_valid = ra.realtime_fixed_augmented_data_gen(valid_indices, 'train',