Coder Social home page Coder Social logo

shobhit-agarwal / swapseed Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kiranpranay/swapseed

0.0 1.0 0.0 2.58 MB

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: MIT License

Python 100.00%

swapseed's Introduction

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

swapseed's People

Contributors

kiranpranay avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.