Image Classification
Transformers
Safetensors
timm
vit
detection
deepfake
forensics
deepfake_detection
community
opensight
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
| # AGENTS.md β CommunityForensics-DeepfakeDet-ViT | |
| ## What this repo is | |
| Hugging Face model repo for `buildborderless/CommunityForensics-DeepfakeDet-ViT` β a ViT-Small classifier for deepfake image detection. Trained on 2.7M samples across 4,803 generators. This is a model distribution repo (no app, no build, no tests). | |
| ## Key files | |
| - **`model.safetensors`** β HF-format weights (Git LFS β ensure `git lfs pull` after clone) | |
| - **`config.json`** β `ViTForImageClassification` config (384Γ384, 6 heads, num_labels=1, sigmoid output: real/fake) | |
| - **`preprocessor_config.json`** β CLIP-style normalization, resize to shortest_edge=440, center-crop to 384 | |
| - **`modeling_vit_classifier.py`** β **DEPRECATED** (moved to `scripts/`). Use standard HF path below. | |
| - **`pretrained_weights/`** β original `.pt` checkpoints from training (also LFS) | |
| - **`onnx/`** β 5 pre-exported ONNX variants (15MBβ84MB) for CPU/GPU deployment. See README for variant guide. | |
| ## Usage | |
| The model is hosted on Hugging Face. The standard way to load it is via `transformers`: | |
| ```python | |
| from transformers import ViTForImageClassification, ViTImageProcessor | |
| model = ViTForImageClassification.from_pretrained("buildborderless/CommunityForensics-DeepfakeDet-ViT") | |
| processor = ViTImageProcessor.from_pretrained("buildborderless/CommunityForensics-DeepfakeDet-ViT") | |
| ``` | |
| The custom wrapper (`modeling_vit_classifier.py`) uses `timm.create_model` with a sigmoid output and `pretrained_weights/model_v11_ViT_384_base_ckpt.pt`. This is for standalone (non-HF-pipeline) inference requiring both `timm` and `transformers`. | |
| ## Dependencies | |
| - `transformers >= 5.4.0` (required β older versions lack `shortest_edge` resize and will squash images) | |
| - `timm` (for the deprecated ViTClassifier wrapper only) | |
| - `torch`, `torchvision`, `Pillow` | |
| - `onnxruntime >= 1.27` (for ONNX models) | |
| ## Scripts (in `scripts/`) | |
| Data processing utilities for the eval dataset β not needed for inference: | |
| - `convert_to_pytorch.py` β convert timm checkpoints to HuggingFace format | |
| - `resample_evalset.py` β face-detection-based dataset filtering | |
| - `restructure.py` β reorganize real/generated image directories | |
| - `quick_analysis.py` β dataset statistics report | |
| ## Git LFS | |
| All weight files (`.safetensors`, `.pt`, `.ckpt`, `.onnx`) are stored via Git LFS. Always run `git lfs pull` after cloning or the model files will be pointer stubs. The full ONNX model alone is 138MB β pull selectively with `git lfs pull --include="onnx/model_int8.onnx"` if you only need one variant. | |
| ## Remote | |
| This repo is pushed to `https://huggingface.co/buildborderless/CommunityForensics-DeepfakeDet-ViT`, not GitHub. Standard `gh` CLI commands will not work. | |