How to do it...

In the following steps, we provide a recipe for replacing the face of one individual in an image with that of another. The code is structured in five parts: Deepfake.ipynb (main), the deepfake_config configuration file, deepfake_face_detection, deepfake_face_points_detection, and deepfake_face_swap. Also, a models folder is included.

The following code can be found in Deepfake.ipynb:

  1. Import opencv for image operations and the methods needed to swap faces from the associated code:
import osimport cv2import numpy as npfrom deepfake_face_detection import select_facefrom deepfake_face_swap import (    warp_image_2d,    warp_image_3d,    mask_from_points,    apply_mask,    correct_colours,    transformation_from_points,    ProcessFace,)
  1. Specify ...

Get Machine Learning for Cybersecurity Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.