Skip to main content

DeepClip

License Stars Release PyPI Python PyTorch

CLIP for deepfakes — face forgery detection aligned with CLIP text embeddings

📌 Contents

💡 What DeepClip Predicts

DeepClip scores a face image against CLIP text captions. Besides the fake probability, it gives an artifact score for each pair of a face region and a forgery artifact type, so you can see where and what kind of forgery the model sees.

Values
Region face, eyes, nose, mouth
Artifact type blur, color, texture, structure, blend
  • Fake probability: 1 - p_real, where p_real is the score of the caption "a photo of a real face."
  • Artifact scores: 4 regions × 5 types = 20 captions such as "... blending artifacts on the mouth", each a probability in [0, 1].

🧬 Model Zoo

Model Resolution Image Backbone Text Encoder Model Config Download
⚡ deepclip_b0 224 X 224 tf_efficientnet_b0 + GCViT CLIP ViT-B/16 (frozen) spec model
🔥 deepclip_b5 384 X 384 tf_efficientnet_b5 + GCViT CLIP ViT-L/14 (frozen) spec model

The pretrained weights are downloaded automatically with timm.create_model(model_name, pretrained=True).

📦 Installation

Option A: Pip (Inference)

pip install "deepclip[detect]"

The detect extra installs ultralytics for the YOLO face detection used by deepclip.detect. If you only need the models (timm.create_model("deepclip_b0", pretrained=True)), pip install deepclip is enough.

Option B: Full Repository (Training & Evaluation)

train_deepclip.py and test_deepclip.py run against the full repo, not the pip package. Clone it and install the full dev environment:

git clone https://github.com/SEOYUNJE/DeepClip.git
cd DeepClip
pip install -r requirements.txt

🔮 Predict Image & Video

The predictors detect the largest face with YOLO (yolov8n-face, downloaded to ~/.cache/deepclip on the first run), crop it with a margin and run DeepClip on the crop.

Predict DeepFake Image

from deepclip.detect import ClipImagePredictor

# Initialize the predictor
predictor = ClipImagePredictor(
            margin_ratio = 0.2, # Margin ratio around the detected face crop
            conf_thres = 0.5, # Confidence threshold for face detection
            min_face_ratio = 0.01, # Minimum face-to-frame size ratio to process
            model_name = "deepclip_b0", # deepclip_b0, deepclip_b5
            )

# Fake probability only
prob = predictor.predict_img(
            img_path = "path/to/image.jpg",
            tta_hflip = 0.0 # Horizontal Flip for Test-Time Augmentation
            )
print(f"Deepfake Probability: {prob:.4f}")

# Fake probability + artifact scores
result = predictor.predict_img_artifacts(img_path = "path/to/image.jpg")
print(result["prob"])                       # fake probability
print(result["artifacts"]["mouth"]["blend"]) # blending artifacts on the mouth

Predict DeepFake Video

from deepclip.detect import ClipVideoPredictor

# Initialize the predictor
predictor = ClipVideoPredictor(
            margin_ratio = 0.2, # Margin ratio around the detected face crop
            conf_thres = 0.5, # Confidence threshold for face detection
            min_face_ratio = 0.01, # Minimum face-to-frame size ratio to process
            model_name = "deepclip_b0", # deepclip_b0, deepclip_b5
            )

# Fake probability only
prob = predictor.predict_video(
            video_path = "path/to/video.mp4",
            num_frames = 20, # Number of frames to sample per video
            agg_mode = "conf", # Aggregation Method: 'conf', 'mean', 'vote'
            tta_hflip = 0.0 # Horizontal Flip for Test-Time Augmentation
            )
print(f"Deepfake Probability: {prob:.4f}")

# Fake probability + artifact scores (mean over the frames)
result = predictor.predict_video_artifacts(video_path = "path/to/video.mp4", num_frames = 20)

Output of predict_*_artifacts

{
    "prob": 0.9634,               # fake probability (aggregated with agg_mode for videos)
    "artifacts": {                # None when no face is found (prob is 0.5)
        "face":  {"blur": 0.12, "color": 0.08, "texture": 0.21, "structure": 0.05, "blend": 0.64},
        "eyes":  {...},
        "nose":  {...},
        "mouth": {...},
    },
}
agg_mode Frame Aggregation
conf Mean of the confident frames (> 0.8 or < 0.2) when enough frames agree, otherwise mean
mean Mean of all frames
vote Ratio of frames with probability > 0.5

🚀 Training

DeepClip is trained on the frame-level FaceForensics++ dataset with its forgery annotation. We recommend Weights & Biases (W&B) for experiment tracking (--wandb-api-key is required).

!python train_deepclip.py \
    --root-dir DATA_ROOT \
    --model-name "deepclip_b0" \ # deepclip_b0, deepclip_b5
    --output-dir "checkpoints" \ # Directory of the best checkpoint
    --seed 2025 \ # for reproducibility
    --wandb-api-key "your-api-key" # Write your own api key

DATA_ROOT must contain the frame metadata and the face crops:

DATA_ROOT/
├── crops/
│   └── {vid}/
│       ├── 12.png
│       └── ...
└── train_clip_frame_metadata.csv   # vid, frame_idx, label (REAL/FAKE), ori_vid, pair_label

pair_label is a string of 20 0/1 characters, one per (region, type) pair in the order face-blur, face-color, ..., mouth-blend (index = 5 × region + type).

Argument Default Description
--root-dir (required) Root directory of the dataset
--model-name deepclip_b0 deepclip_b0 or deepclip_b5
--config deepclip/config/deepclip_{b0,b5}.yaml Training recipe (model, text sampling, loss, optimizer)
--output-dir . Directory of the best checkpoint
--seed 2025 Random seed
--num-workers cpu_count - 1 DataLoader workers
--debug off Train on a small subset
--wandb-api-key (required) W&B API key
--metadata train_clip_frame_metadata.csv Metadata file under --root-dir
--crop-dir crops Face crop directory under --root-dir

📈 Model Evaluation

test_deepclip.py evaluates a pretrained DeepClip model on deepfake videos and prints AUC, accuracy, log loss, macro F1, the confusion matrix and per-class precision / recall / F1.

!python test_deepclip.py \
    --root-dir DATA_ROOT \
    --dataset "celeb_df_v2" \ # celeb_df_v2, ff++, kodf
    --model-name "deepclip_b0" \ # deepclip_b0, deepclip_b5
    --margin-ratio 0.2 \
    --conf-thres 0.5 \
    --min-face-ratio 0.01 \
    --num-frames 20 \
    --agg-mode "conf" \ # conf, mean, vote
    --tta-hflip 0.0 \
    --top-k 3 # Number of top artifact scores used by the rule-based fake probability (1-20)

The final fake probability of a video is rule-based: max(prob, S_art), where S_art is the sigmoid of the mean of the top-k artifact logits. Artifacts can only raise the fake probability, never lower it.

DATA_ROOT must contain the test metadata of each dataset (label is REAL / FAKE):

DATA_ROOT/
├── Celeb_DF(v2)/
│   ├── test_metadata.csv          # vid, source, label
│   └── {source}/{vid}.mp4
├── FF++/
│   ├── test_metadata.csv
│   └── {source}/{vid}.mp4
└── kodf/
    ├── test_metadata.csv
    └── {source}/{pid}/{vid}.mp4

⚖️ License

This project is licensed under the terms of the MIT license.

Metadata

Release files for deepclip 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deepclip 1.1.0
File Size Uploaded Provenance Actions
deepclip-1.1.0.tar.gz 1.4 MB With provenance Details for deepclip-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for deepclip 1.1.0
File Interpreter ABI Platform Actions
deepclip-1.1.0-py3-none-any.whl Python 3 none any Details for deepclip-1.1.0-py3-none-any.whl

Total release size: 2.8 MB

Release files / deepclip-1.1.0.tar.gz

Download URL deepclip-1.1.0.tar.gz
Size 1.4 MB
Tags Source
SHA-256 checksum
How to use checksums
32769fd6dbf848e5afdf20e7d514f7bd4b964869065f89935eda82f611467477
BLAKE2b-256 checksum
How to use checksums
1d11e275c204ff4b3089665c145a86171980a7023763ec663954f56519f383de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / deepclip-1.1.0-py3-none-any.whl

Download URL deepclip-1.1.0-py3-none-any.whl
Size 1.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
71dc48ea6dd402100409ef699a3be4d07dc50f5aff5f93b6dbc46e3b947c6a40
BLAKE2b-256 checksum
How to use checksums
d4226e1172e8f0cb859539eac536599e7b317620c15e04f7cd7dd2044774b680
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for deepclip 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for deepclip-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page