CODE PATH
PRO ACCOUNT

Master Code
On The Go

Learn. Practice. Build.

Quest 2 • Lesson 2

🎨 Generative AI (GANs)

Learn how Generative Adversarial Networks create new data – from images to music – by pitting two neural networks against each other.

Generative Adversarial Networks (GANs) consist of two neural networks: a Generator that creates fake data, and a Discriminator that tries to tell real from fake. They compete, improving each other over time.

"Imagine an art forger (Generator) and an art expert (Discriminator). The forger improves until the expert can't tell the difference – that's a GAN at work."

🧠 How GANs Work

🚀 Live Demo: Train a Simple GAN

This GAN learns to generate circles from random noise. Click "Train GAN" to start. Watch the fake images become more realistic.

Real (target)

Generated (fake)

Generator Loss:
Discriminator Loss:
Epoch: 0
Ready. Click "Train GAN" to start.
📘 How the demo works
The GAN is built with TensorFlow.js. The generator takes 10 random numbers and outputs a 10×10 grayscale image (a circle). The discriminator tries to classify images as real or fake. After training, you can see the generator producing increasingly realistic circles.
gan.py
# Generator: noise → image
generator = Sequential([
  Dense(128, activation='relu', input_shape=[10]),
  Dense(100, activation='sigmoid'),
])

# Discriminator: image → real/fake
discriminator = Sequential([
  Dense(64, activation='relu', input_shape=[100]),
  Dense(1, activation='sigmoid'),
])

# Adversarial training loop
for epoch in range(num_epochs):
  noise = random.normal(0, 1, (batch_size, 10))
  fake_images = generator.predict(noise)
  real_images = get_real_images()
  disc_loss = discriminator.train_on_batch(real_images, ones) + discriminator.train_on_batch(fake_images, zeros)
  gen_loss = gan.train_on_batch(noise, ones)

✨ Challenge: Improve the GAN

Try modifying the GAN architecture:

➡️ Next Lesson

Lesson 2.3: AI in Production – deploy your AI models.

Continue to Lesson 2.3 →

(Coming soon – check back or buy Pro Pack for early access)

❤️ Support Free Education

This course is 100% free. If it helps you, consider buying me a coffee.

☕ Buy Me a Coffee
← Back to AI Course Hub