zoo/dcgan/dcgan_c.py
def train(self, images, latent=100, epochs=4000, batch_size=128, save_interval=50):
        """ Train the GAN
            images : images from the training data
            latent : dimension of the latent space
            
            credit: https://github.com/eriklindernoren
        """
        # Adversarial ground truths
        valid_labels = np.ones ((batch_size, 1))
        fake_labels  = np.zeros((batch_size, 1))

        for epoch in range(epochs):

            #  Train the Discriminator

            # Select a random half of the images
            idx   = np.random.randint(0, images.shape[0], batch_size)
            batch = images[idx]

            # Sample noise and generate a batch of new images
            noise = np.random.normal(0, 1, (batch_size, latent))
            fakes = self.g.predict(noise)

            # Train the discriminator (real classified as ones and generated as zeros)
            d_loss_real = self.d.train_on_batch(batch, valid_labels)
            d_loss_fake = self.d.train_on_batch(fakes, fake_labels)
            d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
            
            #  Train the Generator

            # Train the generator (wants discriminator to mistake images as real)
            g_loss = self.model.train_on_batch(noise, valid_labels)

            # Plot the progress
            print ("%d [D loss: %f, acc.: %.2f%%] [G loss: %f]" % (epoch, d_loss[0], 100*d_loss[1], g_loss))


            # If at save interval => save generated image samples
            if epoch % save_interval == 0:
                self.save_imgs(epoch)
 Train the GAN
            images : images from the training data
            latent : dimension of the latent space
            
            credit: https://github.com/eriklindernoren
        
Train the GAN
images : images from the training data
latent : dimension of the latent space


Train the GAN images : images from the training data latent : dimension of the latent space
def train(self, images, latent=100, epochs=4000, batch_size=128, save_interval=50):
        valid_labels = np.ones ((batch_size, 1))
        fake_labels  = np.zeros((batch_size, 1))
        for epoch in range(epochs):
            idx   = np.random.randint(0, images.shape[0], batch_size)
            batch = images[idx]
            noise = np.random.normal(0, 1, (batch_size, latent))
            fakes = self.g.predict(noise)
            d_loss_real = self.d.train_on_batch(batch, valid_labels)
            d_loss_fake = self.d.train_on_batch(fakes, fake_labels)
            d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
            g_loss = self.model.train_on_batch(noise, valid_labels)
            print ("%d [D loss: %f, acc.: %.2f%%] [G loss: %f]" % (epoch, d_loss[0], 100*d_loss[1], g_loss))
            if epoch % save_interval == 0:
                self.save_imgs(epoch)
def train ( self , images , latent = 100 , epochs = 4000 , batch_size = 128 , save_interval = 50 ) : valid_labels = np . ones ( ( batch_size , 1 ) ) fake_labels = np . zeros ( ( batch_size , 1 ) ) for epoch in range ( epochs ) : idx = np . random . randint ( 0 , images . shape [ 0 ] , batch_size ) batch = images [ idx ] noise = np . random . normal ( 0 , 1 , ( batch_size , latent ) ) fakes = self . g . predict ( noise ) d_loss_real = self . d . train_on_batch ( batch , valid_labels ) d_loss_fake = self . d . train_on_batch ( fakes , fake_labels ) d_loss = 0.5 * np . add ( d_loss_real , d_loss_fake ) g_loss = self . model . train_on_batch ( noise , valid_labels ) print ( "%d [D loss: %f, acc.: %.2f%%] [G loss: %f]" % ( epoch , d_loss [ 0 ] , 100 * d_loss [ 1 ] , g_loss ) ) if epoch % save_interval == 0 : self . save_imgs ( epoch )
Train the GAN
images : images from the training data
latent : dimension of the latent space
Train the GAN images : images from the training data latent : dimension of the latent space
""" Train the GAN
            images : images from the training data
            latent : dimension of the latent space
            
            credit: https://github.com/eriklindernoren
        """ # Adversarial ground truths #  Train the Discriminator # Select a random half of the images # Sample noise and generate a batch of new images # Train the discriminator (real classified as ones and generated as zeros) #  Train the Generator # Train the generator (wants discriminator to mistake images as real) # Plot the progress # If at save interval => save generated image samples
self
images
latent
epochs
batch_size
save_interval