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")# pip install -U transformers accelerate # 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
fix: address reviewer feedback — qualify claims, fix AGENTS.md, add quantization caveat
Browse files- CHANGELOG: remove '<0.004% across all' claim, explain portrait deviation
- AGENTS.md: num_labels=1 sigmoid output, updated ONNX sizes
- README: soften INT8 claims, add quantization accuracy note
- Low severity: trailing newline, expanded .gitignore
- .gitignore +7 -0
- AGENTS.md +3 -3
- CHANGELOG.md +4 -2
- README.md +3 -1
- scripts/modeling_vit_classifier.py +1 -1
.gitignore
CHANGED
|
@@ -2,3 +2,10 @@
|
|
| 2 |
__pycache__/
|
| 3 |
*.pyc
|
| 4 |
test_app/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
__pycache__/
|
| 3 |
*.pyc
|
| 4 |
test_app/
|
| 5 |
+
.pytest_cache/
|
| 6 |
+
.mypy_cache/
|
| 7 |
+
*.log
|
| 8 |
+
*.egg-info/
|
| 9 |
+
dist/
|
| 10 |
+
build/
|
| 11 |
+
REVIEWER*
|
AGENTS.md
CHANGED
|
@@ -5,11 +5,11 @@ Hugging Face model repo for `buildborderless/CommunityForensics-DeepfakeDet-ViT`
|
|
| 5 |
|
| 6 |
## Key files
|
| 7 |
- **`model.safetensors`** — HF-format weights (Git LFS — ensure `git lfs pull` after clone)
|
| 8 |
-
- **`config.json`** — `ViTForImageClassification` config (384×384, 6 heads,
|
| 9 |
-
- **`preprocessor_config.json`** — CLIP-style normalization, resize to 440, center-crop to 384
|
| 10 |
- **`modeling_vit_classifier.py`** — **DEPRECATED** (moved to `scripts/`). Use standard HF path below.
|
| 11 |
- **`pretrained_weights/`** — original `.pt` checkpoints from training (also LFS)
|
| 12 |
-
- **`onnx/`** — 5 pre-exported ONNX variants (
|
| 13 |
|
| 14 |
## Usage
|
| 15 |
The model is hosted on Hugging Face. The standard way to load it is via `transformers`:
|
|
|
|
| 5 |
|
| 6 |
## Key files
|
| 7 |
- **`model.safetensors`** — HF-format weights (Git LFS — ensure `git lfs pull` after clone)
|
| 8 |
+
- **`config.json`** — `ViTForImageClassification` config (384×384, 6 heads, num_labels=1, sigmoid output: real/fake)
|
| 9 |
+
- **`preprocessor_config.json`** — CLIP-style normalization, resize to shortest_edge=440, center-crop to 384
|
| 10 |
- **`modeling_vit_classifier.py`** — **DEPRECATED** (moved to `scripts/`). Use standard HF path below.
|
| 11 |
- **`pretrained_weights/`** — original `.pt` checkpoints from training (also LFS)
|
| 12 |
+
- **`onnx/`** — 5 pre-exported ONNX variants (15MB–84MB) for CPU/GPU deployment. See README for variant guide.
|
| 13 |
|
| 14 |
## Usage
|
| 15 |
The model is hosted on Hugging Face. The standard way to load it is via `transformers`:
|
CHANGELOG.md
CHANGED
|
@@ -86,14 +86,16 @@ The previous 8 ONNX variants (21–138 MB) — exported from the incorrect weigh
|
|
| 86 |
|
| 87 |
## Verification
|
| 88 |
|
| 89 |
-
The corrected model produces results
|
| 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
|
|
|
|
| 86 |
|
| 87 |
## Verification
|
| 88 |
|
| 89 |
+
The corrected model produces results closely matching the original timm-based training pipeline. Old vs new comparison across test images:
|
| 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, 720×1280) | 6.58% fake | 3.31% fake | 0.0327% |
|
| 95 |
| AI-generated sample | 99.97% fake | 99.48% fake | 0.0049% |
|
| 96 |
|
| 97 |
+
The portrait image (720×1280) shows the largest deviation (0.033%) due to PIL vs torchvision interpolation differences on extreme aspect ratios during the resize-to-440 step. Both paths classify every image identically (same verdict). For square and near-square images, diffs are consistently <0.005%.
|
| 98 |
+
|
| 99 |
---
|
| 100 |
|
| 101 |
## Known limitations — ONNX
|
README.md
CHANGED
|
@@ -121,9 +121,11 @@ Five pre-exported ONNX models with different size/speed trade-offs. All use the
|
|
| 121 |
| Use case | Recommended variant | Why |
|
| 122 |
|---|---|---|
|
| 123 |
| Server-side, maximum accuracy | `model.onnx` (full) | No quantization loss, FP32 precision |
|
| 124 |
-
| General CPU deployment | `model_int8.onnx` | Fastest CPU inference,
|
| 125 |
| Disk/RAM constrained | `model_q4.onnx` | Smallest file size, slower inference |
|
| 126 |
|
|
|
|
|
|
|
| 127 |
```python
|
| 128 |
import onnxruntime as ort, numpy as np
|
| 129 |
from PIL import Image
|
|
|
|
| 121 |
| Use case | Recommended variant | Why |
|
| 122 |
|---|---|---|
|
| 123 |
| Server-side, maximum accuracy | `model.onnx` (full) | No quantization loss, FP32 precision |
|
| 124 |
+
| General CPU deployment | `model_int8.onnx` | Fastest CPU inference, strong accuracy on real-world images |
|
| 125 |
| Disk/RAM constrained | `model_q4.onnx` | Smallest file size, slower inference |
|
| 126 |
|
| 127 |
+
> **Quantization note**: Dynamic quantization accuracy varies by input. On real-world photos and AI-generated images, all variants agree with FP32 within ~1%. On synthetic noise or extreme aspect ratios, quantized variants may diverge more. For maximum accuracy, use `model.onnx` (FP32).
|
| 128 |
+
|
| 129 |
```python
|
| 130 |
import onnxruntime as ort, numpy as np
|
| 131 |
from PIL import Image
|
scripts/modeling_vit_classifier.py
CHANGED
|
@@ -66,4 +66,4 @@ class ViTClassifier(nn.Module):
|
|
| 66 |
x = self.preprocess_input(x).to(self.device)
|
| 67 |
x = self.vit(x)
|
| 68 |
x = torch.nn.functional.sigmoid(x)
|
| 69 |
-
return x
|
|
|
|
| 66 |
x = self.preprocess_input(x).to(self.device)
|
| 67 |
x = self.vit(x)
|
| 68 |
x = torch.nn.functional.sigmoid(x)
|
| 69 |
+
return x
|