Book Image

Advanced Deep Learning with Keras

By : Rowel Atienza
Book Image

Advanced Deep Learning with Keras

By: Rowel Atienza

Overview of this book

Recent developments in deep learning, including Generative Adversarial Networks (GANs), Variational Autoencoders (VAEs), and Deep Reinforcement Learning (DRL) are creating impressive AI results in our news headlines - such as AlphaGo Zero beating world chess champions, and generative AI that can create art paintings that sell for over $400k because they are so human-like. Advanced Deep Learning with Keras is a comprehensive guide to the advanced deep learning techniques available today, so you can create your own cutting-edge AI. Using Keras as an open-source deep learning library, you'll find hands-on projects throughout that show you how to create more effective AI with the latest techniques. The journey begins with an overview of MLPs, CNNs, and RNNs, which are the building blocks for the more advanced techniques in the book. You’ll learn how to implement deep learning models with Keras and TensorFlow 1.x, and move forwards to advanced techniques, as you explore deep neural network architectures, including ResNet and DenseNet, and how to create autoencoders. You then learn all about GANs, and how they can open new levels of AI performance. Next, you’ll get up to speed with how VAEs are implemented, and you’ll see how GANs and VAEs have the generative power to synthesize data that can be extremely convincing to humans - a major stride forward for modern AI. To complete this set of advanced techniques, you'll learn how to implement DRL such as Deep Q-Learning and Policy Gradient Methods, which are critical to many modern results in AI.
Table of Contents (16 chapters)
Advanced Deep Learning with Keras
Contributors
Preface
Other Books You May Enjoy
Index

Preface

In recent years, deep learning has made unprecedented success stories in difficult problems in vision, speech, natural language processing and understanding, and all other areas with abundance of data. The interest in this field by companies, universities, governments, and research organizations has accelerated the advances in the field. This book covers select important advances in deep learning. The advanced theories are explained by giving a background of the principles, digging into the intuition behind the concepts, implementing the equations and algorithms using Keras, and examining the results.

Artificial Intelligence (AI), as it stands today, is still far from being a well-understood field. Deep learning, as a sub field of AI, is in the same position. While it is far from being a mature field, many real-world applications such as vision-based detection and recognition, product recommendation, speech recognition and synthesis, energy conservation, drug discovery, finance, and marketing are already using deep learning algorithms. Many more applications will be discovered and built. The aim of this book is to explain advanced concepts, give sample implementations, and let the readers, as experts in their field, identify the target applications.

A field that is not completely mature is a double-edged sword. On one edge, it offers a lot of opportunities for discovery and exploitation. There are many unsolved problems in deep learning. This translates into opportunities to be the first to market – product development, publication, or recognition. The other edge is that it would be difficult to trust a not completely well-understood field in a mission-critical environment. We can safely say that if asked, very few machine learning engineers will ride an auto-pilot plane controlled by a deep learning system. There is a lot of work to be done to gain this level of trust. The advanced concepts that are discussed in this book have a high chance of playing a major role as the foundation in gaining this level of trust.

Every book in deep learning will not be able to completely cover the whole field. This book is not an exception. Given the time and space, we could have touched interesting areas such as detection, segmentation and recognition, visual understanding, probabilistic reasoning, natural language processing and understanding, speech synthesis, and automated machine learning. However, this book believes in choosing and explaining select areas so that readers can take up other fields that are not covered.

As the reader is about to read the rest of this book, they need to keep in mind that they chose an area that is exciting and can have a huge impact on the society. We are fortunate to have a job that we look forward to working on as we wake up in the morning.

Who this book is for

The book is intended for machine learning engineers and students who would like to gain a better understanding of advanced topics in deep learning. Each discussion is supplemented with code implementation in Keras. This book is for readers who would like to understand how to translate theory into a working code implementation in Keras. Apart from understanding theories, code implementation is usually one of the difficult tasks in applying machine learning to real-world problems.

What this book covers

Chapter 1, Introducing Advanced Deep Learning with Keras, covers the key concepts of deep learning such as optimization, regularization, loss functions, fundamental layers, and networks and their implementation in Keras. This chapter also serves as a review of both deep learning and Keras using sequential API.

Chapter 2, Deep Neural Networks, discusses the functional API of Keras. Two widely-used deep network architectures, ResNet and DenseNet, are examined and implemented in Keras, using functional API.

Chapter 3, Autoencoders, covers a common network structure called autoencoder that is used to discover the latent representation of the input data. Two example applications of autoencoders, denoising and colorization, are discussed and implemented in Keras.

Chapter 4, Generative Adversarial Networks (GANs), discusses one of the recent significant advances in deep learning. GAN is used to generate new synthetic data that appear real. This chapter explains the principles of GAN. Two examples of GAN, DCGAN and CGAN, are examined and implemented in Keras.

Chapter 5, Improved GANs, covers algorithms that improve the basic GAN. The algorithms address the difficulty in training GANs and improve the perceptual quality of synthetic data. WGAN, LSGAN, and ACGAN are discussed and implemented in Keras.

Chapter 6, Disentangled Representation GANs, discusses how to control the attributes of the synthetic data generated by GANs. The attributes can be controlled if the latent representations are disentangled. Two techniques in disentangling representations, InfoGAN and StackedGAN, are covered and implemented in Keras.

Chapter 7, Cross-Domain GANs, covers a practical application of GANs, translating images from one domain to another or commonly known as cross-domain transfer. CycleGAN, a widely used cross-domain GAN, is discussed and implemented in Keras. This chapter also demonstrates CycleGAN performing colorization and style transfer.

Chapter 8, Variational Autoencoders (VAEs), discusses another recent significant advance in deep learning. Similar to GAN, VAE is a generative model that is used to produce synthetic data. Unlike GAN, VAE focuses on decodable continuous latent space that is suitable for variational inference. VAE and its variations, CVAE and -VAE, are covered and implemented in Keras.

Chapter 9, Deep Reinforcement Learning, explains the principles of reinforcement learning and Q-Learning. Two techniques in implementing Q-Learning for discrete action spaces are presented, Q Table update and Deep Q Network (DQN). Implementation of Q-Learning using Python and DQN in Keras are demonstrated in OpenAI gym environments.

Chapter 10, Policy Gradient Methods, explains how to use neural networks to learn the policy for decision making in reinforcement learning. Four methods are covered and implemented in Keras and OpenAI gym environment, REINFORCE, REINFORCE with Baseline, Actor-Critic, and Advantage Actor-Critic. The example presented in this chapter demonstrates policy gradient methods on a continuous action space.

To get the most out of this book

  • Deep learning and Python: The reader should have a fundamental knowledge of deep learning and its implementation in Python. While previous experience in using Keras to implement deep learning algorithms is important, it is not required. Chapter 1, Introducing Advanced Deep Learning with Keras offers a review of deep learning concepts and their implementation in Keras.

  • Math: The discussions in this book assume that the reader is familiar with calculus, linear algebra, statistics, and probability at the college level.

  • GPU: Majority of the Keras implementations in this book require GPU. Without GPU, it is not practical to execute many of the code examples because of the time involved (many hours to days). The examples in this book use reasonable data size as much as possible in order to minimize the use of high-performance computers. The reader is expected to have access to at least NVIDIA GTX 1060.

  • Editor: The code examples in this book were edited using vim in Ubuntu Linux 16.04 LTS, Ubuntu Linux 17.04, and macOS High Sierra. Any Python-aware text editor is acceptable.

  • Tensorflow: Keras requires a backend. The code examples in this book were written in Keras with TensorFlow backend. Please ensure that the GPU driver and tensorflow are both installed properly.

  • GitHub: We learn by example and experimentation. Please git pull or fork the code bundle for the book from its GitHub repository. After getting the code, examine it. Run it. Change it. Run it again. Do all creative experiments by tweaking the code examples. It is the only way to appreciate all the theories explained in the chapters. Giving a star on the book GitHub repository is also highly appreciated.

Download the example code files

The code bundle for the book is hosted on GitHub at

https://github.com/PacktPublishing/Advanced-Deep-Learning-with-Keras

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781788629416_ColorImages.pdf.

Conventions used

The code examples in this book are in Python. More specifically, python3. The color scheme is based on vim syntax highlighting. Consider the following example:

def encoder_layer(inputs,
                  filters=16,
                  kernel_size=3,
                  strides=2,
                  activation='relu',
                  instance_norm=True):
    """Builds a generic encoder layer made of Conv2D-IN-LeakyReLU
    IN is optional, LeakyReLU may be replaced by ReLU

    """

    conv = Conv2D(filters=filters,
                  kernel_size=kernel_size,
                  strides=strides,
                  padding='same')

    x = inputs
    if instance_norm:
        x = InstanceNormalization()(x)
    if activation == 'relu':
        x = Activation('relu')(x)
    else:
        x = LeakyReLU(alpha=0.2)(x)
    x = conv(x)
    return x

Whenever possible, docstring is included. At the very least, text comment is used to minimize space usage.

Any command-line code execution is written as follows:

$ python3 dcgan-mnist-4.2.1.py

The example code file naming is: algorithm-dataset-chapter.section.number.py. The command-line example is DCGAN on MNIST dataset in Chapter 4, second section and first listing. In some cases, the explicit command line to execute is not written but it is assumed to be:

$ python3 name-of-the-file-in-listing
The file name of the code example is included in the Listing caption.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email , and mention the book's title in the subject of your message. If you have questions about any aspect of this book, please email us at .

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book we would be grateful if you would report this to us. Please visit, http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.