aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornunzip <np.scarh@gmail.com>2019-03-04 23:26:45 +0000
committernunzip <np.scarh@gmail.com>2019-03-04 23:26:45 +0000
commit21e16309d54fd2a31fdbf7fb470c3d70b38d1c65 (patch)
treecce7865c9fb2ad7a9e3de14602cd9e33fd17a463
parent34057507d6b7ae5cafd2b7b8cb2b69c20780ffd5 (diff)
downloade4-gan-21e16309d54fd2a31fdbf7fb470c3d70b38d1c65.tar.gz
e4-gan-21e16309d54fd2a31fdbf7fb470c3d70b38d1c65.tar.bz2
e4-gan-21e16309d54fd2a31fdbf7fb470c3d70b38d1c65.zip
Attempt virtual batch normalization
-rw-r--r--dcgan.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/dcgan.py b/dcgan.py
index bc7e14e..61c0b48 100644
--- a/dcgan.py
+++ b/dcgan.py
@@ -112,7 +112,7 @@ class DCGAN():
return Model(img, validity)
- def train(self, epochs, batch_size=128, save_interval=50):
+ def train(self, epochs, batch_size=128, save_interval=50, VBN=False):
# Load the dataset
(X_train, _), (_, _) = mnist.load_data()
@@ -127,6 +127,7 @@ class DCGAN():
xaxis = np.arange(epochs)
loss = np.zeros((2,epochs))
+
for epoch in tqdm(range(epochs)):
# ---------------------
@@ -137,6 +138,14 @@ class DCGAN():
idx = np.random.randint(0, X_train.shape[0], batch_size)
imgs = X_train[idx]
+ if VBN:
+ idx = np.random.randint(0, X_train.shape[0], batch_size)
+ ref_imgs = X_train[idx]
+ mu = np.mean(ref_imgs, axis=0)
+ sigma = np.var(ref_imgs, axis=0)
+ sigma[sigma<1] = 1
+ img = np.divide(np.subtract(img, mu), sigma)
+
# Sample noise and generate a batch of new images
noise = np.random.normal(0, 1, (batch_size, self.latent_dim))
gen_imgs = self.generator.predict(noise)