Exemplo n.º 1
0
    if config.sample_ratio is not None:
        kwargs = {}
        gan_data_loader = MNISTLoader_aug(expanded_images, expanded_labels, 
                                  first=int(party_data_size *100 * (1 - config.sample_ratio)),
                                  seed=config.sample_seed
                                )
        sample_data_loader = MNISTLoader_aug(expanded_images, expanded_labels, 
                                  last=int(party_data_size *100 * config.sample_ratio),
                                  seed=config.sample_seed
                                )
    else:
        gan_data_loader = MNISTLoader(config.data_dir, include_train=not config.exclude_train,
                                  include_test=not config.exclude_test)

    if config.enable_accounting:
        accountant = GaussianMomentsAccountant(gan_data_loader.n, config.moment)
        if config.log_path:
            open(config.log_path, "w").close()
    else:
        accountant = None

    if config.adaptive_rate:
        lr = tf.placeholder(tf.float32, shape=())
    else:
        lr = config.learning_rate

    gen_optimizer = tf.train.AdamOptimizer(config.gen_learning_rate, beta1=0.5, beta2=0.9)
    disc_optimizer = tf.train.AdamOptimizer(lr, beta1=0.5, beta2=0.9)

    clipper_ret = get_clipper(config.clipper, config)
    if isinstance(clipper_ret, tuple):
Exemplo n.º 2
0
    np.random.seed()
    if config.enable_accounting:
        config.sigma = np.sqrt(2.0 * np.log(1.25 / config.delta)) / config.epsilon
        print("Now with new sigma: %.4f" % config.sigma)

    if config.image_size == 64:
        data_loader = LSUNLoader(config.data_dir, num_workers=4, actions=lsun_process_actions())
        data_loader.start_fetch()
        generator_forward = d64_resnet_dcgan.generator_forward
        discriminator_forward = d64_resnet_dcgan.discriminator_forward
    else:
        raise NotImplementedError("Unsupported image size %d." % config.image_size)

    if config.enable_accounting:
        accountant = GaussianMomentsAccountant(data_loader.num_steps(1), config.moment)
        if config.log_path:
            open(config.log_path, "w").close()
    else:
        accountant = None

    if config.adaptive_rate:
        lr = tf.placeholder(tf.float32, shape=())
    else:
        lr = config.learning_rate

    gen_optimizer = tf.train.AdamOptimizer(config.gen_learning_rate, beta1=config.beta1,
                                       beta2=config.beta2)
    disc_optimizer = tf.train.AdamOptimizer(lr, beta1=config.beta1,
                                       beta2=config.beta2)