Generating New Reality From Autoencoders and Adversarial Networks to Deepfakes (Micheal Lanham) (z-library.sk, 1lib.sk, z-lib.sk)
Author: Micheal Lanham
其他
No Description
📄 File Format:
PDF
💾 File Size:
11.5 MB
7
Views
0
Downloads
0.00
Total Donations
📄 Text Preview (First 20 pages)
ℹ️
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
📄 Page
1
Generating a New Reality From Autoencoders and Adversarial Networks to Deepfakes — Micheal Lanham
📄 Page
2
Generating a New Reality From Autoencoders and Adversarial Networks to Deepfakes Micheal Lanham
📄 Page
3
Generating a New Reality: From Autoencoders and Adversarial Networks to Deepfakes ISBN-13 (pbk): 978-1-4842-7091-2 ISBN-13 (electronic): 978-1-4842-7092-9 https://doi.org/10.1007/978-1-4842-7092-9 Copyright © 2021 by Micheal Lanham This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Celestin Suresh John Development Editor: Laura Berendson Coordinating Editor: Aditee Mirashi Cover designed by eStudioCalamar Cover image designed by Freepik (www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza, Suite 4600, New York, NY 10004-1562, USA. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@ springer-sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/978- 1- 4842- 7091- 2. For more detailed information, please visit www.apress.com/source- code. Printed on acid-free paper Micheal Lanham Calgary, AB, Canada
📄 Page
4
To my true loves: knowledge, my children, and Rhonda.
📄 Page
5
v Table of Contents Chapter 1: The Basics of Deep Learning ������������������������������������������������������������������� 1 Prerequisites ��������������������������������������������������������������������������������������������������������������������������������� 2 The Perceptron ������������������������������������������������������������������������������������������������������������������������������ 4 The Multilayer Perceptron ����������������������������������������������������������������������������������������������������������� 14 Backpropagation ������������������������������������������������������������������������������������������������������������������� 16 Stochastic Gradient Descent ������������������������������������������������������������������������������������������������� 17 PyTorch and Deep Learning �������������������������������������������������������������������������������������������������������� 18 Understanding Regression ���������������������������������������������������������������������������������������������������������� 21 Over- and Underfitting ����������������������������������������������������������������������������������������������������������� 26 Classifying Classes ��������������������������������������������������������������������������������������������������������������������� 27 One-Hot Encoding ������������������������������������������������������������������������������������������������������������������ 29 Classifying MNIST Digits �������������������������������������������������������������������������������������������������������� 30 Conclusion ���������������������������������������������������������������������������������������������������������������������������������� 33 Chapter 2: Unleashing Generative Modeling ����������������������������������������������������������� 35 Unsupervised Learning with Autoencoders �������������������������������������������������������������������������������� 36 Extracting Features with Convolution ����������������������������������������������������������������������������������������� 43 The Convolutional Autoencoder �������������������������������������������������������������������������������������������������� 50 Generative Adversarial Networks ������������������������������������������������������������������������������������������������ 55 Deep Convolutional GAN ������������������������������������������������������������������������������������������������������������� 63 Conclusion ���������������������������������������������������������������������������������������������������������������������������������� 68 About the Author ����������������������������������������������������������������������������������������������������� ix About the Technical Reviewer ��������������������������������������������������������������������������������� xi Acknowledgments ������������������������������������������������������������������������������������������������� xiii Introduction �������������������������������������������������������������������������������������������������������������xv
📄 Page
6
vi Chapter 3: Exploring the Latent Space ������������������������������������������������������������������� 69 Understanding What Deep Learning Learns �������������������������������������������������������������������������������� 70 Deep Learning Function Approximation �������������������������������������������������������������������������������� 71 The Limitations of Calculus ��������������������������������������������������������������������������������������������������� 75 Deep Learning Hill Climbing �������������������������������������������������������������������������������������������������� 76 Over- and Underfitting ����������������������������������������������������������������������������������������������������������� 80 Building a Variational Autoencoder ��������������������������������������������������������������������������������������������� 86 Learning Distributions with the VAE �������������������������������������������������������������������������������������������� 90 Variability and Exploring the Latent Space ��������������������������������������������������������������������������������� 99 Conclusion �������������������������������������������������������������������������������������������������������������������������������� 102 Chapter 4: GANs, GANs, and More GANs ��������������������������������������������������������������� 105 Feature Understanding and the DCGAN ������������������������������������������������������������������������������������ 106 Unrolling the Math of GANs ������������������������������������������������������������������������������������������������������� 112 Resolving Distance with WGAN ������������������������������������������������������������������������������������������������� 116 Discretizing Boundary-Seeking GANs ��������������������������������������������������������������������������������������� 120 Relativity and the Relativistic GAN �������������������������������������������������������������������������������������������� 124 Conditioning with CGAN ������������������������������������������������������������������������������������������������������������ 129 Conclusion �������������������������������������������������������������������������������������������������������������������������������� 133 Chapter 5: Image to Image Content Generation ���������������������������������������������������� 135 Segmenting Images with a UNet����������������������������������������������������������������������������������������������� 136 Uncovering the Details of a UNet ����������������������������������������������������������������������������������������� 142 Translating Images with Pix2Pix ����������������������������������������������������������������������������������������������� 145 Seeing Double with the DualGAN ���������������������������������������������������������������������������������������������� 151 Riding the Latent Space on the BicycleGAN ������������������������������������������������������������������������������ 156 Discovering Domains with the DiscoGAN ���������������������������������������������������������������������������������� 161 Conclusion �������������������������������������������������������������������������������������������������������������������������������� 165 Table of ConTenTs
📄 Page
7
vii Chapter 6: Residual Network GANs ���������������������������������������������������������������������� 167 Understanding Residual Networks �������������������������������������������������������������������������������������������� 168 Cycling Again with CycleGAN ���������������������������������������������������������������������������������������������������� 174 Creating Faces with StarGAN ���������������������������������������������������������������������������������������������������� 180 Using the Best with Transfer Learning �������������������������������������������������������������������������������������� 184 Increasing Resolution with SRGAN ������������������������������������������������������������������������������������������� 189 Conclusion �������������������������������������������������������������������������������������������������������������������������������� 193 Chapter 7: Attention Is All We Need! �������������������������������������������������������������������� 195 What Is Attention? ��������������������������������������������������������������������������������������������������������������������� 196 Understanding the Types of Attention ���������������������������������������������������������������������������������� 199 Applying Attention ��������������������������������������������������������������������������������������������������������������� 201 Augmenting Convolution with Attention ������������������������������������������������������������������������������������ 205 Lipschitz Continuity in GANs ����������������������������������������������������������������������������������������������������� 209 What Is Lipschitz Continuity? ���������������������������������������������������������������������������������������������� 209 Building the Self-Attention GAN ������������������������������������������������������������������������������������������������ 214 Improving on the SAGAN ����������������������������������������������������������������������������������������������������������� 218 Conclusion �������������������������������������������������������������������������������������������������������������������������������� 222 Chapter 8: Advanced Generators �������������������������������������������������������������������������� 223 Progressively Growing GANs ����������������������������������������������������������������������������������������������������� 224 Styling with StyleGAN Version 2 ������������������������������������������������������������������������������������������������ 230 Mapping Networks �������������������������������������������������������������������������������������������������������������� 231 Style Modules ���������������������������������������������������������������������������������������������������������������������� 232 Frechet Inception Distance �������������������������������������������������������������������������������������������������� 234 StyleGAN2 ���������������������������������������������������������������������������������������������������������������������������� 236 DeOldify and the New NoGAN ��������������������������������������������������������������������������������������������������� 242 Colorizing and Enhancing Video ������������������������������������������������������������������������������������������ 247 Being Artistic with ArtLine ��������������������������������������������������������������������������������������������������������� 249 Conclusion �������������������������������������������������������������������������������������������������������������������������������� 253 Table of ConTenTs
📄 Page
8
viii Chapter 9: Deepfakes and Face Swapping ����������������������������������������������������������� 255 Introducing the Tools for Face Swapping ���������������������������������������������������������������������������������� 257 Gathering the Swapping Data ��������������������������������������������������������������������������������������������������� 260 Downloading YouTube Videos for Deepfakes ����������������������������������������������������������������������� 263 Understanding the Deepfakes Workflow ����������������������������������������������������������������������������������� 267 Extracting Faces ������������������������������������������������������������������������������������������������������������������ 269 Sorting and Trimming Faces ������������������������������������������������������������������������������������������������ 271 Realigning the Alignments File �������������������������������������������������������������������������������������������� 274 Training a Face Swapping Model ���������������������������������������������������������������������������������������������� 276 Creating a Deepfake Video �������������������������������������������������������������������������������������������������������� 279 Encoding the Video �������������������������������������������������������������������������������������������������������������� 282 Conclusion �������������������������������������������������������������������������������������������������������������������������������� 284 Chapter 10: Cracking Deepfakes �������������������������������������������������������������������������� 287 Understanding Face Manipulation Methods ����������������������������������������������������������������������������� 288 Techniques for Cracking Fakes ������������������������������������������������������������������������������������������������� 291 Handcrafted Features ���������������������������������������������������������������������������������������������������������� 292 Learning-Based Features ���������������������������������������������������������������������������������������������������� 294 Artifacts ������������������������������������������������������������������������������������������������������������������������������� 296 Identifying Fakes in Deepfakes ������������������������������������������������������������������������������������������������� 299 Conclusion �������������������������������������������������������������������������������������������������������������������������������� 300 Appendix A: Running Google Colab Locally ���������������������������������������������������������� 303 Appendix B: Opening a Notebook ������������������������������������������������������������������������� 307 Appendix C: Connecting Google Drive and Saving ������������������������������������������������ 309 Index ��������������������������������������������������������������������������������������������������������������������� 313 Table of ConTenTs
📄 Page
9
ix About the Author Micheal Lanham is a proven software and tech innovator with 20+ years of experience. During that time, he has developed a broad range of software applications in areas such as games, graphics, web, desktop, engineering, artificial intelligence, GIS, and machine learning applications for a variety of industries as an R&D developer. At the turn of the millennium, Micheal began working with neural networks and evolutionary algorithms in game development. He is an avid educator, and along with writing several books about game development, extended reality, and AI, he regularly teaches at meetups and other events. Micheal also likes to cook for his large family in his hometown of Calgary, Canada.
📄 Page
10
xi About the Technical Reviewer Aneesh Chivukula is a technical expert and an analytics executive. He has strong academic research capacities in machine learning. He has developed innovative products with artificial intelligence. He brings thought leadership of technology trends in the enterprise solutions. Aneesh has a doctorate of philosophy degree in data analytics and machine learning from the University of Technology Sydney, Australia. He holds a master of science degree by research in computer science and artificial intelligence from the International Institute of Information Technology Hyderabad, India.
📄 Page
11
xiii Acknowledgments This book, like many others, would not have been possible without the free exchange of knowledge provided in the AI/ML community, from countless researchers who tirelessly work on improving the field of artificial intelligence and generative modeling to the mass of AI enthusiasts who regularly produce open code repositories featuring new tools and a catalog of innovations. I would like to thank and acknowledge all the contributions of those in the AI/ ML field who work hard educating others. Many of the examples in this book have been collated from the numerous open-source repositories featuring deep learning and generative modeling. One such resource developed by Erik Linder-Norén, an ML engineer at Apple, inspired and contributed to several examples in this book’s early chapters. I would also like to thank you, the reader, for taking the opportunity to review this text and open your mind to new opportunities. It has always been a profound pleasure of mine watching that light bulb moment students experience when they first meld with a new concept. It’s something I hope you will experience several times through the course of this book. Lastly, as always, special thanks to my large family and friends. While I may not see all my nine children on a regular basis, they and their children always have a special place in my heart. I feel fortunate that my family supports my writing and continues to encourage new titles.
📄 Page
12
xv Introduction We live in an era of fake news and uncertain reality. It’s a world where reality has become blurred by digital wizardry artists and artificial intelligence practitioners. It’s a digital reality now populated with fake news, images, and people. For many, the uncertainty and confusion are overwhelming. Yet, others, like yourself, search to embrace this new era of digital fakery to explore new opportunities. This book takes an in-depth look at the technology that powers this new digital fake reality. The broad name for this technology or form of AI/ML is generative modeling (GM). It is a form of AI/ML modeling that looks to understand what something represents, as opposed to other forms of modeling that look to classify or predict something. Generative modeling is not a new concept, but one that has emerged from the application of deep learning. The introduction of deep learning has launched the field into the mainstream. Unfortunately, not all mainstream use of GM is flattering or showcases the power of this diverse technology. There is a real and speculated fear for most outside and inside the field of GM on what is possible. For many, the application of GM to produce fake anything is abhorrent and nonessential, but the broad applications GM introduces can benefit many industries across many tasks. In this book, we begin with the assumption you have limited or little knowledge of deep learning and generative modeling. You have a basic knowledge of programming Python and applying data science, including the typical fundamental math knowledge in calculus, linear algebra, and statistics used in data science. We will cover a wide range of GM techniques and applications in this book, starting with the fundamentals of building a deep learning network and then progressing to GM. Here is a brief overview of the chapters we will explore: 1. The Basics of Deep Learning: We begin by introducing the basic concepts of deep learning, autoencoders, and how to build simple models with PyTorch. The examples in this chapter demonstrate simple concepts we will apply throughout this book and should not be missed by newcomers.
📄 Page
13
xvi 2. Unleashing Generative Adversarial Networks: This chapter moves to the fundamentals of explaining the generative adversarial network (GAN) and how it can be used to generate new and novel content. Examples in this chapter explore the applications of GANs from generating fashion to faces. 3. Exploring the Latent Space: Fundamental to generative modeling is the concept of learning the latent or hidden representation of something. In this chapter, we explore how the latent space is defined and how we can better control it through hyperparameters, loss function, and network configuration. 4. GANs, GANs, and More GANs: This book explores several variations of GANs, and in this chapter we look at five forms that attempt to learn the latent space differently. We build on knowledge from previous chapters to explore key differences in the way GANs learn and generate content. 5. Image to Image Content Generation: This chapter covers the advanced application of GANs to enhance the generation of content by learning through understanding translations. The examples in this chapter focus on showcasing paired and unpaired image translation using a variety of powerful GANs. 6. Residual Network GANs: Throughout this book we will constantly struggle with the generative ability to produce diverse and realistic features. The GANs in this chapter all use residual networks to help identify and learn more realistic feature generation. 7. Attention Is All We Need: This chapter explores the attention mechanism introduced into deep learning through the application of natural language processing. Attention provides a unique capability to identify and map relevant features with other features. The examples in this chapter demonstrate the power of using an attention mechanism with a GAN. InTroduCTIon
📄 Page
14
xvii 8. Advanced Generators: This chapter dives into the deep end and explores the current class of best-performing GANs. The examples in this chapter work from several open-source repositories that showcase how far the field of GM has come in a short time. 9. Deepfakes and Face Swapping: In this chapter, we switch gears and explore the application of GM for producing deepfakes. Where this whole chapter is dedicated to showcasing the ease of which you can produce a deepfake freely available open-source desktop software. 10. Cracking Deepfakes: From creating deepfakes and fake content for most of the book, we move on to understanding how generated content can be detected. This chapter looks at the techniques and research currently being done to expose fake content. In the future, these tools will be critical to controlling the digital reality we embrace and understanding what is real. This book covers a wide range of complex subjects presented in a practical hands- on and technically friendly manner. To get the most out of this book, it is recommended that you engage and work with several of the 40+ examples. All the examples in this book have been tested and run to completion using Google Colab, the recommended platform for this book. While some examples in this book may take up to days to train, most can be run in under an hour. Thank you for taking your precious time to read this book and ideally expand your opportunities and understanding in the field of AI/ML. The journey you have chosen is nontrivial and will be filled with frustration and anguish. It is one that will also be filled with awe and wonder the first time you generate your first fake face. InTroduCTIon
📄 Page
15
1 © Micheal Lanham 2021 M. Lanham, Generating a New Reality, https://doi.org/10.1007/978-1-4842-7092-9_1 CHAPTER 1 The Basics of Deep Learning Throughout history mankind has often struggled with making sense of what is real and what reality means. From hunter gatherers to Greek philosophers and then to the Renaissance, our interpretation of reality has matured over time. What we once perceived as mysticism is now understood and regulated by much of science. Not more than 10 years ago we were on track to understanding the reality of the universe, or so we thought. Now, with the inception of AI, we are seeing new forms of reality spring up around us daily. New realities being manifested by this new wave of AI are made possible by neural networks and deep learning. Deep learning and neural networks have been on the fringe of computer science for more than 50 years, and they have their own mystique associated with them. For many, the abstract concepts and mathematics of deep learning make them inaccessible. Mainstream science shunned deep learning and neural networks for years, and in many industries they are still off-limits. Yet, among all those hurdles, deep learning has become the brave new leader in AI and machine learning for the 21st century. In this book, we look at how deep learning and neural networks work at a fundamental level. We will learn the inner workings of networks and what makes them tick. Then we will quickly move on to understanding how neural networks can be configured to generate their own content and reality. From there, we will progress through many other versions of deep learning content generation including swapping faces, enhancing old videos, and creating new realities. For this chapter, we will start at the basics of deep learning and how to build neural networks for several typical machine learning tasks. We will look at how deep learning can perform regression and classification of data as well as understand internally the process of learning. Then we will move on to understanding how networks can be
📄 Page
16
2 specialized to extract features in data with convolution. We will finish with building a full working image classifier using supervised deep learning. As this is the first chapter, we will also cover several prerequisites and other helpful content to better guide your success through this book. Here is a summary of what we will cover in this chapter: • Prerequisites • Perceptrons • Multilayer perceptrons • PyTorch for deep learning • Regression • Classifying classes This book will begin at the basics of data science, machine learning, and deep learning, but to be successful, be sure you meet most of the requirements in the next section. Prerequisites While many of the concepts regarding machine learning and deep learning should be taught at the high school level, in this book we will go way beyond the basic introduction of deep learning. Generating content with deep learning networks is an advanced endeavor that can be learned, but to be successful, it will be helpful if you meet most of the following prerequisites: • Interest in mathematics: You don’t need a degree in math, but you should have an interest in learning math concepts. Thankfully, most of the hard math is handled by the coding libraries we will use, but you still need to understand some key differences in math concepts. Deep learning and generative modeling use the following areas of mathematics: • Linear algebra, working with matrices and systems of equations Chapter 1 the BasiCs of Deep Learning
📄 Page
17
3 • Statistics and probability, understanding how descriptive statistics work and basic probability theory • Calculus, understanding the basics of differentiation and how it can be used to understand the rate of change • Programming knowledge: Ideally you have used and programmed with Python or another programming language. If you have no programming knowledge at all, you will want to pick up a course or textbook on Python. As part of your knowledge of programming, you may also want to take a closer look at the following libraries: • NumPy1: NumPy (pronounced “numb pie”) is a library for manipulating arrays or tensors of numbers. It and the concepts it applies are fundamental to machine learning and deep learning. We will cover various uses of NumPy in this book, but it is suggested you study it further on your own as needed. • PyTorch2: This will be the basis for the deep learning projects in this book. It will be assumed you have little to no knowledge of PyTorch, but you may still want to learn more on your own what this impressive library has to offer. • MatPlotLib3: This module will be the foundation for much of the output we display in this book. There will be plenty of examples showing how it is used, but additional homework may be helpful. • Data science and/or machine learning: It will be helpful if you have previously taken a data science course, one that covers the statistical methods used in machine learning and what aspects to be aware of when working with data. 1 NumPy is an open source project at http://numpy.org. 2 PyTorch is an open source project at http://pytorch.org. 3 Matplotlib is an open source package heavily used with Python, available at https://matplotlib.org/. Chapter 1 the BasiCs of Deep Learning
📄 Page
18
4 • Computer: All the examples in this book are developed on the cloud, and while it is possible to use them with a mobile computing device, for best results it is suggested you use a computer. • Instructions have been provided in Appendix A for setting up and using the code examples on your local computer. This may be a consideration if you have a machine with an advanced GPU or need to run an example for more than 12 hours. • Time: Generative modeling can be time-consuming. Some of the examples in this book may take hours and possibly days to run if you are up for it. In most cases, you will benefit more from running the example to completion, so please be patient. • Open to learn: We will do our best to cover most of the material you need to use the exercises in this book. However, to fully understand some of these concepts, you may need to extend your learning outside this text. If your career is data science and machine learning or you want it to be, you likely already realize your path to learning will be continuous. While it is highly recommended that you have some background in the prerequisites mentioned, you may still get by if you are willing to extend your knowledge as you read this book. There are many sources of text, blogs, and videos that you may find useful to help you fill in gaps in your knowledge. The primary prerequisites I ask you bring are an open mind and a willingness to learn. In the next section, we jump into the foundation of neural networks, the perceptron. The Perceptron There is some debate, but most people recognize that the inspiration for neural networks was the brain, or, more specifically, the brain cell or neuron. Figure 1-1 shows the biological neuron over the top of a mathematical model called the perceptron. Frank Rosenblatt developed the basic perceptron model as far back as 1957. The model was later improved on to what is shown in the figure by Marvin Minsky in his book called Perceptrons. Unfortunately, the book was overly critical of the application of the Chapter 1 the BasiCs of Deep Learning
📄 Page
19
5 perceptron for anything other than simple Boolean logic problems like XOR. Much of this criticism was unfounded as we later discovered, but the fallout of this critique is often blamed for the first AI winter. An AI winter is when all research and development using AI is stopped or placed in storage. These winters are often brought on by some major roadblock that stops progress in the field. The first winter was brought on by Minsky’s critique of the perceptron and his belief that it could solve the XOR problem only. There have been two AI winters thus far. The dates of these winters are up for debate and may vary by exact discipline. It is perhaps this association with the brain that causes some of the criticism with the perceptron and deep learning. This association also drives the mystique and uncertainty of neural networks. However, the perceptron itself is just a model of connectivity, and we may often refer to this type of learning as connectionism. If anything, the model of the perceptron only relates to a neuron in the way it connects and really nothing more. Actual neural brain function is far more complex and works nothing like a perceptron. If we return to Figure 1-1 and the perceptron model, you can see how the system can take several inputs denoted by the boxes. These inputs are multiplied by a value we call a weight to weigh or adjust the strength of the input to the next stage. Before that, though, Figure 1-1. A comparison of a biological neuron and the perceptron Chapter 1 the BasiCs of Deep Learning
📄 Page
20
6 we have another input called a bias, with a value of 1.0, that we multiply by another weight. The bias allows the perceptron to offset the results. After the inputs and bias are all weighed/scaled, they are then collectively summed in the summation function. The results of the summation function are then passed to an activation function. The purpose of the activation function may be to further scale, squish, or cut off the value to be output. Let’s take a look at how a simple perceptron can be modeled in code in Exercise 1-1. EXERCISE 1-1. CODING A PERCEPTRON 1. open the GEN_1_XOR_perceptron.ipynb notebook from the project’s github site. if you are unsure on how to access the source, check appendix B. 2. in the first code block of the notebook, we can see some imports for numpy and Matplotlib. Matplotlib is used to display plots. import numpy as np import matplotlib.pyplot as plt 3. scroll to the Xor problem code block, as shown here. this is where the data is set up; the data consists of the X and Y values that we want to train the perceptron on. the X values represent the inputs, and the Y values denote the desired output. We will often refer to Y as the label or the expected output. We use the numpy np module to create the lists of inputs to a tensor using np. array. at the bottom of this block, we output the shape of these tensors. X = np.array([[0,0],[0,1],[1,0],[1,1]]) Y = np.array([0,1,1,0]) print(X.shape) print(Y.shape) Chapter 1 the BasiCs of Deep Learning
The above is a preview of the first 20 pages. Register to read the complete e-book.
Recommended for You
Loading recommended books...
Failed to load, please try again later