Skip to content

SwapSeed 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 with the image enhancers.

License

Notifications You must be signed in to change notification settings

KiranPranay/swapseed

Repository files navigation

Face Swapping with InsightFace and ONNX

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.

Face Swap Result

Face Swap Result

Installation

  1. Clone the repository:
git clone https://github.com/KiranPranay/swapseed
cd swapseed
  1. Install the required dependencies:
pip install -r requirements.txt
  1. Execution
 python main.py

Usage

There are three main functions available for face swapping:

  • 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.

Example

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')

Available Enhancers

  • GFPGAN
  • REAL-ESRGAN 2x
  • REAL-ESRGAN 4x
  • REAL-ESRGAN 8x

GPU Support

  • cuda (set 'device=cuda' to run with gpu)

Acknowledgments

This project uses the InsightFace library and ONNX model for face analysis and swapping. Thanks to the developers of these libraries for their contributions.

License

MIT License

Disclaimmer

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 ☕😀

Buy Me a Coffee at ko-fi.com

About

SwapSeed 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 with the image enhancers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages