Instructions to use buildborderless/CommunityForensics-DeepfakeDet-ViT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use buildborderless/CommunityForensics-DeepfakeDet-ViT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="buildborderless/CommunityForensics-DeepfakeDet-ViT") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoImageProcessor, AutoModelForImageClassification processor = AutoImageProcessor.from_pretrained("buildborderless/CommunityForensics-DeepfakeDet-ViT") model = AutoModelForImageClassification.from_pretrained("buildborderless/CommunityForensics-DeepfakeDet-ViT", device_map="auto") - timm
How to use buildborderless/CommunityForensics-DeepfakeDet-ViT with timm:
import timm model = timm.create_model("hf_hub:buildborderless/CommunityForensics-DeepfakeDet-ViT", pretrained=True) - Inference
- Notebooks
- Google Colab
- Kaggle
BREAKING CHANGES: PR #5
TL;DR β The ViT-Small model configuration was corrected and all ONNX exports were regenerated. ONNX outputs are now [batch_size, 1] (single sigmoid, > 0.5 = fake) instead of [batch_size, 2] logits. This is a breaking change for any code that consumed the old 2-class output. Full details and a migration guide below.
What changed (PR #5, fix/config-cleanup)
The original training checkpoint stores weights under a nested model key, which broke the standard Hugging Face loader path and produced incorrect outputs (2-class logits on a single-label task). This was fixed and all artifacts regenerated:
config.json:num_labelsis now1β single sigmoid output (real/fake).- ONNX output shape:
[batch_size, 2]β[batch_size, 1]. - 4 supported variants in
onnx/:model.onnxβ FP32, ~83.4 MB (maximum accuracy, server-side)model_int8.onnxβ ~22 MB (fastest CPU)model_uint8.onnxβ ~22 MB (unsigned CPU variant)model_q4.onnxβ ~15.1 MB (smallest, low disk/RAM)model_quantized.onnxis retained as a byte-identical alias ofmodel_int8.onnxfor compatibility.
- The 8 broken legacy variants (old
[batch_size, 2]output) are archived underonnx_legacy/β do not use them for new deployments. - Requires
transformers >= 5.4.0; older versions lackshortest_edgeresize and will silently squash images.
Migration guide
ONNX consumers β replace the 2-class handling with a single sigmoid:
import onnxruntime as ort
import numpy as np
session = ort.InferenceSession("onnx/model_int8.onnx")
# inputs = preprocessed tensor [batch, 3, 384, 384]
outputs = session.run(None, {"input": inputs})[0] # shape now [batch, 1]
fake_prob = 1.0 / (1.0 + np.exp(-outputs)) # or a sigmoid layer
is_fake = fake_prob[0, 0] > 0.5
Transformers users β the standard path now loads the corrected weights directly (no custom wrapper needed):
from transformers import ViTForImageClassification, ViTImageProcessor
model = ViTForImageClassification.from_pretrained("buildborderless/CommunityForensics-DeepfakeDet-ViT")
processor = ViTImageProcessor.from_pretrained("buildborderless/CommunityForensics-DeepfakeDet-ViT")
How to verify you're on the fixed build
- ONNX session output shape is
[batch, 1], not[batch, 2]. config.jsoncontains"num_labels": 1.transformers.__version__is>= 5.4.0.- You are loading from
onnx/(or the model hub root), notonnx_legacy/.
Prefer not to upgrade yet?
Pin to the last revision before this breaking change: revision a54ed6c.
Note that this revision contains the uncorrected configuration; the fix and regenerated ONNX variants ship from commit 0b8f9cb onward.
A note on quantization
Dynamic quantization accuracy varies by input. On normal real-world photos and AI-generated images the quantized variants track FP32 closely, but on out-of-distribution content (extreme aspect ratios, synthetic noise) divergence can be larger. For high-stakes or forensic decisions, prefer model.onnx (FP32). Per-variant guidance is in the README.