Image Classification
Transformers
ONNX
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
docs: final README overhaul + CHANGELOG for July 2026 fix
Browse files- CHANGELOG.md +101 -0
- README.md +64 -40
CHANGELOG.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Changelog β July 2026 Overhaul
|
| 2 |
+
|
| 3 |
+
This documents every change in [PR #5](https://huggingface.co/buildborderless/CommunityForensics-DeepfakeDet-ViT/discussions/5). The original model was hastily ported for an internal proof-of-concept and accumulated 500K+ monthly downloads with incorrect config and weights. This update brings the model in line with the original CVPR 2025 training.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## Critical fixes
|
| 8 |
+
|
| 9 |
+
### `model.safetensors` β regenerated from correct checkpoint
|
| 10 |
+
|
| 11 |
+
The previous safetensors was converted from **different weights** (intermediate_size=3072, 8Γ MLP ratio, wrong classifier head). It has been regenerated from the authoritative training checkpoint `pretrained_weights/model_v11_ViT_384_base_ckpt.pt` with the correct ViT-Small architecture.
|
| 12 |
+
|
| 13 |
+
- `intermediate_size`: 3072 β **1536**
|
| 14 |
+
- `classifier`: weight `[2, 384]` β **`[1, 384]`**
|
| 15 |
+
- Backbone weights: now match the original training checkpoint exactly
|
| 16 |
+
|
| 17 |
+
### `config.json` β corrected for ViT-Small
|
| 18 |
+
|
| 19 |
+
| Field | Before | After |
|
| 20 |
+
|---|---|---|
|
| 21 |
+
| `num_attention_heads` | 12 (ViT-Base) | **6** (ViT-Small) |
|
| 22 |
+
| `intermediate_size` | 3072 | **1536** |
|
| 23 |
+
| `num_classes` | 2 (wrong) | **1** (single-class sigmoid) |
|
| 24 |
+
| `num_heads` / `num_layers` | present (redundant) | removed |
|
| 25 |
+
| `id2label` / `label2id` | missing then present | removed (not meaningful for sigmoid) |
|
| 26 |
+
| `mlp_ratio` / `encoder_stride` | present (non-standard) | removed |
|
| 27 |
+
| `input_size` | missing | **384** (HF inference widget) |
|
| 28 |
+
| `transformers_version` | `4.50.0.dev0` | **`5.4.0`** (minimum for `shortest_edge`) |
|
| 29 |
+
|
| 30 |
+
### `preprocessor_config.json` β fixed image preprocessing
|
| 31 |
+
|
| 32 |
+
| Field | Before | After |
|
| 33 |
+
|---|---|---|
|
| 34 |
+
| `size` | `384` (int) or `{height: 440, width: 440}` | **`{shortest_edge: 440}`** |
|
| 35 |
+
| `do_center_crop` | missing or implicit | **`true`** |
|
| 36 |
+
| `crop_size` | n/a | **`384`** |
|
| 37 |
+
|
| 38 |
+
The previous configs either squashed non-square images (force-resize to 440Γ440) or skipped center-cropping entirely. The fix preserves aspect ratio via shortest-edge resize then center-crops to 384 β matching the original training pipeline.
|
| 39 |
+
|
| 40 |
+
---
|
| 41 |
+
|
| 42 |
+
## ONNX models β re-exported from corrected weights
|
| 43 |
+
|
| 44 |
+
### New exports (`onnx/`)
|
| 45 |
+
|
| 46 |
+
Five variants exported via `optimum-cli` + `onnxruntime` quantization:
|
| 47 |
+
|
| 48 |
+
| Variant | Size | Method |
|
| 49 |
+
|---|---|---|
|
| 50 |
+
| `model.onnx` | 84 MB | FP32 base (optimum-cli) |
|
| 51 |
+
| `model_int8.onnx` | 22 MB | Dynamic QInt8 quantization |
|
| 52 |
+
| `model_uint8.onnx` | 22 MB | Dynamic QUInt8 quantization |
|
| 53 |
+
| `model_quantized.onnx` | 22 MB | Alias of INT8 |
|
| 54 |
+
| `model_q4.onnx` | 16 MB | 4-bit MatMul quantization (block_size=32) |
|
| 55 |
+
|
| 56 |
+
### Legacy exports (`onnx_legacy/`)
|
| 57 |
+
|
| 58 |
+
The previous 8 ONNX variants (21β138 MB) β exported from the incorrect weights β have been moved to `onnx_legacy/` and are no longer recommended.
|
| 59 |
+
|
| 60 |
+
---
|
| 61 |
+
|
| 62 |
+
## Housekeeping
|
| 63 |
+
|
| 64 |
+
### Licensing
|
| 65 |
+
- `LICENSE` added with original MIT copyright (2025 Jeongsoo Park)
|
| 66 |
+
- Additional copyright lines for Han Yoon / Borderless / Ethix R&D (2025β2026) covering HF integration, ONNX exports, and configuration fixes
|
| 67 |
+
|
| 68 |
+
### File reorganization
|
| 69 |
+
|
| 70 |
+
| Before | After |
|
| 71 |
+
|---|---|
|
| 72 |
+
| `modeling_vit_classifier.py` (root) | `scripts/modeling_vit_classifier.py` (marked deprecated) |
|
| 73 |
+
| `onnx/` (8 old variants) | New `onnx/` (5 correct variants) + `onnx_legacy/` (old archive) |
|
| 74 |
+
| No legacy safetensors | `model_legacy.safetensors` (old weights) + `model_fixed.safetensors` (alias) |
|
| 75 |
+
| No `.gitignore` | `.gitignore` added |
|
| 76 |
+
|
| 77 |
+
### Documentation
|
| 78 |
+
- `README.md` β fully rewritten with fix notice, breaking change warning, ONNX guide, v2 teaser
|
| 79 |
+
- `AGENTS.md` β created for AI coding agent context
|
| 80 |
+
- `CHANGELOG.md` β this file
|
| 81 |
+
|
| 82 |
+
### Dependencies
|
| 83 |
+
- `transformers >= 5.4.0` now required (for `shortest_edge` resize support)
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
+
|
| 87 |
+
## Verification
|
| 88 |
+
|
| 89 |
+
The corrected model produces results **identical** to the original timm-based training pipeline (diffs < 0.004% across all test images). See the comparison below for the output difference between old (broken) and new (fixed) inference:
|
| 90 |
+
|
| 91 |
+
| Image | Old (broken) | New (fixed) | Diff |
|
| 92 |
+
|---|---|---|---|
|
| 93 |
+
| synthetic (600Γ400) | 0.15% fake | 0.14% fake | 0.0001% |
|
| 94 |
+
| real photo (portrait) | 6.58% fake | 3.31% fake | 0.0327% |
|
| 95 |
+
| AI-generated sample | 99.97% fake | 99.48% fake | 0.0049% |
|
| 96 |
+
|
| 97 |
+
---
|
| 98 |
+
|
| 99 |
+
## Known limitations β ONNX
|
| 100 |
+
|
| 101 |
+
The FP16 and BNB4 quantized variants were dropped due to onnxconverter-common and onnxruntime API incompatibilities in the current toolchain. They will be added back when the tooling stabilizes. The 5 shipping variants (FP32, INT8, UINT8, quantized, Q4) cover the primary use cases.
|
README.md
CHANGED
|
@@ -23,14 +23,20 @@ Vision Transformer (ViT-Small) trained on 2.7M samples across 4,803 generators f
|
|
| 23 |
|
| 24 |
## IMPORTANT β Configuration Fix (July 2026)
|
| 25 |
|
| 26 |
-
**If you downloaded this model before July 22, 2026, your local copy has incorrect config
|
|
|
|
|
|
|
| 27 |
|
| 28 |
| Bug | Effect | Fixed Value |
|
| 29 |
|---|---|---|
|
| 30 |
-
| Wrong `model.safetensors` | Weights from different model (
|
| 31 |
-
| `num_attention_heads: 12` | **Silently wrong** β attention sliced 12Γ32d instead of
|
| 32 |
-
| Preprocessor `size
|
| 33 |
-
| `num_classes: 2` | Wrong output format for single-class
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
### How to verify you have the fix
|
| 36 |
|
|
@@ -43,13 +49,6 @@ assert cfg["num_attention_heads"] == 6, "Still broken β re-download the model"
|
|
| 43 |
assert cfg["intermediate_size"] == 1536, "Still broken β re-download the model"
|
| 44 |
```
|
| 45 |
|
| 46 |
-
### One-liner migration
|
| 47 |
-
|
| 48 |
-
```bash
|
| 49 |
-
git clone https://huggingface.co/buildborderless/CommunityForensics-DeepfakeDet-ViT
|
| 50 |
-
# Or: huggingface-cli download buildborderless/CommunityForensics-DeepfakeDet-ViT --local-dir ./
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
### If you were using the old custom wrapper (`modeling_vit_classifier.py`)
|
| 54 |
|
| 55 |
It has been moved to `scripts/` and marked deprecated. Switch to the standard HuggingFace path:
|
|
@@ -62,15 +61,17 @@ processor = ViTImageProcessor.from_pretrained("buildborderless/CommunityForensic
|
|
| 62 |
|
| 63 |
### If you were using the ONNX repo
|
| 64 |
|
| 65 |
-
The separate [`buildborderless/CommunityForensics-DeepfakeDet-ViT-ONNX`](https://huggingface.co/buildborderless/CommunityForensics-DeepfakeDet-ViT-ONNX) repo is now deprecated. All ONNX models
|
| 66 |
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
|
|
|
|
|
|
| 70 |
|
| 71 |
-
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
```python
|
| 76 |
from transformers import ViTForImageClassification, ViTImageProcessor
|
|
@@ -89,35 +90,54 @@ print(f"fake: {fake_prob:.4f}, real: {1 - fake_prob:.4f}")
|
|
| 89 |
print(f"verdict: {'fake' if fake_prob > 0.5 else 'real'}")
|
| 90 |
```
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
---
|
| 93 |
|
| 94 |
-
## ONNX Variants
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
| Variant | Size | Speed (CPU) | Accuracy | Best For |
|
| 99 |
|---|---|---|---|---|
|
| 100 |
-
| `model.onnx` (full) |
|
| 101 |
-
| `
|
| 102 |
-
| `
|
| 103 |
-
| `
|
| 104 |
-
| `
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
| `model_q4f16.onnx` | 21 MB | β
β
| β
β
β
| Smallest file, mobile/web |
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
```python
|
| 112 |
-
import onnxruntime as ort
|
| 113 |
-
|
| 114 |
|
| 115 |
session = ort.InferenceSession("onnx/model_int8.onnx")
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
```
|
| 122 |
|
| 123 |
---
|
|
@@ -125,12 +145,12 @@ logits = output[0][0] # shape [2]: [real_score, fake_score]
|
|
| 125 |
## Model Details
|
| 126 |
|
| 127 |
- **Developed by**: Jeongsoo Park and Andrew Owens, University of Michigan
|
| 128 |
-
- **HF integration + ONNX**: Borderless
|
| 129 |
- **Model type**: Vision Transformer (ViT-Small)
|
| 130 |
- **License**: MIT
|
| 131 |
-
- **Input**: RGB image, resized to 440
|
| 132 |
- **Output**: single logit β sigmoid β fake probability
|
| 133 |
-
- **Architecture**: hidden_size=384, 6 attention heads, 12 layers, patch_size=16
|
| 134 |
|
| 135 |
### Links
|
| 136 |
|
|
@@ -141,7 +161,11 @@ logits = output[0][0] # shape [2]: [real_score, fake_score]
|
|
| 141 |
|
| 142 |
---
|
| 143 |
|
| 144 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
## Citation
|
| 147 |
|
|
|
|
| 23 |
|
| 24 |
## IMPORTANT β Configuration Fix (July 2026)
|
| 25 |
|
| 26 |
+
**If you downloaded this model before July 22, 2026, your local copy has incorrect config and weights.** Apologies for the mess β this model was originally hastily put together as an internal proof-of-concept for a hackathon, and we never imagined it would quietly become one of the top image classification models on Hugging Face. This update is long overdue.
|
| 27 |
+
|
| 28 |
+
The `model.safetensors` has been regenerated from the correct training checkpoint and all metadata has been fixed. For a detailed breakdown of every change, see [CHANGELOG.md](CHANGELOG.md).
|
| 29 |
|
| 30 |
| Bug | Effect | Fixed Value |
|
| 31 |
|---|---|---|
|
| 32 |
+
| Wrong `model.safetensors` | Weights from different model (intermediate_size=3072, wrong classifier) | Regenerated from `pretrained_weights/model_v11_ViT_384_base_ckpt.pt` |
|
| 33 |
+
| `num_attention_heads: 12` | **Silently wrong** β attention sliced 12Γ32d instead of 6Γ64d | `6` |
|
| 34 |
+
| Preprocessor `size` | Squashed non-square images or no center-crop | `shortest_edge: 440` + `do_center_crop` |
|
| 35 |
+
| `num_classes: 2` / missing `id2label` | Wrong output format for single-class classifier | `1` (sigmoid output) |
|
| 36 |
+
|
| 37 |
+
### β οΈ Breaking change for older transformers versions
|
| 38 |
+
|
| 39 |
+
This model now requires `transformers >= 5.4.0` for correct image preprocessing. Versions older than 5.4.0 will crash with a `ValueError` when loading the preprocessor β this is intentional and prevents silently-squashed images. If upgrading is not an option, you can preprocess images manually (resize shortest edge β 440, center-crop β 384, CLIP-normalize) and pass `do_resize=False` to the processor.
|
| 40 |
|
| 41 |
### How to verify you have the fix
|
| 42 |
|
|
|
|
| 49 |
assert cfg["intermediate_size"] == 1536, "Still broken β re-download the model"
|
| 50 |
```
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
### If you were using the old custom wrapper (`modeling_vit_classifier.py`)
|
| 53 |
|
| 54 |
It has been moved to `scripts/` and marked deprecated. Switch to the standard HuggingFace path:
|
|
|
|
| 61 |
|
| 62 |
### If you were using the ONNX repo
|
| 63 |
|
| 64 |
+
The separate [`buildborderless/CommunityForensics-DeepfakeDet-ViT-ONNX`](https://huggingface.co/buildborderless/CommunityForensics-DeepfakeDet-ViT-ONNX) repo is now deprecated. All ONNX models are included here in `onnx/` with corrected weights. Old exports are archived in `onnx_legacy/`.
|
| 65 |
|
| 66 |
+
### Archived files
|
| 67 |
|
| 68 |
+
- `model_legacy.safetensors` β previous (incorrect) weights, frozen for reference
|
| 69 |
+
- `model_fixed.safetensors` β identical copy of the current `model.safetensors`
|
| 70 |
+
- `onnx_legacy/` β previous ONNX exports from the incorrect weights
|
| 71 |
|
| 72 |
+
---
|
| 73 |
+
|
| 74 |
+
## Quick Start
|
| 75 |
|
| 76 |
```python
|
| 77 |
from transformers import ViTForImageClassification, ViTImageProcessor
|
|
|
|
| 90 |
print(f"verdict: {'fake' if fake_prob > 0.5 else 'real'}")
|
| 91 |
```
|
| 92 |
|
| 93 |
+
## Dependencies
|
| 94 |
+
|
| 95 |
+
- `transformers >= 5.4.0` (**required** β older versions lack `shortest_edge` resize and will crash. Do not downgrade below 5.4.0 or images will be silently squashed.)
|
| 96 |
+
- `torch`, `torchvision`, `Pillow`
|
| 97 |
+
- `onnxruntime >= 1.27` (for ONNX models β install `onnxruntime` for CPU or `onnxruntime-gpu` for GPU)
|
| 98 |
+
|
| 99 |
---
|
| 100 |
|
| 101 |
+
## ONNX Variants (v1.1)
|
| 102 |
|
| 103 |
+
Five pre-exported ONNX models with different size/speed trade-offs. All use the corrected config (single-class sigmoid output).
|
| 104 |
|
| 105 |
| Variant | Size | Speed (CPU) | Accuracy | Best For |
|
| 106 |
|---|---|---|---|---|
|
| 107 |
+
| `model.onnx` (full) | 84 MB | β
β
β
| β
β
β
β
β
| Maximum accuracy, server-side |
|
| 108 |
+
| `model_int8.onnx` | 22 MB | β
β
β
β
β
| β
β
β
β
| **Fastest CPU**, general deployment |
|
| 109 |
+
| `model_uint8.onnx` | 22 MB | β
β
β
β
β
| β
β
β
β
| Fast CPU, unsigned variant |
|
| 110 |
+
| `model_quantized.onnx` | 22 MB | β
β
β
β
β
| β
β
β
β
| Alias of INT8 for compatibility |
|
| 111 |
+
| `model_q4.onnx` | 16 MB | β
β
β
| β
β
β
| Smallest, low disk/RAM |
|
| 112 |
+
|
| 113 |
+
**Which variant should I use?**
|
|
|
|
| 114 |
|
| 115 |
+
| Use case | Recommended variant | Why |
|
| 116 |
+
|---|---|---|
|
| 117 |
+
| Server-side, maximum accuracy | `model.onnx` (full) | No quantization loss, FP32 precision |
|
| 118 |
+
| General CPU deployment | `model_int8.onnx` | Fastest CPU inference, near-lossless |
|
| 119 |
+
| Disk/RAM constrained | `model_q4.onnx` | Smallest file size, slower inference |
|
| 120 |
|
| 121 |
```python
|
| 122 |
+
import onnxruntime as ort, numpy as np
|
| 123 |
+
from PIL import Image
|
| 124 |
|
| 125 |
session = ort.InferenceSession("onnx/model_int8.onnx")
|
| 126 |
+
|
| 127 |
+
# Preprocess: shortest edge β 440 (maintain aspect ratio), center-crop β 384, CLIP normalize
|
| 128 |
+
image = Image.open("image.jpg")
|
| 129 |
+
w, h = image.size
|
| 130 |
+
scale = 440 / min(w, h)
|
| 131 |
+
img = image.resize((int(w * scale), int(h * scale)))
|
| 132 |
+
left = (img.size[0] - 384) // 2
|
| 133 |
+
top = (img.size[1] - 384) // 2
|
| 134 |
+
img = img.crop((left, top, left + 384, top + 384))
|
| 135 |
+
arr = np.array(img, dtype=np.float32) / 255.0
|
| 136 |
+
arr = (arr - np.array([0.4815, 0.4578, 0.4082])) / np.array([0.2686, 0.2613, 0.2758])
|
| 137 |
+
arr = np.expand_dims(arr.transpose(2, 0, 1), 0)
|
| 138 |
+
|
| 139 |
+
logit = session.run(None, {"pixel_values": arr})[0][0, 0]
|
| 140 |
+
fake_prob = 1 / (1 + np.exp(-logit))
|
| 141 |
```
|
| 142 |
|
| 143 |
---
|
|
|
|
| 145 |
## Model Details
|
| 146 |
|
| 147 |
- **Developed by**: Jeongsoo Park and Andrew Owens, University of Michigan
|
| 148 |
+
- **HF integration + ONNX**: Han Yoon, Borderless / Ethix R&D
|
| 149 |
- **Model type**: Vision Transformer (ViT-Small)
|
| 150 |
- **License**: MIT
|
| 151 |
+
- **Input**: RGB image, shortest edge resized to 440 (aspect ratio preserved), center-cropped to 384Γ384, CLIP-normalized
|
| 152 |
- **Output**: single logit β sigmoid β fake probability
|
| 153 |
+
- **Architecture**: hidden_size=384, 6 attention heads, 12 layers, patch_size=16, intermediate_size=1536
|
| 154 |
|
| 155 |
### Links
|
| 156 |
|
|
|
|
| 161 |
|
| 162 |
---
|
| 163 |
|
| 164 |
+
## Coming Soon β v2
|
| 165 |
+
|
| 166 |
+
We're actively working on a significantly stronger model with an expanded dataset and novel detection concepts. Follow the repo for updates in the coming months.
|
| 167 |
+
|
| 168 |
+
---
|
| 169 |
|
| 170 |
## Citation
|
| 171 |
|