)
    # gan.perform_training(epochs=GAN_EPOCHS, checkpoint_freq=50)
    gan.load_latest_checkpoint()

    print("GAN training finished")
    time.sleep(1)

    train_folders = omniglot_database.train_folders
    keys = list(train_folders.keys())
    sample_size = np.max([
        N_WAY * META_BATCH_SIZE,
        int(len(train_folders.keys()) * labeled_percentage)
    ])
    keys = np.random.choice(keys, sample_size, replace=False)
    train_folders = {k: v for (k, v) in train_folders.items() if k in keys}
    omniglot_database.train_folders = train_folders

    L = None
    ssml_maml = SSMLMAML(perc=labeled_percentage,
                         accessible_labels=L,
                         database=omniglot_database,
                         network_cls=SimpleModel,
                         n=N_WAY,
                         k_ml=K,
                         k_val_ml=K,
                         k_val=K,
                         k_val_val=K,
                         k_test=K,
                         k_val_test=K,
                         meta_batch_size=META_BATCH_SIZE,
                         num_steps_ml=5,
Exemplo n.º 2
0
    experiment_name = prefix+str(labeled_percentage)
    if GAN_N_ALT > 1:
        experiment_name += "_alt"+str(GAN_N_ALT)

    # Split labeled and not labeled
    train_folders = omniglot_database.train_folders
    keys = list(train_folders.keys())
    labeled_keys = np.random.choice(keys, int(len(train_folders.keys())*labeled_percentage), replace=False)
    train_folders_labeled = {k: v for (k, v) in train_folders.items() if k in labeled_keys}
    train_folders_unlabeled = {k: v for (k, v) in train_folders.items() if k not in labeled_keys}

    print("Number of unlabeled classes:", len(train_folders_unlabeled.keys()))
    print("Number of labeled classes:" , len(train_folders_labeled.keys()))

    # Start with unlabeled
    omniglot_database.train_folders = train_folders_unlabeled
    omniglot_discriminator = get_discriminator(len(train_folders_labeled))
    ssgan = SSGAN(
        gan_name='ssgan_omniglot_'+str(labeled_percentage),
        SS=False,
        image_shape=shape,
        latent_dim=latent_dim,
        database=omniglot_database,
        parser=omniglot_parser,
        generator=omniglot_generator,
        discriminator=omniglot_discriminator,
        visualization_freq=50,
        d_learning_rate=0.0003,
        g_learning_rate=0.0003,
    )