Apache License 2.0

项目介绍

ishandutta0098/mukh 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 Apache License 2.0 许可证,目前获得 379 个 Star、95 次 Fork。

仓库全名
ishandutta0098/mukh
开源许可证
Apache License 2.0
Star 数
379
Fork 数
95
未关闭 Issue
6

README 摘要

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

完整内容见 GitHub 原始 README 或本页 。

常见问题

mukh 用什么语言开发?

主要使用 Python 编写,采用 Apache License 2.0 许可证,目前有 379 个 Star。

mukh 可以免费商用吗?

仓库采用 Apache License 2.0 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 mukh 的源码?

可以直接克隆仓库:git clone https://github.com/ishandutta0098/mukh.git,默认分支为 main;安装与运行步骤见仓库 README。

mukh 最近还在维护吗?

仓库最近一次更新为 2025年6月30日,当前有 6 个未关闭 Issue;Star 数为 379,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

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

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Python
Shell

README

Mukh

Downloads Documentation Stars License PyPI

LinkedIn Twitter YouTube

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

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

Usage

Face Detection

from mukh.face_detection import FaceDetector

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

# Detect faces
detections = detector.detect(
    image_path="assets/images/img1.jpg",                       # Path to the image to detect faces in
    save_json=True,                                             # Save the detections to a JSON file
    json_path=f"output/{detection_model}/detections.json",       # Path to save the JSON file
    save_annotated=True,                                       # Save the annotated image
    output_folder=f"output/{detection_model}",                   # Path to save the annotated image
)

Example

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

Output Annotated Image

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

Face Reenactment

from mukh.reenactment import FaceReenactor

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

# Reenact face
result_path = reenactor.reenact_from_video(
    source_path="assets/images/img1.jpg",         # Path to the source image
    driving_video_path="assets/videos/video.mp4", # Path to the driving video
    output_path=f"output/{reenactor_model}",      # Path to save the reenacted video
    save_comparison=True,                         # Save the comparison video
    resize_to_image_resolution=False,             # Resize the reenacted video to the image resolution
)

Example

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

import torch
from mukh.deepfake_detection import DeepfakeDetector

# Initialize detector
detection_model = "efficientnet"                  # Other models "resnet_inception"

detector = DeepfakeDetector(
    model_name=detection_model,
    confidence_threshold=0.5,
    device=torch.device("cuda" if torch.cuda.is_available() else "cpu"),
)

# Detect deepfakes in Images

media_path = "assets/images/img1.jpg"             

detections, final_result = detector.detect(
    media_path=media_path,                                         # Path to the media file (image/video)
    save_csv=True,                                                 # Save the detections to a CSV file
    csv_path=f"output/{detection_model}/deepfake_detections.csv",  # Path to save the CSV file
    save_annotated=True,                                           # Save the annotated media
    output_folder=f"output/{detection_model}",                # Path to save the annotated media
)

Example

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

Output

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

Videos

import torch
from mukh.deepfake_detection import DeepfakeDetector

# Initialize detector
detection_model = "efficientnet"                  # Other models "resnet_inception"

detector = DeepfakeDetector(
    model_name=detection_model,
    confidence_threshold=0.5,
    device=torch.device("cuda" if torch.cuda.is_available() else "cpu"),
)

# Detect deepfakes in Videos

media_path = "assets/videos/deepfake_elon_musk.mp4"             

detections, final_result = detector.detect(
    media_path=media_path,                                         # Path to the media file (image/video)
    save_csv=True,                                                 # Save the detections to a CSV file
    csv_path=f"output/{detection_model}/deepfake_detections.csv",  # Path to save the CSV file
    save_annotated=True,                                           # Save the annotated media
    output_folder=f"output/{detection_model}",                # Path to save the annotated media
    num_frames=11,                                                 # Number of equally spaced frames for video analysis
)

Example

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

      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
| deepfake_elon_musk.mp4 | EfficientNetAutoAttB4 | 8/11 deepfake frames | Final: DEEPFAKE

Deepfake Detection Pipeline

from mukh.pipelines.deepfake_detection import PipelineDeepfakeDetection

# Define model configurations with weights
model_configs = {
    "resnet_inception": 0.5,
    "efficientnet": 0.5
}

# Create ensemble detector
pipeline = PipelineDeepfakeDetection(model_configs)

media_path = "assets/videos/deepfake_elon_musk.mp4" # Or pass an image path

# Detect deepfakes
result = pipeline.detect(
    media_path=media_path,
    output_folder="output/deepfake_detection_pipeline",
    save_csv=True,
    num_frames=11,        # Number of equally spaced video frames for analysis
)

Example

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

Output

Ensemble confidence score

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

 | 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

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.

评论

暂无评论