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
fix: use num_labels=1 instead of num_classes=1
Browse filesnum_classes=1 maps to num_labels=2 internally in ViTConfig,
creating [2,384] classifier that mismatches the safetensors.
num_labels=1 produces [1,384] — correct for single-class sigmoid.
- README.md +2 -2
- config.json +1 -1
README.md
CHANGED
|
@@ -38,7 +38,7 @@ The `model.safetensors` has been regenerated from the correct training checkpoin
|
|
| 38 |
| Wrong `model.safetensors` | Weights from different model (intermediate_size=3072, wrong classifier) | Regenerated from `pretrained_weights/model_v11_ViT_384_base_ckpt.pt` |
|
| 39 |
| `num_attention_heads: 12` | **Silently wrong** — attention sliced 12×32d instead of 6×64d | `6` |
|
| 40 |
| Preprocessor `size` | Squashed non-square images or no center-crop | `shortest_edge: 440` + `do_center_crop` |
|
| 41 |
-
| `num_classes: 2` /
|
| 42 |
|
| 43 |
### ⚠️ Breaking change for older transformers versions
|
| 44 |
|
|
@@ -50,7 +50,7 @@ This model now requires `transformers >= 5.4.0` for correct image preprocessing.
|
|
| 50 |
import json
|
| 51 |
with open("path/to/config.json") as f:
|
| 52 |
cfg = json.load(f)
|
| 53 |
-
assert cfg["
|
| 54 |
assert cfg["num_attention_heads"] == 6, "Still broken — re-download the model"
|
| 55 |
assert cfg["intermediate_size"] == 1536, "Still broken — re-download the model"
|
| 56 |
```
|
|
|
|
| 38 |
| Wrong `model.safetensors` | Weights from different model (intermediate_size=3072, wrong classifier) | Regenerated from `pretrained_weights/model_v11_ViT_384_base_ckpt.pt` |
|
| 39 |
| `num_attention_heads: 12` | **Silently wrong** — attention sliced 12×32d instead of 6×64d | `6` |
|
| 40 |
| Preprocessor `size` | Squashed non-square images or no center-crop | `shortest_edge: 440` + `do_center_crop` |
|
| 41 |
+
| `num_classes: 2` / no `num_labels` | Wrong output format for single-class classifier — `num_classes=1` maps to 2 labels internally | `num_labels: 1` (sigmoid output) |
|
| 42 |
|
| 43 |
### ⚠️ Breaking change for older transformers versions
|
| 44 |
|
|
|
|
| 50 |
import json
|
| 51 |
with open("path/to/config.json") as f:
|
| 52 |
cfg = json.load(f)
|
| 53 |
+
assert cfg["num_labels"] == 1, "Still broken — re-download the model"
|
| 54 |
assert cfg["num_attention_heads"] == 6, "Still broken — re-download the model"
|
| 55 |
assert cfg["intermediate_size"] == 1536, "Still broken — re-download the model"
|
| 56 |
```
|
config.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
| 14 |
"model_type": "vit",
|
| 15 |
"num_attention_heads": 6,
|
| 16 |
"num_channels": 3,
|
| 17 |
-
"
|
| 18 |
"num_hidden_layers": 12,
|
| 19 |
"patch_size": 16,
|
| 20 |
"qkv_bias": true,
|
|
|
|
| 14 |
"model_type": "vit",
|
| 15 |
"num_attention_heads": 6,
|
| 16 |
"num_channels": 3,
|
| 17 |
+
"num_labels": 1,
|
| 18 |
"num_hidden_layers": 12,
|
| 19 |
"patch_size": 16,
|
| 20 |
"qkv_bias": true,
|