Skip to content

DeepFace-Img2Img is a project designed solely for face swapping in images. By using a source image and a target image, it facilitates the swapping of faces between them.

Notifications You must be signed in to change notification settings

PongpreechaSuea/DeepFace-Img2Img

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DeepFaceHuman-Img2Img

DeepFace-Img2Img is a specialized project dedicated to face swapping within images. It operates by taking a source image and a target image, and seamlessly swapping the faces between the two. This service utilizes advanced deep learning techniques to ensure high-quality and realistic results. The primary focus of the project is to provide an easy and efficient way to swap faces in photos, making it ideal for entertainment, personal projects, or research purposes. With a user-friendly interface and powerful backend, DeepFace-Img2Img simplifies the process of face swapping, delivering impressive outcomes with minimal effort.

Access the Colab Notebook for examples and further learning Colab Notebook

Features

  • Face swapping from uploaded images
  • Adjustable full generation option
  • Web interface for easy interaction
  • API endpoints for programmatic access

Requirements

  • Python 3.8+
  • FastAPI
  • Pillow
  • torch
  • opencv-python
  • onnxruntime

Installation

  1. Clone repository:

    git clone https://github.com/PongpreechaSuea/DeepFace-Img2Img.git
    cd DeepFace-Img2Img
  2. Create and activate virtual environment:

    python -m venv venv
    source venv/bin/activate  # For Windows use `venv\Scripts\activate`
  3. Install required packages:

    pip install -r requirements.txt
    pip install insightface==0.7.3
  4. Download Model:

    cd model
    python download_models.py
    cd ..
    
    cd src\CodeFormer\CodeFormer\weights
    python download_weights.py

Configuration

Customize the src/config.py file as needed:

SOURCE_PATH = "./temp_source.jpg"
TARGET_PATH = "./temp_target.jpg"
MODEL_PATH = "./model/inswapper_128.onnx"
# Add other configuration variables as needed

Usage

Starting the Server

Start the FastAPI server:

python app.py

The server will run on http://0.0.0.0:8000 by default.

API Endpoints

Swap Faces in Images

  • Endpoint: /swap-face/

  • Method: POST

  • Description: Upload source and target images to swap faces

  • Request: multipart/form-data

    • source: Source image for face swapping
    • target: Target image for face swapping
    • full_generate: Boolean for full generation option
  • Response: JPEG image with swapped face

Web Interface

Access the web interface at http://0.0.0.0:8000/ to use the face swapping tool through a user-friendly interface.

Example Usage

import requests

url = "http://0.0.0.0:8000/swap-face/"
files = {
    'source': open('path_to_source_image.jpg', 'rb'),
    'target': open('path_to_target_image.jpg', 'rb')
}
data = {'full_generate': 'true'}

response = requests.post(url, files=files, data=data)

if response.status_code == 200:
    with open('result.jpg', 'wb') as f:
        f.write(response.content)
    print("Face swapped image saved as result.jpg")
else:
    print("Error:", response.status_code, response.text)

Docker Support

This project includes Docker support for easy deployment.

Building and Running with Docker

Build the Docker image:

docker build -t deepface-img2img .

Run the container:

docker run -p 8000:8000 deepface-img2img

Using Docker Compose

Alternatively, you can use Docker Compose:

docker-compose up --build

This will build the image and start the container, mapping port 8000 on your host to port 8000 in the container.

Example

Input Output
Source Image Target Image Result
Source Image Target Image Result Image
Source Image Target Image Result Image
Source Image Target Image Result Image
Source Image Target Image Result Image

About

DeepFace-Img2Img is a project designed solely for face swapping in images. By using a source image and a target image, it facilitates the swapping of faces between them.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published