Skip to content

Commit

Permalink
random sampling + noise sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
brettbj committed Jun 28, 2017
1 parent 4b647b4 commit 2014856
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 60 deletions.
51 changes: 27 additions & 24 deletions dp_gan.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def build_discriminator():
# setting seed for reproducibility
np.random.seed(args.seed)
tf.set_random_seed(args.seed)
rn.seed(arg.seed)
rn.seed(args.seed)

# Adam parameters suggested in https://arxiv.org/abs/1511.06434
adam_lr = args.lr
Expand Down Expand Up @@ -205,9 +205,12 @@ def build_discriminator():
for epoch in range(epochs):
print('Epoch {} of {}'.format(epoch + 1, epochs))

num_batches = int(X_train.shape[0] / batch_size)
num_batches = training_size
progress_bar = Progbar(target=num_batches)

random_sample = np.random.randint(0, training_size,
size=training_size)

epoch_gen_loss = []
epoch_disc_loss = []

Expand All @@ -218,8 +221,8 @@ def build_discriminator():
noise = np.random.uniform(-1, 1, (batch_size, latent_size))

# get a batch of real patients
image_batch = X_train[index * batch_size:(index + 1) * batch_size]
label_batch = y_train[index * batch_size:(index + 1) * batch_size]
image_batch = np.expand_dims(X_train[random_sample[index]], axis=1)
label_batch = np.expand_dims(y_train[random_sample[index]], axis=1)

# sample some labels from p_c
sampled_labels = np.random.randint(0, 2, batch_size)
Expand All @@ -231,8 +234,6 @@ def build_discriminator():
generated_images = generator.predict(
[noise, sampled_labels.reshape((-1, 1))], verbose=0)

# print(image_batch.shape)
# print(generated_images.shape)
X = np.concatenate((image_batch, generated_images))
y = np.array([1] * batch_size + [0] * batch_size)
aux_y = np.concatenate((label_batch, sampled_labels), axis=0)
Expand All @@ -259,22 +260,22 @@ def build_discriminator():
priv_start_time = time.clock()

# separate privacy accumulation for speed
privacy_accum_op = priv_accountant.accumulate_privacy_spending(
[None, None], args.noise, batch_size)
for index in range(num_batches):
with tf.control_dependencies([privacy_accum_op]):
spent_eps_deltas = priv_accountant.get_privacy_spent(
sess, target_eps=target_eps)
privacy_history.append(spent_eps_deltas)
sess.run([privacy_accum_op])

for spent_eps, spent_delta in spent_eps_deltas:
print("spent privacy: eps %.4f delta %.5g" % (
spent_eps, spent_delta))
print('priv time: ', time.clock() - priv_start_time)

if spent_eps_deltas[-3][1] > 0.0001:
raise Exception('spent privacy')
# privacy_accum_op = priv_accountant.accumulate_privacy_spending(
# [None, None], args.noise, batch_size)
# for index in range(num_batches):
# with tf.control_dependencies([privacy_accum_op]):
# spent_eps_deltas = priv_accountant.get_privacy_spent(
# sess, target_eps=target_eps)
# privacy_history.append(spent_eps_deltas)
# sess.run([privacy_accum_op])
#
# for spent_eps, spent_delta in spent_eps_deltas:
# print("spent privacy: eps %.4f delta %.5g" % (
# spent_eps, spent_delta))
# print('priv time: ', time.clock() - priv_start_time)
#
# if spent_eps_deltas[-3][1] > 0.0001:
# raise Exception('spent privacy')

print('\nTesting for epoch {}:'.format(epoch + 1))
# generate a new batch of noise
Expand Down Expand Up @@ -339,6 +340,8 @@ def build_discriminator():
directory +
'params_discriminator_epoch_{0:03d}.h5'.format(epoch))

pickle.dump({'train': train_history, 'test': test_history,
'privacy': privacy_history},
pickle.dump({'train': train_history, 'test': test_history},
open(directory + 'acgan-history.pkl', 'wb'))
# pickle.dump({'train': train_history, 'test': test_history,
# 'privacy': privacy_history},
# open(directory + 'acgan-history.pkl', 'wb'))
43 changes: 7 additions & 36 deletions noise_sweep.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 2 --clip_value 1e-05 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 2_1e-05_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 2 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 2_0.0001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 2 --clip_value 0.001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 2_0.001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 3 --clip_value 1e-05 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 3_1e-05_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 3 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 3_0.0001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 3 --clip_value 0.001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 3_0.001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 4 --clip_value 1e-05 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 4_1e-05_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 4 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 4_0.0001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 4 --clip_value 0.001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 4_0.001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 8 --clip_value 1e-05 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 8_1e-05_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 8 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 8_0.0001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 8 --clip_value 0.001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 8_0.001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.25 --clip_value 1e-05 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 0.25_1e-05_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.25 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 0.25_0.0001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.25 --clip_value 0.001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 0.25_0.001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.5 --clip_value 1e-05 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 0.5_1e-05_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.5 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 0.5_0.0001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.5 --clip_value 0.001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 0.5_0.001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 1e-05 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 1_1e-05_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 1_0.0001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 0.001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 1_0.001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1.5 --clip_value 1e-05 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 1.5_1e-05_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1.5 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 1.5_0.0001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1.5 --clip_value 0.001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 1.5_0.001_0.0002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.25 --clip_value 1e-05 --epochs 500 --lr 0.002 --batch_size 1 --prefix 0.25_1e-05_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.25 --clip_value 0.0001 --epochs 500 --lr 0.002 --batch_size 1 --prefix 0.25_0.0001_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.25 --clip_value 0.001 --epochs 500 --lr 0.002 --batch_size 1 --prefix 0.25_0.001_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.5 --clip_value 1e-05 --epochs 500 --lr 0.002 --batch_size 1 --prefix 0.5_1e-05_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.5 --clip_value 0.0001 --epochs 500 --lr 0.002 --batch_size 1 --prefix 0.5_0.0001_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 0.5 --clip_value 0.001 --epochs 500 --lr 0.002 --batch_size 1 --prefix 0.5_0.001_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 1e-05 --epochs 500 --lr 0.002 --batch_size 1 --prefix 1_1e-05_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 0.0001 --epochs 500 --lr 0.002 --batch_size 1 --prefix 1_0.0001_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 0.001 --epochs 500 --lr 0.002 --batch_size 1 --prefix 1_0.001_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1.5 --clip_value 1e-05 --epochs 500 --lr 0.002 --batch_size 1 --prefix 1.5_1e-05_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1.5 --clip_value 0.0001 --epochs 500 --lr 0.002 --batch_size 1 --prefix 1.5_0.0001_0.002_
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1.5 --clip_value 0.001 --epochs 500 --lr 0.002 --batch_size 1 --prefix 1.5_0.001_0.002_
CUDA_VISIBLE_DEVICES="0" python dp_gan.py --noise 2 --clip_value 0.0001 --epochs 500 --lr 2e-05 --batch_size 1 --prefix 2_0.0001_2e-05_ &
CUDA_VISIBLE_DEVICES="0" python dp_gan.py --noise 2 --clip_value 0.00001 --epochs 500 --lr 2e-05 --batch_size 1 --prefix 2_0.00001_2e-05_ &
CUDA_VISIBLE_DEVICES="0" python dp_gan.py --noise 2 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 2_0.0001_2e-05_ &
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 0.0001 --epochs 500 --lr 2e-05 --batch_size 1 --prefix 1_0.0001_2e-05_ &
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 0.00001 --epochs 500 --lr 2e-05 --batch_size 1 --prefix 1_0.00001_2e-05_ &
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 0.0001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 1_0.0001_2e-05_ &
CUDA_VISIBLE_DEVICES="1" python dp_gan.py --noise 1 --clip_value 0.00001 --epochs 500 --lr 0.0002 --batch_size 1 --prefix 1_0.00001_2e-05_ &

0 comments on commit 2014856

Please sign in to comment.