Exemple #1
0
                              batch_size=batch_size_value,
                              shape=(img_height, img_width, img_channels),
                              shuffle=True,
                              da=True,
                              rotation90=rotation90,
                              rotation_range=rotation_range,
                              vflip=vflips,
                              hflip=hflips,
                              elastic=elastic,
                              g_blur=g_blur,
                              median_blur=median_blur,
                              gamma_contrast=gamma_contrast,
                              zoom=zoom,
                              random_crops_in_DA=random_crops_in_DA)

        extra_generator = ImageDataGenerator(**extra_gen_args)

        extra_x, extra_y = extra_generator.get_transformed_samples(
            extra_train_data, force_full_images=True)

    X_train = np.vstack((X_train, extra_x))
    Y_train = np.vstack((Y_train, extra_y))
    print("{} extra train data generated, the new shape of the train now is {}"\
          .format(extra_train_data, X_train.shape))

print("#######################\n"
      "#  DATA AUGMENTATION  #\n"
      "#######################\n")

if custom_da == False:
    print("Keras DA selected")
                         zoom=zoom,
                         random_crops_in_DA=random_crops_in_DA,
                         prob_map=probability_map,
                         train_prob=train_prob,
                         n_classes=n_classes,
                         extra_data_factor=replicate_train)
    data_gen_val_args = dict(X=X_val,
                             Y=Y_val,
                             batch_size=batch_size_value,
                             shape=(img_height, img_width, img_channels),
                             shuffle=shuffle_val_data_each_epoch,
                             da=False,
                             random_crops_in_DA=random_crops_in_DA,
                             val=True,
                             n_classes=n_classes)
    train_generator = ImageDataGenerator(**data_gen_args)
    val_generator = ImageDataGenerator(**data_gen_val_args)

    # Generate examples of data augmentation
    if aug_examples:
        train_generator.get_transformed_samples(10,
                                                save_to_dir=True,
                                                train=False,
                                                out_dir=da_samples_dir)

print("#################################\n"
      "#  BUILD AND TRAIN THE NETWORK  #\n"
      "#################################\n")

print("Creating the network . . .")
model = U_Net_2D([img_height, img_width, img_channels],