mukh

A comprehensive face analysis library that provides unified APIs for various face-related tasks

https://github.com/ishandutta0098/mukh

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.1%) to scientific vocabulary

Keywords

ai computer-vision deepfake-detection face-analysis face-detection face-reenactment facial-landmarks machine-learning opencv pip python torch
Last synced: 6 months ago · JSON representation ·

Repository

A comprehensive face analysis library that provides unified APIs for various face-related tasks

Basic Info
Statistics
  • Stars: 163
  • Watchers: 7
  • Forks: 19
  • Open Issues: 5
  • Releases: 0
Topics
ai computer-vision deepfake-detection face-analysis face-detection face-reenactment facial-landmarks machine-learning opencv pip python torch
Created 12 months ago · Last pushed 8 months ago
Metadata Files
Readme Contributing License Citation

README.md

Mukh

[![Downloads](https://static.pepy.tech/personalized-badge/mukh?period=total&units=international_system&left_color=grey&right_color=blue&left_text=downloads)](https://pepy.tech/project/mukh) [![Documentation](https://img.shields.io/badge/docs-View%20Documentation-blue.svg?style=flat)](https://ishandutta0098.github.io/mukh/) [![Stars](https://img.shields.io/github/stars/ishandutta0098/mukh?color=yellow&style=flat&label=%E2%AD%90%20stars)](https://github.com/ishandutta0098/mukh/stargazers) [![License](https://img.shields.io/badge/license-Apache%202.0-green.svg?style=flat)](https://github.com/ishandutta0098/mukh/blob/master/LICENSE) [![PyPI](https://img.shields.io/badge/pypi-mukh-orange.svg?style=flat&logo=pypi)](https://pypi.org/project/mukh/) [![LinkedIn](https://img.shields.io/badge/LinkedIn-@ishandutta0098-blue.svg?style=flat&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/ishandutta0098) [![Twitter](https://img.shields.io/:follow-@ishandutta0098-blue.svg?style=flat&logo=x)](https://twitter.com/intent/user?screen_name=ishandutta0098) [![YouTube](https://img.shields.io/badge/YouTube-@ishandutta--ai-red?style=flat&logo=youtube)](https://www.youtube.com/@ishandutta-ai)

Mukh (मुख, meaning "face" in Sanskrit) is a comprehensive face analysis library that provides unified APIs for various face-related tasks. It simplifies the process of working with multiple face analysis models through a consistent interface.

Features

  • 🥸 DeepFake Detector: First python package featuring an Ensemble of multiple models
  • 🎯 Unified API: Single, consistent API for multiple face analysis tasks like face detection and reenactment
  • 🔄 Model Flexibility: Support for multiple models per task
  • 🛠️ Custom Pipelines: Optimized preprocessing and model combinations

Documentation

The library is documented in detail, click here to view the documentation.

Currently Supported Tasks

  • Face Detection
  • Face Reenactment with Source Image and Driving Video
  • Deepfake Detection for Image and Video
  • Deepfake Detection Pipeline - Ensemble of multiple models

Installation

bash conda create -n mukh-dev python=3.10 -y conda activate mukh-dev pip install mukh==0.1.14

Usage

Face Detection

```python from mukh.face_detection import FaceDetector

Initialize detector

detectionmodel = "mediapipe" # Other models: "blazeface", "ultralight" detector = FaceDetector.create(detectionmodel)

Detect faces

detections = detector.detect( imagepath="assets/images/img1.jpg", # Path to the image to detect faces in savejson=True, # Save the detections to a JSON file jsonpath=f"output/{detectionmodel}/detections.json", # Path to save the JSON file saveannotated=True, # Save the annotated image outputfolder=f"output/{detection_model}", # Path to save the annotated image ) ```

Example

python python examples/face_detection/basic_detection_single_image.py --detection_model mediapipe

Output Annotated Image

python image_name | x1 | y1 | x2 | y2 | confidence img1.jpg | 62 | 228 | 453 | 619 | 0.9381868243217468

Face Reenactment

```python from mukh.reenactment import FaceReenactor

Initialize reenactor

reenactormodel = "tps" # Available models: "tps" reenactor = FaceReenactor.create(reenactormodel)

Reenact face

resultpath = reenactor.reenactfromvideo( sourcepath="assets/images/img1.jpg", # Path to the source image drivingvideopath="assets/videos/video.mp4", # Path to the driving video outputpath=f"output/{reenactormodel}", # Path to save the reenacted video savecomparison=True, # Save the comparison video resizetoimageresolution=False, # Resize the reenacted video to the image resolution ) ```

Example

python python examples/reenactment/basic_reenactment.py \ --reenactor_model tps \ --source_path assets/images/img1.jpg \ --driving_video_path assets/videos/video_1sec.mp4 \ --output_folder output

Output

https://github.com/user-attachments/assets/875ba692-ea78-42e3-9e03-d1f4703930be

Deepfake Detection

Images

```python import torch from mukh.deepfake_detection import DeepfakeDetector

Initialize detector

detectionmodel = "efficientnet" # Other models "resnetinception"

detector = DeepfakeDetector( modelname=detectionmodel, confidencethreshold=0.5, device=torch.device("cuda" if torch.cuda.isavailable() else "cpu"), )

Detect deepfakes in Images

media_path = "assets/images/img1.jpg"

detections, finalresult = detector.detect( mediapath=mediapath, # Path to the media file (image/video) savecsv=True, # Save the detections to a CSV file csvpath=f"output/{detectionmodel}/deepfakedetections.csv", # Path to save the CSV file saveannotated=True, # Save the annotated media outputfolder=f"output/{detectionmodel}", # Path to save the annotated media ) ```

Example

python python examples/deepfake_detection/detection.py \ --detection_model resnet_inception \ --media_path assets/images/img1.jpg \ --confidence_threshold 0.5

Output

python media_name | frame_number | is_deepfake | confidence | model_name img1.jpg | 0 | False | 0.99 | efficientnet

Videos

```python import torch from mukh.deepfake_detection import DeepfakeDetector

Initialize detector

detectionmodel = "efficientnet" # Other models "resnetinception"

detector = DeepfakeDetector( modelname=detectionmodel, confidencethreshold=0.5, device=torch.device("cuda" if torch.cuda.isavailable() else "cpu"), )

Detect deepfakes in Videos

mediapath = "assets/videos/deepfakeelon_musk.mp4"

detections, finalresult = detector.detect( mediapath=mediapath, # Path to the media file (image/video) savecsv=True, # Save the detections to a CSV file csvpath=f"output/{detectionmodel}/deepfakedetections.csv", # Path to save the CSV file saveannotated=True, # Save the annotated media outputfolder=f"output/{detectionmodel}", # Path to save the annotated media num_frames=11, # Number of equally spaced frames for video analysis )

```

Example

python python examples/deepfake_detection/detection.py \ --detection_model resnet_inception \ --media_path assets/videos/deepfake_elon_musk.mp4 \ --confidence_threshold 0.5 \ --num_frames 11

Output

python media_name | frame_number |is_deepfake|confidence| model_name deepfake_elon_musk.mp4 | 0 | True | 0.99 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 43 | True | 0.69 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 86 | False | 0.73 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 172 | True | 0.95 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 215 | True | 0.98 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 129 | True | 0.96 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 258 | True | 0.53 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 301 | True | 0.77 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 344 | False | 0.83 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 387 | True | 0.62 |EfficientNetAutoAttB4 deepfake_elon_musk.mp4 | 431 | False | 0.79 |EfficientNetAutoAttB4 python | deepfake_elon_musk.mp4 | EfficientNetAutoAttB4 | 8/11 deepfake frames | Final: DEEPFAKE

Deepfake Detection Pipeline

```python from mukh.pipelines.deepfake_detection import PipelineDeepfakeDetection

Define model configurations with weights

modelconfigs = { "resnetinception": 0.5, "efficientnet": 0.5 }

Create ensemble detector

pipeline = PipelineDeepfakeDetection(model_configs)

mediapath = "assets/videos/deepfakeelon_musk.mp4" # Or pass an image path

Detect deepfakes

result = pipeline.detect( mediapath=mediapath, outputfolder="output/deepfakedetectionpipeline", savecsv=True, num_frames=11, # Number of equally spaced video frames for analysis ) ```

Example

python python examples/pipelines/deepfake_detection.py \ --media_path assets/videos/deepfake_elon_musk.mp4 \ --output_folder output/deepfake_detection_pipeline

Output

Ensemble confidence score python frame_number|is_deepfake|confidence 0 | True | 0.5 43 | True | 0.84 86 | True | 0.635 129 | True | 0.98 172 | True | 0.975 215 | True | 0.99 258 | True | 0.765 301 | True | 0.885 344 | True | 0.585 387 | True | 0.81 431 | True | 0.605

Result from the respective models python | deepfake_elon_musk.mp4 | ResNetInception | 10/11 deepfake frames | Final: DEEPFAKE | deepfake_elon_musk.mp4 | EfficientNetAutoAttB4 | 8/11 deepfake frames | Final: DEEPFAKE

Final Pipeline Output python Final Ensemble Result: DEEPFAKE Deepfake frames: 11/11 Average confidence: 0.7791 Model configurations: { 'resnet_inception': 0.5, 'efficientnet': 0.5 }

Citations

For a detailed list of models, libraries, and datasets used, please refer to CITATIONS.md.

Contact

For questions and feedback, please open an issue on GitHub.

Owner

  • Name: Ishan Dutta
  • Login: ishandutta0098
  • Kind: user
  • Location: Bengaluru, Karnataka
  • Company: Adobe

Machine Learning Engineer II (GenAI) @Adobe | Open Source @Lightning-AI | Ambassador @JarvislabsAI @wandb | Kaggle Master (Top 70)

Citation (CITATIONS.md)

# CITATIONS

## Face Detection
### Blazeface
- **Paper** [BlazeFace: Sub-millisecond Neural Face Detection on Mobile GPUs](https://arxiv.org/abs/1907.05047) 
    - Valentin Bazarevsky, Yury Kartynnik, et. al.
- **GitHub**: [Blazeface PyTorch](https://github.com/hollance/BlazeFace-PyTorch)
- **License**: Apache License 2.0

### Ultralight
- **GitHub**: [Ultra-Light-Fast-Generic-Face-Detector-1MB](https://github.com/Linzaer/Ultra-Light-Fast-Generic-Face-Detector-1MB)
- **License**: MIT License

### Mediapipe
- **Paper**: [Mediapipe: A Framework for Building Perception Pipelines](https://arxiv.org/abs/1906.08172)  
  - Camillo Lugaresi, Jiuqiang Tang, et. al.
- **GitHub**: [mediapipe](https://github.com/google-ai-edge/mediapipe)
- **License**: Apache License 2.0
  

## Reenactment
### TPS (Thin Plate Spline)
- **Paper**: [Thin-Plate Spline Motion Model for Image Animation](https://arxiv.org/abs/2203.14367)  
  - Jian Zhao, Hui Zhang
- **GitHub**: [Thin-Plate-Spline-Motion-Model
](https://github.com/yoyo-nb/Thin-Plate-Spline-Motion-Model)
- **License**: MIT License

## Deepfake Detection
### ResNet Inception
- **GitHub**: [ResNet GitHub Repository](https://github.com/aaronespasa/deepfake-detection)
- **License**: Apache License 2.0

### EfficientNet
- **Paper**: [Video Face Manipulation Detection Through Ensemble of CNNs](https://arxiv.org/abs/2004.07676)  
  - Nicolò Bonettini, Edoardo Daniele Cannas, et. al.
- **GitHub**: [icpr2020dfdc
](https://github.com/polimi-ispl/icpr2020dfdc)
- **License**: GNU General Public License 3.0

GitHub Events

Total
  • Issues event: 14
  • Watch event: 175
  • Delete event: 1
  • Issue comment event: 34
  • Push event: 76
  • Pull request review comment event: 1
  • Pull request review event: 3
  • Pull request event: 15
  • Fork event: 32
  • Create event: 1
Last Year
  • Issues event: 14
  • Watch event: 175
  • Delete event: 1
  • Issue comment event: 34
  • Push event: 76
  • Pull request review comment event: 1
  • Pull request review event: 3
  • Pull request event: 15
  • Fork event: 32
  • Create event: 1

Dependencies

setup.py pypi
  • Uncomment *
  • numpy >=1.19.0
  • opencv-python >=4.5.0