def run_celeba():
    celeba_database = CelebADatabase(input_shape=(224, 224, 3))
    # celeba_database = LFWDatabase()
    maml = FaceRecognition(
        database=celeba_database,
        network_cls=MiniImagenetModel,
        # network_cls=VGGSmallModel,
        n=5,
        k_ml=1,
        k_val_ml=5,
        k_val=1,
        k_val_val=15,
        k_test=1,
        k_val_test=15,
        meta_batch_size=4,
        num_steps_ml=5,
        lr_inner_ml=0.01,
        num_steps_validation=5,
        save_after_iterations=20,
        meta_learning_rate=0.001,
        report_validation_frequency=250,
        log_train_images_after_iteration=1000,
        num_tasks_val=100,
        clip_gradients=True,
        experiment_name='celeba')

    # maml.train(iterations=100)
    # maml.evaluate(5, seed=42)
    maml.evaluate_with_original_face_recognition(5, seed=42)
Exemple #2
0
def run_transfer_learning():
    isic_database = CelebADatabase()
    transfer_learning = TransferLearning(
        database=isic_database,
        network_cls=get_network,
        n=5,
        k=1,
        k_val_ml=5,
        k_val_val=15,
        k_val_test=15,
        k_test=1,
        meta_batch_size=4,
        num_steps_ml=5,
        lr_inner_ml=0.05,
        num_steps_validation=5,
        save_after_iterations=15000,
        meta_learning_rate=0.001,
        report_validation_frequency=250,
        log_train_images_after_iteration=1000,
        number_of_tasks_val=100,
        number_of_tasks_test=1000,
        clip_gradients=True,
        experiment_name='fixed_vgg_19',
        val_seed=42,
        val_test_batch_norm_momentum=0.0,
    )
    transfer_learning.evaluate(50, seed=42, use_val_batch_statistics=True)
def run_celeba():
    celeba_database = CelebADatabase()
    base_model = tf.keras.applications.VGG19(weights='imagenet')
    feature_model = tf.keras.models.Model(inputs=base_model.input,
                                          outputs=base_model.layers[24].output)

    sml = SML(
        database=celeba_database,
        network_cls=MiniImagenetModel,
        n=5,
        k=1,
        k_val_ml=5,
        k_val_val=15,
        k_val_test=15,
        k_test=15,
        meta_batch_size=4,
        num_steps_ml=5,
        lr_inner_ml=0.05,
        num_steps_validation=5,
        save_after_iterations=15000,
        meta_learning_rate=0.001,
        n_clusters=20,
        feature_model=feature_model,
        # feature_size=288,
        feature_size=4096,
        input_shape=(224, 224, 3),
        preprocess_function=tf.keras.applications.vgg19.preprocess_input,
        log_train_images_after_iteration=1000,
        number_of_tasks_val=100,
        number_of_tasks_test=1000,
        clip_gradients=True,
        report_validation_frequency=250,
        experiment_name='celeba_imagenet_features')
    sml.train(iterations=60000)
    sml.evaluate(iterations=50, seed=42)
def run_celeba():
    celeba_database = CelebADatabase()

    gan_sampling = GANSampling(
        database=celeba_database,
        network_cls=MiniImagenetModel,
        n=5,
        k=1,
        k_val_ml=6,
        k_val_train=1,
        k_val_val=15,
        k_val_test=15,
        k_test=1,
        meta_batch_size=4,
        num_steps_ml=5,
        lr_inner_ml=0.05,
        num_steps_validation=5,
        save_after_iterations=2000,
        meta_learning_rate=0.001,
        report_validation_frequency=250,
        log_train_images_after_iteration=1000,
        number_of_tasks_val=100,
        number_of_tasks_test=1000,
        clip_gradients=True,
        experiment_name='celeba_noise_std_1.2',
        val_seed=42,
        val_test_batch_norm_momentum=0.0
    )

    gan_sampling.train(iterations=20000)
    gan_sampling.evaluate(iterations=50, use_val_batch_statistics=True, seed=42)
def run_celeba():
    celeba_database = CelebADatabase()
    maml = ModelAgnosticMetaLearningModel(
        database=celeba_database,
        network_cls=MiniImagenetModel,
        n=5,
        k_ml=1,
        k_val_ml=5,
        k_val=1,
        k_val_val=15,
        k_test=1,
        k_val_test=15,
        meta_batch_size=4,
        num_steps_ml=1,
        lr_inner_ml=0.05,
        num_steps_validation=5,
        save_after_iterations=5000,
        meta_learning_rate=0.0001,
        report_validation_frequency=250,
        log_train_images_after_iteration=1000,
        num_tasks_val=100,
        clip_gradients=True,
        experiment_name='celeba'
    )

    maml.train(iterations=60000)
    maml.evaluate(50, num_tasks=1000, seed=42)
Exemple #6
0
    def setUp(self):
        def parse_function(example_address):
            return example_address

        self.parse_function = parse_function

        self.omniglot_database = OmniglotDatabase(random_seed=-1,
                                                  num_train_classes=1200,
                                                  num_val_classes=100)
        self.mini_imagenet_database = MiniImagenetDatabase()
        self.celeba_database = CelebADatabase()
        self.lfw_database = LFWDatabase()
        self.euro_sat_database = EuroSatDatabase()
        self.isic_database = ISICDatabase()
        self.chest_x_ray_database = ChestXRay8Database()
def run_celeba():
    celeba_database = CelebADatabase(random_seed=-1)
    maml = MAMLAbstractLearner(database=celeba_database,
                               network_cls=MiniImagenetModel,
                               n=5,
                               k=4,
                               meta_batch_size=1,
                               num_steps_ml=5,
                               lr_inner_ml=0.01,
                               num_steps_validation=5,
                               save_after_epochs=20,
                               meta_learning_rate=0.001,
                               report_validation_frequency=1,
                               log_train_images_after_iteration=1000,
                               least_number_of_tasks_val_test=50,
                               clip_gradients=True,
                               experiment_name='celeba')
    maml.train(epochs=100)
Exemple #8
0
        test_dataset = self.database.get_attributes_task_dataset(
            partition='test',
            k=self.k_test,
            k_val=self.k_val_test,
            meta_batch_size=1,
            parse_fn=self.gan.parser.get_parse_fn(),
            seed=seed)
        test_dataset = test_dataset.repeat(-1)
        test_dataset = test_dataset.take(num_tasks)

        setattr(test_dataset, 'steps_per_epoch', num_tasks)
        return test_dataset


if __name__ == '__main__':
    celeba_database = CelebADatabase()
    shape = (84, 84, 3)
    latent_dim = 512
    gan = hub.load(
        "https://tfhub.dev/google/progan-128/1").signatures['default']
    setattr(gan, 'parser', CelebAGANParser(shape=(84, 84, 3)))

    maml_gan = MAMLGANProGAN(
        gan=gan,
        latent_dim=latent_dim,
        generated_image_shape=shape,
        database=celeba_database,
        network_cls=MiniImagenetModel,
        n=2,  # n=2
        k_ml=1,
        k_val_ml=5,
Exemple #9
0
    x = layers.ReLU()(x)

    decoder_outputs = layers.Conv2DTranspose(3, 4, activation="sigmoid", padding="same")(x)
    decoder = keras.Model(latent_inputs, decoder_outputs, name="decoder")
    decoder.summary()

    return decoder


if __name__ == '__main__':
#     import tensorflow as tf
#     gpus = tf.config.experimental.list_physical_devices('GPU')
#     tf.config.experimental.set_memory_growth(gpus[0], True)
#     tf.config.experimental_run_functions_eagerly(True)

    celebalot_database = CelebADatabase()
    shape = (84, 84, 3)
    latent_dim = 500
    celebalot_encoder = get_encoder(latent_dim)
    celebalot_decoder = get_decoder(latent_dim)
    celebalot_parser = CelebAParser(shape=shape)

    vae = VAE(
        'celeba2',
        image_shape=shape,
        latent_dim=latent_dim,
        database=celebalot_database,
        parser=celebalot_parser,
        encoder=celebalot_encoder,
        decoder=celebalot_decoder,
        visualization_freq=1,