This project demonstrates face swapping using the InsightFace library and ONNX model. It allows you to swap faces between two images or even swap faces within the same image.
You can use the available image Enhancers to bring your output to the next level.
- Clone the repository:
git clone https://github.com/KiranPranay/swapseed
cd swapseed
- Install the required dependencies:
pip install -r requirements.txt
- Execution
python main.py
-
swap_n_show(img1_fn, img2_fn, app, swapper, plot_before=True, plot_after=True): This function swaps faces between two input images.
-
swap_n_show_same_img(img1_fn, app, swapper, plot_before=True, plot_after=True): This function swaps faces within the same image.
-
swap_face_single(img1_fn, img2_fn, app, swapper): This function adds face from the source image to the target image and saves in output/ folder.
-
fine_face_swap(img1_fn, img2_fn, app, swapper): This function has ability to finely select faces from image with multiple faces.
You can use these functions in your Python scripts or Jupyter notebooks.
import cv2
import matplotlib.pyplot as plt
from faceswap import swap_n_show, swap_n_show_same_img, swap_face_single
# Load images
img1_fn = 'images/bramhi.jpg'
img2_fn = 'images/modi.jpg'
# Swap faces between two images
swap_n_show(img1_fn, img2_fn, app, swapper, enhance=True, enhancer='REAL-ESRGAN 2x')
# Swap faces within the same image
swap_n_show_same_img(img1_fn, app, swapper, enhance=True, enhancer='REAL-ESRGAN 2x')
# Add face to an image
swap_face_single(img1_fn, img2_fn, app, swapper, enhance=True, enhancer='REAL-ESRGAN 2x')
# Swap faces in images with multiple faces
fine_face_swap(img1_fn, img2_fn, app, swapper, enhance=True, enhancer='REAL-ESRGAN 2x')
- GFPGAN
- REAL-ESRGAN 2x
- REAL-ESRGAN 4x
- REAL-ESRGAN 8x
- cuda (set 'device=cuda' to run with gpu)
This project uses the InsightFace library and ONNX model for face analysis and swapping. Thanks to the developers of these libraries for their contributions.
This project is for educational purposes only. The face swapping techniques demonstrated here are intended to showcase the capabilities of the InsightFace library and ONNX model for educational and research purposes. The project should not be used for any malicious or illegal activities.
If you like my content or find anything useful, give it a ⭐ or support me by buying me a coffee ☕😀