Giter VIP home page Giter VIP logo

inswapper-flask-api's Introduction

inswapper-flask-api

Python Flask API for Face Swapper and Restoration powered by insightface.

Installation

Clone this repository

git clone https://github.com/ashleykleynhans/inswapper-flask-api.git
cd inswapper-flask-api

Install the required Python dependencies

Linux and Mac

python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt

Windows

python3 -m venv venv
venv\Scripts\activate
pip3 install -r requirements.txt

Download Checkpoints

You will need to download the face swap model and save it under ./checkpoints.

mkdir checkpoints
wget -O ./checkpoints/inswapper_128.onnx https://huggingface.co/ashleykleynhans/inswapper/resolve/main/inswapper_128.onnx

Face Restoration

In order to obtain better results, it is highly recommended to enable a face restoration model, which will improve image quality. This application uses CodeFormer for face restoration.

The required models will be downloaded automatically the first time the face swap API is called.

You will require Git Large File Storage to be installed on your system before you can run the following command.

git lfs install
git clone https://huggingface.co/spaces/sczhou/CodeFormer

Examples

Refer to the examples provided for getting started with making calls to the API.

Benchmarks

These benchmarks are for a source image with a resolution of 960x1280 and a target image with a resolution of 1200x750, upscaled by 1 and with CodeFormer Face Restoration enabled.

System Time Taken
macOS Ventura 13.4.1 on Apple M1 Max 68.6 seconds
Ubuntu 22.04 LTS on t3a.xlarge AWS instance 248.1 seconds
Ubuntu 22.04 LTS on an A5000 RunPod GPU pod 14.2 seconds
Windows 10 103.9 seconds

Get a RunPod account.

Acknowledgements

  1. Thanks insightface.ai for releasing their powerful swap model that made this possible.
  2. This codebase is built on top of inswapper and CodeFormer.
  3. inswapper is built on the top of sd-webui-roop and CodeFormer.

inswapper-flask-api's People

Contributors

ashleykleynhans avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

inswapper-flask-api's Issues

Why does the program terminate when I use this interface?

when I use it in codespace,I got a logging,it cannot work
Successfully saved face swap source image: /tmp/inswapper/d56c4679-0a8d-4aee-bfc8-ccc53b953d4a.png
Saving face swap target image to disk: /tmp/inswapper/f11ab767-475f-49d0-8d9a-50e6f737ddc4.png
Successfully saved face swap target image: /tmp/inswapper/f11ab767-475f-49d0-8d9a-50e6f737ddc4.png
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: ./checkpoints/models/buffalo_l/1k3d68.onnx landmark_3d_68 ['None', 3, 192, 192] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: ./checkpoints/models/buffalo_l/2d106det.onnx landmark_2d_106 ['None', 3, 192, 192] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: ./checkpoints/models/buffalo_l/det_10g.onnx detection [1, 3, '?', '?'] 127.5 128.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: ./checkpoints/models/buffalo_l/genderage.onnx genderage ['None', 3, 96, 96] 0.0 1.0
Applied providers: ['CPUExecutionProvider'], with options: {'CPUExecutionProvider': {}}
find model: ./checkpoints/models/buffalo_l/w600k_r50.onnx recognition ['None', 3, 112, 112] 127.5 127.5
set det-size: (320, 320)
Terminated

Background near swapped face is broken

Hi

BACKGROUND_ENHANCE = True
FACE_RESTORE = True
FACE_UPSAMPLE = True
UPSCALE = 2
CODEFORMER_FIDELITY = 0.5

Background near face gets blurred and pixelated after the swap.

Is there any way to fix it?

Source:
sm2

Target:
tm1

After swap:
broken

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.