BREAKING CHANGES: PR #5

#6
by LPX55 - opened
Borderless R&D org

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_labels is now 1 β€” 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.onnx is retained as a byte-identical alias of model_int8.onnx for compatibility.
  • The 8 broken legacy variants (old [batch_size, 2] output) are archived under onnx_legacy/ β€” do not use them for new deployments.
  • Requires transformers >= 5.4.0; older versions lack shortest_edge resize 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.json contains "num_labels": 1.
  • transformers.__version__ is >= 5.4.0.
  • You are loading from onnx/ (or the model hub root), not onnx_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.

LPX55 pinned discussion

Sign up or log in to comment