Hands-On Generative Adversarial Networks with Keras

Book description

Develop generative models for a variety of real-world use cases and deploy them to production

Key Features

  • Discover various GAN architectures using a Python and Keras library
  • Understand how GAN models function with the help of theoretical and practical examples
  • Apply your learnings to become an active contributor to open source GAN applications

Book Description

Generative Adversarial Networks (GANs) have revolutionized the fields of machine learning and deep learning. This book will be your first step toward understanding GAN architectures and tackling the challenges involved in training them.

This book opens with an introduction to deep learning and generative models and their applications in artificial intelligence (AI). You will then learn how to build, evaluate, and improve your first GAN with the help of easy-to-follow examples. The next few chapters will guide you through training a GAN model to produce and improve high-resolution images. You will also learn how to implement conditional GANs that enable you to control characteristics of GAN output. You will build on your knowledge further by exploring a new training methodology for progressive growing of GANs. Moving on, you'll gain insights into state-of-the-art models in image synthesis, speech enhancement, and natural language generation using GANs. In addition to this, you'll be able to identify GAN samples with TequilaGAN.

By the end of this book, you will be well-versed with the latest advancements in the GAN framework using various examples and datasets, and you will have developed the skills you need to implement GAN architectures for several tasks and domains, including computer vision, natural language processing (NLP), and audio processing.

Foreword by Ting-Chun Wang, Senior Research Scientist, NVIDIA

What you will learn

  • Discover how GANs work and the advantages and challenges of working with them
  • Control the output of GANs with the help of conditional GANs, using embedding and space manipulation
  • Apply GANs to computer vision, natural language processing (NLP), and audio processing
  • Understand how to implement progressive growing of GANs
  • Use GANs for image synthesis and speech enhancement
  • Explore the future of GANs in visual and sonic arts
  • Implement pix2pixHD to turn semantic label maps into photorealistic images

Who this book is for

This book is for machine learning practitioners, deep learning researchers, and AI enthusiasts who are looking for a mix of theory and hands-on content to implement GANs using Keras. Working knowledge of Python is expected.

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Generative Adversarial Networks with Keras
  3. About Packt
    1. Why subscribe?
    2. Packt.com
  4. Foreword
  5. Contributors
    1. About the author
    2. About the reviewer
    3. Packt is searching for authors like you
  6. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  7. Section 1: Introduction and Environment Setup
  8. Deep Learning Basics and Environment Setup
    1. Deep learning basics
      1. Artificial Neural Networks (ANNs)
      2. The parameter estimation
      3. Backpropagation
      4. Loss functions
        1. L1 loss
        2. L2 loss
        3. Categorical crossentropy loss
      5. Non-linearities
        1. Sigmoid
        2. Tanh
        3. ReLU
      6. A fully connected layer
      7. The convolution layer
      8. The max pooling layer
    2. Deep learning environment setup
      1. Installing Anaconda and Python
      2. Setting up a virtual environment in Anaconda
      3. Installing TensorFlow
      4. Installing Keras
      5. Installing data visualization and machine learning libraries
        1. The matplotlib library
        2. The Jupyter library
        3. The scikit-learn library
      6. NVIDIA's CUDA Toolkit and cuDNN
    3. The deep learning environment test
    4. Summary
  9. Introduction to Generative Models
    1. Discriminative and generative models compared
      1. Comparing discriminative and generative models
    2. Generative models
      1. Autoregressive models
      2. Variational autoencoders
      3. Reversible flows
      4. Generative adversarial networks
    3. GANs – building blocks
      1. The discriminator
      2. The generator
      3. Real and fake data
      4. Random noise
      5. Discriminator and generator loss
    4. GANs – strengths and weaknesses
    5. Summary
  10. Section 2: Training GANs
  11. Implementing Your First GAN
    1. Technical requirements
    2. Imports
    3. Implementing a Generator and Discriminator
      1. Generator
      2. Discriminator
    4. Auxiliary functions
    5. Training your GAN
    6. Summary
    7. Further reading
  12. Evaluating Your First GAN
    1. The evaluation of GANs
      1. Image quality
      2. Image variety
      3. Domain specifications
    2. Qualitative methods
      1. k-nearest neighbors
      2. Mode analysis
      3. Other methods
    3. Quantitative methods
      1. The Inception score
      2. The Frechét Inception Distance 
      3. Precision, Recall, and the F1 Score
    4. GANs and the birthday paradox
    5. Summary
  13. Improving Your First GAN
    1. Technical requirements
    2. Challenges in training GANs
      1. Mode collapse and mode drop
      2. Training instability
      3. Sensitivity to hyperparameter initialization
      4. Vanishing gradients
    3. Tricks of the trade
      1. Tracking failure
      2. Working with labels
      3. Working with discrete inputs
      4. Adding noise
      5. Input normalization
      6. Modified objective function
      7. Distribute latent vector
      8. Weight normalization
      9. Avoid sparse gradients
      10. Use a different optimizer
      11. Learning rate schedule
    4. GAN model architectures
      1. ResNet GAN
    5. GAN algorithms and loss functions
      1. Least Squares GAN
      2. Wasserstein GAN
      3. Wasserstein GAN with gradient penalty
      4. Relativistic GAN
    6. Summary
  14. Section 3: Application of GANs in Computer Vision, Natural Language Processing, and Audio
  15. Progressive Growing of GANs
    1. Technical requirements
    2. Progressive Growing of GANs
      1. Increasing variation using minibatch standard deviation
      2. Normalization in the generator and the discriminator
      3. Pixelwise feature vector normalization in the generator
    3. Experimental setup
      1. Training
        1. Helper functions
        2. Initializations
        3. Training loops
    4. Model implementation
      1. Custom layers
      2. The discriminator
      3. The generator
      4. GANs
    5. Summary
  16. Generation of Discrete Sequences Using GANs
    1. Technical requirements
    2. Natural language generation with GANs
    3. Experimental setup
      1. Data
      2. Auxiliary training functions
      3. Training
        1. Imports and global variables
        2. Initializations
        3. Training loop
      4. Logging
    4. Model implementation
      1. Helper functions
      2. Discriminator
      3. Generator
    5. Inference
      1. Model trained on words
      2. Model trained on characters
    6. Summary
  17. Text-to-Image Synthesis with GANs
    1. Technical Requirements
    2. Text-to-image synthesis
    3. Experimental setup
      1. Data utils
      2. Logging utils
      3. Training
        1. Initial setup
        2. The training loop
    4. Model implementation
      1. Wrapper
      2. Discriminator
      3. Generator
    5. Improving the baseline model
      1. Training
    6. Inference
      1. Sampling the generator
      2. Interpolation in the Latent Space
      3. Interpolation in the text-embedding space
      4. Inferencing with arithmetic in the text-embedding space
    7. Summary
  18. TequilaGAN - Identifying GAN Samples
    1. Technical requirements
    2. Identifying GAN samples
      1. Related work
    3. Feature extraction
      1. Centroid
      2. Slope
    4. Metrics
      1. Jensen-Shannon divergence
      2. Kolgomorov-Smirnov Two-Sample test
    5. Experiments
      1. MNIST
    6. Summary
    7. References
  19. Whats next in GANs
    1. What we've GANed so far
      1. Generative models
      2. Architectures
      3. Loss functions
      4. Tricks of the trade
      5. Implementations
    2. Unanswered questions in GANs
      1. Are some losses better than others?
      2. Do GANs do distribution learning?
      3. All about that inductive bias
      4. How can you kill a GAN?
    3. Artistic GANs
      1. Visual arts
        1. GANGogh
        2. Image inpainting
        3. Vid2Vid
        4. GauGAN
      2. Sonic arts
        1. MuseGAN
        2. GANSynth
    4. Recent and yet-to-be-explored GAN topics
    5. Summary
    6. Closing remarks
    7. Further reading

Product information

  • Title: Hands-On Generative Adversarial Networks with Keras
  • Author(s): Rafael Valle
  • Release date: May 2019
  • Publisher(s): Packt Publishing
  • ISBN: 9781789538205