aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2019-03-05 14:32:38 +0000
committerVasil Zlatanov <v@skozl.com>2019-03-05 14:32:38 +0000
commit6b573a30a3021d259400af9751645eb1a5b4705b (patch)
tree09d68aa13d19062369f5044bf246ddd89a579fdb
parent740e1b0c6a02a7bec20008758373f0dd80baade4 (diff)
parent2a720c237259baa2d968286244f9e43794c7e4d9 (diff)
downloade4-gan-6b573a30a3021d259400af9751645eb1a5b4705b.tar.gz
e4-gan-6b573a30a3021d259400af9751645eb1a5b4705b.tar.bz2
e4-gan-6b573a30a3021d259400af9751645eb1a5b4705b.zip
Full featured VBN
-rw-r--r--cgan.py6
-rw-r--r--dcgan.py4
-rw-r--r--lenet.py2
3 files changed, 6 insertions, 6 deletions
diff --git a/cgan.py b/cgan.py
index b9928f0..45b9bb9 100644
--- a/cgan.py
+++ b/cgan.py
@@ -113,7 +113,7 @@ class CGAN():
return Model([img, label], validity)
- def train(self, epochs, batch_size=128, sample_interval=50, graph=False):
+ def train(self, epochs, batch_size=128, sample_interval=50, graph=False, smooth_real=1, smooth_fake=0):
# Load the dataset
(X_train, y_train), (_, _) = mnist.load_data()
@@ -147,8 +147,8 @@ class CGAN():
gen_imgs = self.generator.predict([noise, labels])
# Train the discriminator
- d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid)
- d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], fake)
+ d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid*smooth_real)
+ d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], valid*smooth_fake)
d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
# ---------------------
diff --git a/dcgan.py b/dcgan.py
index eca1852..8a1bc2b 100644
--- a/dcgan.py
+++ b/dcgan.py
@@ -124,7 +124,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()
@@ -139,6 +139,7 @@ class DCGAN():
xaxis = np.arange(epochs)
loss = np.zeros((2,epochs))
+
for epoch in tqdm(range(epochs)):
# ---------------------
@@ -150,7 +151,6 @@ class DCGAN():
imgs = X_train[idx]
tf.keras.backend.get_session().run(tf.global_variables_initializer())
-
# 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)
diff --git a/lenet.py b/lenet.py
index a38f4e1..c1c27b5 100644
--- a/lenet.py
+++ b/lenet.py
@@ -125,8 +125,8 @@ def test_classifier(model, x_test, y_true):
y_pred = model.predict(x_test)
y_pred = np.argmax(y_pred, axis=1)
y_true = np.argmax(y_true, axis=1)
- print("Test acc:", accuracy_score(y_true, y_pred))
plot_example_errors(y_pred, y_true, x_test)
+ return accuracy_score(y_true, y_pred)
def mix_data(X_train, y_train, X_validation, y_validation, train_gen, tr_labels_gen, val_gen, val_labels_gen, split=0):