Ejemplo n.º 1
0
    def train(self, epochs, batch_size=128, sample_interval=50):

        # Load the dataset
        loader = Loader('faces94/malestaff/voudcx', 'faces94/malestaff/tony')
        img_a, img_b = loader.get_all()
        assert img_a.shape[0] == batch_size

        # Adversarial ground truths
        valid = np.ones((batch_size, 1), dtype=np.float32)
        fake = np.zeros((batch_size, 1), dtype=np.float32)

        for epoch in range(epochs):

            # ---------------------
            #  Train Discriminator
            # ---------------------

            # Train the discriminator
            
            img_fake, _ = self.adversarial_autoencoder.predict([img_a, img_b])
            save_img('fake.jpg', img_fake[10])
            history_real = self.discriminator.fit(img_b, valid, batch_size=batch_size)
            history_fake = self.discriminator.fit(img_a, fake, batch_size=batch_size)
            d_loss_real = history_real.history['loss']
            d_loss_fake = history_fake.history['loss']
            d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)

            # ---------------------
            #  Train Generator
            # ---------------------

            # Train the generator
            history_g = self.adversarial_autoencoder.fit([img_a, img_b], [img_b, valid], batch_size=batch_size)
            g_loss = history_g.history['loss']
            print(history_g.history.keys())

            # Plot the progress
            #print ("%d [D loss: %f] [G loss: %f, mse: %f]" % (epoch, d_loss[0], 100*d_loss[1], g_loss[0], g_loss[1]))
            print ("%d [D loss: %f] [G loss: %f]" % (epoch, d_loss[0], g_loss[0]))
Ejemplo n.º 2
0
from loader import Loader

loader = Loader('faces94/malestaff/voudcx', 'faces94/malestaff/tony')
a, b = loader.get_all()
print(a.shape)
print(b.shape)
Ejemplo n.º 3
0
        print(e)
exit()
BATCH_SIZE = 256
BUFFER_SIZE = 60000
EPOCHES = 300
OUTPUT_DIR = "img"  # The output directory where the images of the generator a stored during training
ROW = 200
COL = 180
CHANNEL = 3

directory = 'img/'
path_a = 'faces94/malestaff/tony/'
path_b = 'faces94/malestaff/voudcx/'
AB_loader = Loader(path_a, path_b)

train_images_a, train_images_b = AB_loader.get_all()
assert train_images_a[0].shape == (ROW, COL, CHANNEL)

train_dataset = tf.data.Dataset.from_tensor_slices(
    (train_images_a, train_images_b)).shuffle(BUFFER_SIZE).batch(BATCH_SIZE)

# ## Generator Network


class Generator(keras.Model):
    def __init__(self):
        super().__init__(name='generator')
        #layers
        self.input_layer_a = keras.layers.Conv2D(16,
                                                 3,
                                                 padding='same',