Getting hands-on with the code
Now it’s time to get into the code. We’ll go over exactly what C5-face_detection.py
does and why each option was chosen. There are five main parts to the code: initialization, image preparation, face detection, face landmarking/aligning, and masking.
Initialization
Let’s begin.
Author’s note
Formatting for easy reading in a book requires modifying the spacing in the samples. Python, however, is whitespace sensitive and uses spacing as a part of the language syntax. This means that copying code from this book will almost definitely contain the wrong spacing. For this reason, we highly recommend pulling the code from the Git repository for the book at https://github.com/PacktPublishing/Exploring-Deepfakes if you plan on running it.
- First, we import all required libraries:
import os import torch import cv2 import json_tricks import numpy as np from tqdm import tqdm from argparse import ArgumentParser from face_alignment...