Reader small image

You're reading from  Exploring Deepfakes

Product typeBook
Published inMar 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781801810692
Edition1st Edition
Languages
Right arrow
Authors (2):
Bryan Lyon
Bryan Lyon
author image
Bryan Lyon

Bryan Lyon is a developer for Faceswap.
Read more about Bryan Lyon

Matt Tora
Matt Tora
author image
Matt Tora

Matt Tora is a developer for Faceswap.
Read more about Matt Tora

View More author details
Right arrow

Preface

The media attention around deepfakes often focuses on the ills and dangers of the technology. Even many of the articles about what deepfakes can do fail to account for why you might want to do it. The truth is that deepfakes bring new techniques and abilities to neural networks for those who know how to use them.

Beyond replacing faces, deepfakes provide insights into all areas of generative AI, especially when traditional methods fall short. Join us as we explore what deepfakes are, what they can be used for, and how they may change in the future.

A manifesto for the ethical use of deepfakes

There are a lot of concerns when it comes to the use of deepfakes. To that end, we have to establish some common ground so that we can communicate and discuss deepfake technology:

  • Deepfakes are not for creating inappropriate content
  • Deepfakes are not for changing faces without consent or with the intent of hiding their use
  • Deepfakes are not to be utilized for any illicit, unethical, or questionable purposes
  • Deepfakes exist to experiment with and discover AI techniques, for social or political commentary, movies, and any number of other ethical and reasonable uses

We are very troubled by the fact that Faceswap has been used in unethical and disreputable ways. However, we support the development of tools and techniques that can be used ethically, as well as providing education and experience in AI for anyone who wants to learn it hands-on. We take a zero-tolerance approach to anyone using Faceswap for any unethical purposes and actively discourage any such uses.

Who this book is for

This book is for anyone interested in learning about deepfakes. From academics to researchers to content creators to developers, we’ve written this book so it has something for everybody.

The early chapters will cover the essential background of deepfakes, how they work, their ethics, and how to make one yourself using free software that you can download and use without any technical knowledge.

The middle chapters will go in depth into the exact methodology that deepfakes use to work, including working code that you can run and follow step-by-step as we get hands-on with the major processes of deepfakes: extraction, training, and conversion.

The final chapters will look at where you can go from there. They cover how to use deepfake techniques in your own tasks, and where the technology might go in the future.

What this book covers

Chapter 1, Surveying Deepfakes, provides a look into the past and present of deepfakes with a description of how they work and are used.

Chapter 2, Examining Deepfake Ethics and Dangers, provides a look at the sordid history of deepfakes and guidelines on creating ethical deepfakes.

Chapter 3, Mastering Data, teaches you how to get the most from your data, whether you make it yourself or have to find it.

Chapter 4, The Deepfake Workflow, provides a step-by-step walk-through of using Faceswap from the installation to the final output.

Chapter 5, Extracting Faces, is where we begin our hands-on dive into the code of a deepfake by learning how we detect, align, and mask faces for deepfakes.

Chapter 6, Training a Deepfake Model, is where we continue exploring the code as we train a model from scratch, including defining the layers of the model, feeding it images, and updating the model weights.

Chapter 7, Swapping the Face Back into the Video, is where we complete the code analysis with conversion, the process that puts the swapped face back into the original video.

Chapter 8, Applying the Lessons of Deepfakes, teaches you the process of solving hypothetical problems using deepfake techniques.

Chapter 9, The Future of Generative AI, examines where generative AI will move in the future and what limitations they need to overcome.

To get the most out of this book

This book is designed to build knowledge as you read through the chapters. If you’re starting with no background knowledge of deepfakes, then we suggest you start at the beginning. If you want to skip straight to the code, then you’ll want to look at Part 2 (though we hope you’ll give Part 1 a peruse once you’re ready). If you only care about what you can do with the techniques moving forward, then check out Part 3 (but I promise that the earlier parts have some juicy nuggets of information).

We use Python for all code examples in this book. If you know Python, you should be able to understand all the code samples with the help of the text. If you don’t know Python, then don’t worry! There is a lot of non-code explanation, and even the code includes hands-on explanations of what is going on in it.

All the libraries used in this book are explained when they’re used, but this book should not be considered a guide or in-depth explanation of any of the libraries. Many of these libraries have books of their own dedicated to them, and their use in this book is solely functional.

Software covered in the book

Operating system requirements

Python

Faceswap

Windows, macOS, or Linux

PyTorch

OpenCV

Pillow (PIL Fork)

We use Anaconda (https://www.anaconda.com/) for package management and sandboxing throughout this book. If you want to follow along, we highly recommend you install it from the site listed here. If you would rather use Python virtual environments, you may, but if you do, the instructions in this book will not always work without modification, especially installing the necessary packages. If you choose to use that route, you will have to find the correct version of libraries to install yourself.

If you are using the digital version of this book, we advise you access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.

Included in each hands-on chapter is a list of exercises. Please don’t take these as directions on what you must do, but consider them as helpers to more completely understand what it is that the code is doing and how you can use the techniques for yourself. They do not have “answers” as they are not really questions; they’re just prompts for you to find new and exciting ways to apply your knowledge.

If you do complete any of the exercises (or come up with something impressive of your own), we’d appreciate it if you would “fork” the book’s repo into your own GitHub account and show the world your accomplishment! We’d love to see what you can do with deepfakes.

Download the example code files

You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Exploring-Deepfakes. If an update to the code, it will be updated in the GitHub repository. there’s

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

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system.”

A block of code is set as follows:

html, body, #map {
 height: 100%;
 margin: 0;
 padding: 0
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[default]
exten => s,1,Dial(Zap/1|30)
exten => s,2,Voicemail(u100)
exten => s,102,Voicemail(b100)
exten => i,1,Voicemail(s0)

Any command-line input or output is written as follows:

$ mkdir css
$ cd css

Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: “Select System info from the Administration panel.”

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, email us at customercare@packtpub.com and mention the book title in the subject of your message.

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 www.packtpub.com/support/errata and fill in the form.

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 copyright@packt.com 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 authors.packtpub.com.

Share your thoughts

Once you’ve read Exploring Deepfakes, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.

Download a free PDF copy of this book

Thanks for purchasing this book!

Do you like to read on the go but are unable to carry your print books everywhere?

Is your eBook purchase not compatible with the device of your choice?

Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.

Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.

The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily

Follow these simple steps to get the benefits:

  1. Scan the QR code or visit the link below

https://packt.link/free-ebook/9781801810692

  1. Submit your proof of purchase
  2. That’s it! We’ll send your free PDF and other benefits to your email directly
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Exploring Deepfakes
Published in: Mar 2023Publisher: PacktISBN-13: 9781801810692
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Bryan Lyon

Bryan Lyon is a developer for Faceswap.
Read more about Bryan Lyon

author image
Matt Tora

Matt Tora is a developer for Faceswap.
Read more about Matt Tora