Generative Adversarial Networks Cookbook
eBook - ePub

Generative Adversarial Networks Cookbook

Over 100 recipes to build generative models using Python, TensorFlow, and Keras

Josh Kalin

  1. 268 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Generative Adversarial Networks Cookbook

Over 100 recipes to build generative models using Python, TensorFlow, and Keras

Josh Kalin

Book details
Book preview
Table of contents
Citations

About This Book

Simplify next-generation deep learning by implementing powerful generative models using Python, TensorFlow and Keras

Key Features

  • Understand the common architecture of different types of GANs
  • Train, optimize, and deploy GAN applications using TensorFlow and Keras
  • Build generative models with real-world data sets, including 2D and 3D data

Book Description

Developing Generative Adversarial Networks (GANs) is a complex task, and it is often hard to find code that is easy to understand.

This book leads you through eight different examples of modern GAN implementations, including CycleGAN, simGAN, DCGAN, and 2D image to 3D model generation. Each chapter contains useful recipes to build on a common architecture in Python, TensorFlow and Keras to explore increasingly difficult GAN architectures in an easy-to-read format. The book starts by covering the different types of GAN architecture to help you understand how the model works. This book also contains intuitive recipes to help you work with use cases involving DCGAN, Pix2Pix, and so on. To understand these complex applications, you will take different real-world data sets and put them to use.

By the end of this book, you will be equipped to deal with the challenges and issues that you may face while working with GAN models, thanks to easy-to-follow code solutions that you can implement right away.

What you will learn

  • Structure a GAN architecture in pseudocode
  • Understand the common architecture for each of the GAN models you will build
  • Implement different GAN architectures in TensorFlow and Keras
  • Use different datasets to enable neural network functionality in GAN models
  • Combine different GAN models and learn how to fine-tune them
  • Produce a model that can take 2D images and produce 3D models
  • Develop a GAN to do style transfer with Pix2Pix

Who this book is for

This book is for data scientists, machine learning developers, and deep learning practitioners looking for a quick reference to tackle challenges and tasks in the GAN domain. Familiarity with machine learning concepts and working knowledge of Python programming language will help you get the most out of the book.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on ā€œCancel Subscriptionā€ - itā€™s as simple as that. After you cancel, your membership will stay active for the remainder of the time youā€™ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlegoā€™s features. The only differences are the price and subscription period: With the annual plan youā€™ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weā€™ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Generative Adversarial Networks Cookbook an online PDF/ePUB?
Yes, you can access Generative Adversarial Networks Cookbook by Josh Kalin in PDF and/or ePUB format, as well as other popular books in Computer Science & Neural Networks. We have over one million books available in our catalogue for you to explore.

Information

Year
2018
ISBN
9781789139587
Edition
1

Data First, Easy Environment, and Data Prep

In this chapter, we'll cover the following recipes:
  • Is data that important?
  • But first, set up your development environment
  • Data types
  • Data preprocessing
  • Anomalous data
  • Balancing data
  • Data augmentation

Introduction

Data can make or break your machine learning (ML) algorithm. This chapter will lay the basic ground work for manipulating data, augmenting data, and balancing imbalanced datasets or data with massive outliers. Each recipe will provide a guide on how to use open source libraries to accelerate our Generative Adversarial Network (GAN) training.

Is data that important?

Data is the lifeblood of ML algorithms. Your models will only be as good as the data you provide to them. After all, you are what you eat. We have to focus on developing a good, clean dataset for learning. This begins with getting an environment set up and preparing the data to be ingested into an algorithm. We do have a fundamental advantage within this process because GANs can take considerably smaller sets of data than other techniques. This advantage comes with the explicit caveat that we will need to ensure that the data we're using encompasses the entire trade space of possibilities for our application.

Getting ready

One of the deep dark secrets they don't teach you about this field is that you're going to spend a large chunk of your time preparing the data (sometimes as much as 75% of a project). I've had people ask me over the years why data preparation can absorb so much time and the answer really is simple:
Garbage in -> Garbage out
Data will drive your project to success or failure. It's imperative that we are diligent in exploring the data we have available and using the right portion of the data for learning.

How to do it...

We have to build a pipeline that includes the following components:
  • Data preprocessing
  • Balancing data
  • Anomalous data
  • Data augmentation
These four concepts make up the cornerstone of this chapter. As we work through examples in each of these domains, you'll see that each contribution is important to ensuring your model is learning the right traits and qualities.
Let's start with a simple example of how we could apply all of these basic technologies. We'll focus on introducing the concepts, then the rest of this chapter will focus on the practical implementation of these concepts. Basically, this is going to be the template that we are going to fill in piece-by-piece:
These are the steps for producing a data processing pipeline:
  1. Read in data as a NumPy array
  2. Check the distribution of the data for anomalous indices
  3. Balance the dataset for the learning step
  4. Throw out the anomalous data
  5. Augment our data in an structured and intelligent manner

How it works...

The next few recipes will focus on filling in the code to produce this pipeline for data parsing. The pipeline recipe will walk you through the steps to make this pipeline into a class that we can use as a template in future chapters.

There's more...

The topics in this chapter are going to be the beginning of our journey into the different processing techniques for deep learning data processing. A large part of the job of deep learning practitioners is the data parsing part of the job. We need to take it seriously in order to ensure our models are learning from the right data. Throughout this book, you'll understand that the data parsing is a critical component of getting GANs to converge and to get decent results out of these models. Architecture is far from the only thing that can affect our learners.
There's an expansive set of examples that you will be exposed to during the course of this chapter. The key reading in the beginning is to understand the tools you'll need to run the code with this Docker overview found here: https://docs.docker.com/engine/docker-overview/.
We also recommend you read up on Python, NumPy, and SciPy:
  • Python: https://wiki.python.org/moin/BeginnersGuide/Overview
  • NumPy: https://docs.scipy.org/doc/numpy/
  • SciPy: https://www.scipy.org/getting-started.html
I will emphasize here that the expectation is that you have a baseline understanding of these techniques. These links are meant strictly as a reference.

But first, set up your development environment

What's a development environment? Everyone thinks setting up a development environment needs to be this incredibly arduous process. The installation process could be worse. It's actually quite simple and I intend to show you the basics in this recipe.

Getting ready

Let's lay out the requirements for the equipment you'll need to be successful in this book:
  • GPU: 10 series CUDA-enabled Nidea GPU
  • Operating system: Ubuntu Linux 16.04+
  • CPU/RAM: i5 or i7 with at least 8 GB of RAM
First and foremost, the GPU is a requirement for this type of book. Although these algorithms can technically train on a CPU, it could take days in some cases for a single model to converge. It can take a GPU a day or more to converge in some instances. GPUs offer an immense computational power increase over CPUs and hence are a necessity to ensure that you get the most out of this book. It's easy today to find a laptop with a 1,060 or better in it for around $900.
Ubuntu is the typical operating system for this type of development. This book will assume Ubuntu and Bash as the default interaction with the operating system. All examples will revolve around the assumption that you have Ubuntu installed and the correct hardware inside your computer. This portion of this book will break down the basic pieces needed to be successful.

How to do it...

There are a few common steps that will need to be for each new developerā€”these steps will be addressed in the following subsections of installing an NVIDIA driver, installing the NVIDIA-Docker solution, and building a common container for development, in the next chapters.

Installing the NVIDIA driver for your GPU

Installing the correct NVIDIA driver is incredibly important. A key component to all of these implementations is the usage of CUDA in TensorFlow. NVIDIA has this description for the CUDA library:
"CUDAĀ® is a parallel computing platform and programming model developed by NVIDIA for general computing on graphical processing units (GPUs). With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs." (Source: https://developer.nvidia.com/cuda-zone).
Using CUDA, TensorFlow can achieve drastic speedups in terms of processing power. In order to make this happen, we need to have a certain type of GPU and driver installed on the host machine.
So, let's start installing the things that we require.
In this section, a recommended driver will be specified and a few options for installation will be proposed. It's hard to ensure that the installation will be the same for each developer because the installation can vary for each machine it's installed on. Instead, we'll show some methods on how to get it done but wil...

Table of contents

Citation styles for Generative Adversarial Networks Cookbook

APA 6 Citation

Kalin, J. (2018). Generative Adversarial Networks Cookbook (1st ed.). Packt Publishing. Retrieved from https://www.perlego.com/book/868338/generative-adversarial-networks-cookbook-over-100-recipes-to-build-generative-models-using-python-tensorflow-and-keras-pdf (Original work published 2018)

Chicago Citation

Kalin, Josh. (2018) 2018. Generative Adversarial Networks Cookbook. 1st ed. Packt Publishing. https://www.perlego.com/book/868338/generative-adversarial-networks-cookbook-over-100-recipes-to-build-generative-models-using-python-tensorflow-and-keras-pdf.

Harvard Citation

Kalin, J. (2018) Generative Adversarial Networks Cookbook. 1st edn. Packt Publishing. Available at: https://www.perlego.com/book/868338/generative-adversarial-networks-cookbook-over-100-recipes-to-build-generative-models-using-python-tensorflow-and-keras-pdf (Accessed: 14 October 2022).

MLA 7 Citation

Kalin, Josh. Generative Adversarial Networks Cookbook. 1st ed. Packt Publishing, 2018. Web. 14 Oct. 2022.