def train(self, epochs, batch_size, sample_interval=50):
    ((X_train, _), (_, _)) = mnist.load_data()
    X_train = ((X_train.astype(np.float32) - 127.5) / 127.5)
    X_train = np.expand_dims(X_train, axis=3)
    valid = (- np.ones((batch_size, 1)))
    fake = np.ones((batch_size, 1))
    dummy = np.zeros((batch_size, 1))
    for epoch in range(epochs):
        for _ in range(self.n_critic):
            idx = np.random.randint(0, X_train.shape[0], batch_size)
            imgs = X_train[idx]
            noise = np.random.normal(0, 1, (batch_size, self.latent_dim))
            d_loss = self.critic_model.train_on_batch([imgs, noise], [valid, fake, dummy])
        g_loss = self.generator_model.train_on_batch(noise, valid)
        print(('%d [D loss: %f] [G loss: %f]' % (epoch, d_loss[0], g_loss)))
        if ((epoch % sample_interval) == 0):
            self.sample_images(epoch)
def train(self, epochs, batch_size, sample_interval=50):
    ((X_train, _), (_, _)) = mnist.load_data()
    X_train = ((X_train.astype(np.float32) - 127.5) / 127.5)
    X_train = np.expand_dims(X_train, axis=3)
    valid = (- np.ones((batch_size, 1)))
    fake = np.ones((batch_size, 1))
    dummy = np.zeros((batch_size, 1))
    for epoch in range(epochs):
        for _ in range(self.n_critic):
            idx = np.random.randint(0, X_train.shape[0], batch_size)
            imgs = X_train[idx]
            noise = np.random.normal(0, 1, (batch_size, self.latent_dim))
            d_loss = self.critic_model.train_on_batch([imgs, noise], [valid, fake, dummy])
        g_loss = self.generator_model.train_on_batch(noise, valid)
        print(('%d [D loss: %f] [G loss: %f]' % (epoch, d_loss[0], g_loss)))
        if ((epoch % sample_interval) == 0):
            self.sample_images(epoch)