wiltodelta commited on
Commit
46b331c
·
verified ·
1 Parent(s): b415bb6

Source-classify freeze (GitHub 58071bb)

Browse files
Files changed (7) hide show
  1. README.md +34 -53
  2. benchmark.py +14 -16
  3. config.json +4 -4
  4. demo.ipynb +5 -2
  5. infer.py +23 -0
  6. metrics.json +106 -12
  7. multi-provider-source-v7.npz +3 -0
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  license: apache-2.0
3
- library_name: numpy
4
  pipeline_tag: image-classification
5
  tags:
6
  - image-forensics
@@ -23,13 +23,13 @@ tags:
23
  - grok
24
  ---
25
 
26
- # RAIW multi-provider source-pipeline classifier (`multi-provider-source-v6`)
27
 
28
- This repository contains the compact (`15.52 MB`), CPU-only, pickle-free (`allow_pickle=False`) NumPy weights for the abstaining [`remove-ai-watermarks`](https://github.com/wiltodelta/remove-ai-watermarks) pixel source-pipeline classifier across **10 AI provider families** (`openai`, `google`, `bytedance`, `flux`, `stable_diffusion`, `meta`, `midjourney`, `ideogram`, `firefly`, `xai`) plus `unknown`, with Stage-2 model/export version attribution (`version_subfamily`).
29
 
30
  This model is **not a SynthID detector** and does not decode or verify any cryptographic or invisible watermark payload (`watermark_truth="unknown"`). Its labels describe complete generation and export pixel pipelines, so renderer, geometry, encoding, post-processing, and watermark state may be confounded. `unknown` does not mean that SynthID is absent, and a provider label does not prove that SynthID is present.
31
 
32
- ## Quickstart (pure NumPy, CPU-only, no PyTorch required)
33
 
34
  [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/wiltodelta/remove-ai-watermarks/blob/main/docs/source-classify-hf/demo.ipynb)
35
 
@@ -41,8 +41,10 @@ pip install "remove-ai-watermarks[source-classify]"
41
  import remove_ai_watermarks as raiw
42
 
43
  res = raiw.classify_source("image.jpg")
44
- print(res.label, res.version_subfamily, round(res.confidence, 4))
45
- # e.g. 'openai' 'openai:gpt_image_1_5' 0.9942 (or 'unknown' None 0.9815 on real photos)
 
 
46
  ```
47
 
48
  Command line (installed CLI or zero-setup `uv run` with the bundled `infer.py` and open-detector `benchmark.py`):
@@ -55,31 +57,46 @@ uv run https://huggingface.co/wiltodelta/raiw-source-classify/resolve/main/bench
55
  uv run https://huggingface.co/wiltodelta/raiw-source-classify/resolve/main/benchmark.py --tier frontier
56
  ```
57
 
58
- Try it in your browser on the [Remove AI Watermarks Hugging Face Space](https://huggingface.co/spaces/wiltodelta/remove-ai-watermarks) or at [raiw.cc](https://raiw.cc). Set `RAIW_SOURCE_CLASSIFY_WEIGHTS` to `multi-provider-source-v6.npz` or its parent directory for air-gapped deployments.
59
 
60
  ## Model architecture
61
 
62
- - **Input (`512-d`, `extract_512d_v4_features`):**
63
  - `112-d` adaptive overlapping native-tile truncated SRM micro-residuals across flat and textured regions.
64
  - `128-d` phase-resolved modulo-8 / modulo-16 sublattice energy, cropped-grid secondary-phase detection, interior VAE modulation, and `8x8` block-DCT quantization comb statistics.
65
  - `144-d` Moisan periodic-plus-smooth (`p + s`) spectral decomposition, radial decay profile, and continuous scale-invariant period-comb scanner.
66
  - `96-d` patch-averaged cross-channel spectral phase coherence, Bayer/Quad-Bayer CFA periodicity, heteroscedastic shot-noise slope, and radial chromatic-aberration alignment.
67
  - `32-d` explicit codec, aspect-ratio, scale, and social-recompression regime vector (`x[480:512]`).
68
- - **Stage 1 (`154` unit channels + `96` 2D multiplicative interaction gates across `10` canonical providers):**
69
- - Two-tower ensemble executed in pure NumPy: `5` multi-seed Regime-FiLM `LayerNorm` + `SiLU` residual MLP trunks (`12` provider/unknown/supported-AI logits + `45` subfamily logits) paired with `65` packed `HistGradientBoosting` specialist forests (global provider, subfamily, codec-regime, hard-domain veto, and `21` pairwise cross-AI disambiguator heads), trained with strict parent-disjoint geometry positives (`crop96_jpeg` + `resize_lanczos_jpeg`).
70
- - Decoupled Stage-1.5 router over the `558-d` gate-expanded feature vector (`multi-provider-source-v5` runtime schema): an `11`-channel regime-aware acceptance detector (per-provider acceptance channels plus a global supported-AI channel standardized against a regime-null baseline) paired with a prior-calibrated `LayerNorm` + `SiLU` conditional attribution MLP with linear skip projection (`attr_skip_w`), making provider attribution invariant to `unknown` threshold tightening.
 
 
71
  - **Stage 2 (`9` stacked blended version heads, `666-d`):**
72
  - Vectorized `HistGradientBoosting` tree ensembles blended with standardized linear heads over the `512-d` descriptor concatenated with the `154` Stage-1 unit scores (`666-d`) to predict the canonical model/export subfamily (`version_subfamily`).
73
- - **Artifact:** `multi-provider-source-v6.npz` (`allow_pickle=False`, `15.52 MB`)
74
- - **SHA-256:** `87868eea08b8b811999f675186b82b067c4de655981cb7f25114aac00b1dd284`
75
 
76
- The artifact contains only learned parameters, normalization constants, tree arrays, labels, and calibrated thresholds. It does not contain training images, paths, image hashes, embeddings, or a training catalog.
77
 
78
- ## Evaluation (`145,110` deduplicated feature views; `10,585` locked test)
79
 
80
- The operating point was selected strictly on disjoint calibration partitions (`8,363` primary calibration views, `3,011` social-recompressed real negatives, and `2,972` crop/resize development views across 16 fine-grained real-image varieties and group-locked `parent_sha256` families). On the `10,585`-image locked test split (`4,538` multi-variety `unknown` negatives + `6,047` AI provider images across native, resized, and social-recompressed views):
81
 
82
- - **Unified 10-provider router:** `99.93%` `unknown` specificity (`3 / 4,538` false positives, `0.07%` test `unknown` FPR; `0.00%` photographic FPR and `0.13%` non-photographic structured FPR), `83.28%` exact provider recall (`84.14%` on clean-provenance AI; `86.67%` any-AI recall; `92.45%` native, `92.95%` resized, and `77.06%` recompressed exact recall), `99.94%` any-AI precision when firing (`96.09%` exact-provider accuracy among classified AI; `95.93%` overall Stage-2 version accuracy given exact provider), and `0.9977` binary ROC-AUC / `0.9985` binary PR-AUC (`0.9977` mean standalone provider ROC-AUC).
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  | Provider | Test count | Standalone ROC AUC | Router recall | Router precision | Stage-2 version accuracy |
85
  |---|---:|---:|---:|---:|---:|
@@ -94,42 +111,6 @@ The operating point was selected strictly on disjoint calibration partitions (`8
94
  | `firefly` | 103 | 0.9948 | 61.2% | 91.3% | 100.0% |
95
  | `xai` | 48 | 0.9990 | 45.8% | 91.7% | 77.3% |
96
 
97
- ### Held-out real-image specificity by variety (`4,538` test negatives across 16 real classes + foreign AI)
98
-
99
- | Real-image variety | Test count | False positives | False-positive rate | Specificity |
100
- |---|---:|---:|---:|---:|
101
- | `photo` | 2,183 | 0 | 0.00% | 100.00% |
102
- | `photo_retouched` | 339 | 2 | 0.59% | 99.41% |
103
- | `classical_inpaint` | 17 | 0 | 0.00% | 100.00% |
104
- | `digital_art` | 440 | 1 | 0.23% | 99.77% |
105
- | `game_art` | 174 | 0 | 0.00% | 100.00% |
106
- | `vector` | 135 | 0 | 0.00% | 100.00% |
107
- | `interface` | 180 | 0 | 0.00% | 100.00% |
108
- | `diagram` | 98 | 0 | 0.00% | 100.00% |
109
- | `chart_data_viz` | 159 | 0 | 0.00% | 100.00% |
110
- | `technical_architecture` | 84 | 0 | 0.00% | 100.00% |
111
- | `procedural_graphic` | 13 | 0 | 0.00% | 100.00% |
112
- | `document` | 165 | 0 | 0.00% | 100.00% |
113
- | `gov_scientific_doc` | 32 | 0 | 0.00% | 100.00% |
114
- | `receipt_invoice` | 181 | 0 | 0.00% | 100.00% |
115
- | `print_publishing` | 229 | 0 | 0.00% | 100.00% |
116
- | `stress_recompressed` | 103 | 0 | 0.00% | 100.00% |
117
- | `foreign_ai` | 6 | 0 | 0.00% | 100.00% |
118
-
119
- ### External blind multi-variety real-image verification (`selective-v8`, `2,267` untouched images)
120
-
121
- Evaluated on the external `selective-v8` blind real-image cohorts (`2,267` images; `2,265` strictly parent-disjoint from `locked_test`): **1 / 2,267 false positives (`0.04%` overall FPR, `99.96%` specificity)**, plus **0 / 60 false positives (`0.00%` FPR)** on external phone thermal receipts.
122
-
123
- | Blind `selective-v8` cell | Evaluated | False positives | False-positive rate | Specificity |
124
- |---|---:|---:|---:|---:|
125
- | `photo` | 450 | 0 | 0.00% | 100.00% |
126
- | `vector` | 332 | 0 | 0.00% | 100.00% |
127
- | `game_art` | 230 | 0 | 0.00% | 100.00% |
128
- | `interface` | 342 | 0 | 0.00% | 100.00% |
129
- | `diagram` | 305 | 0 | 0.00% | 100.00% |
130
- | `document` | 308 | 0 | 0.00% | 100.00% |
131
- | `stress_recompressed` | 300 | 1 | 0.33% | 99.67% |
132
-
133
  ## Intended use
134
 
135
  Install `remove-ai-watermarks[source-classify]` and call the explicit Python API `classify_source(path)` or CLI command `remove-ai-watermarks classify-source <IMAGE>`. `identify` does not run this model. Set `RAIW_SOURCE_CLASSIFY_WEIGHTS` to the `.npz` file or its parent directory for offline deployments.
 
1
  ---
2
  license: apache-2.0
3
+ library_name: onnx
4
  pipeline_tag: image-classification
5
  tags:
6
  - image-forensics
 
23
  - grok
24
  ---
25
 
26
+ # RAIW multi-provider source-pipeline classifier (`multi-provider-source-v7`)
27
 
28
+ This repository contains the unified (`55.53 MB`), CPU-only, pickle-free (`allow_pickle=False`) multimodal weights for the abstaining [`remove-ai-watermarks`](https://github.com/wiltodelta/remove-ai-watermarks) pixel source-pipeline and synthetic-image classifier across **10 AI provider families** (`openai`, `google`, `bytedance`, `flux`, `stable_diffusion`, `meta`, `midjourney`, `ideogram`, `firefly`, `xai`) plus `unknown`, with Stage-2 model/export version attribution (`version_subfamily`) and calibrated binary synthetic detection (`synthetic_detected`, `synthetic_probability`) under foreign resize and container transcoding.
29
 
30
  This model is **not a SynthID detector** and does not decode or verify any cryptographic or invisible watermark payload (`watermark_truth="unknown"`). Its labels describe complete generation and export pixel pipelines, so renderer, geometry, encoding, post-processing, and watermark state may be confounded. `unknown` does not mean that SynthID is absent, and a provider label does not prove that SynthID is present.
31
 
32
+ ## Quickstart (NumPy + ONNX Runtime CPU, no PyTorch required)
33
 
34
  [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/wiltodelta/remove-ai-watermarks/blob/main/docs/source-classify-hf/demo.ipynb)
35
 
 
41
  import remove_ai_watermarks as raiw
42
 
43
  res = raiw.classify_source("image.jpg")
44
+ print(res.label, res.version_subfamily, res.synthetic_detected, round(res.synthetic_probability, 4))
45
+ # e.g. 'openai' 'openai:gpt_image_1_5' True 0.9942 (native AI export)
46
+ # e.g. 'unknown' None True 0.9412 (foreign 1024x1024 transcoded AI image)
47
+ # e.g. 'unknown' None False 0.0084 (camera photo, UI screenshot, diagram, or scanned document)
48
  ```
49
 
50
  Command line (installed CLI or zero-setup `uv run` with the bundled `infer.py` and open-detector `benchmark.py`):
 
57
  uv run https://huggingface.co/wiltodelta/raiw-source-classify/resolve/main/benchmark.py --tier frontier
58
  ```
59
 
60
+ Try it in your browser on the [Remove AI Watermarks Hugging Face Space](https://huggingface.co/spaces/wiltodelta/remove-ai-watermarks) or at [raiw.cc](https://raiw.cc). Set `RAIW_SOURCE_CLASSIFY_WEIGHTS` to `multi-provider-source-v7.npz` or its parent directory for air-gapped deployments.
61
 
62
  ## Model architecture
63
 
64
+ - **Physics, sublattice, sensor, and codec branch (`512-d`, `extract_512d_v4_features`):**
65
  - `112-d` adaptive overlapping native-tile truncated SRM micro-residuals across flat and textured regions.
66
  - `128-d` phase-resolved modulo-8 / modulo-16 sublattice energy, cropped-grid secondary-phase detection, interior VAE modulation, and `8x8` block-DCT quantization comb statistics.
67
  - `144-d` Moisan periodic-plus-smooth (`p + s`) spectral decomposition, radial decay profile, and continuous scale-invariant period-comb scanner.
68
  - `96-d` patch-averaged cross-channel spectral phase coherence, Bayer/Quad-Bayer CFA periodicity, heteroscedastic shot-noise slope, and radial chromatic-aberration alignment.
69
  - `32-d` explicit codec, aspect-ratio, scale, and social-recompression regime vector (`x[480:512]`).
70
+ - **Visual multi-task branch (`ViT-S/16 @ 384` weight-fp16 ONNX, `vit_onnx_bytes`):**
71
+ - Permissive MIT `ViT-S/16 @ 384` frozen visual stem (`OwensLab/commfor-model-384` / `TensorFold/detectra-v1` lineage) paired with open-world multi-task readout heads (`[cls_tok(384), patch_mean(384), patch_std(384)]` -> `28-d` vector `[orig_syn(0), prov_10(1:11), foreign_ai(11), real_non_ai(12), gfx_veto(13), dom_syn(14), emb(15:28)]`) stored as a weight-fp16 -> fp32-compute ONNX graph inside the pickle-free `.npz` bundle and executed via `onnxruntime` on CPU, plus a conditional `short_edge=672` 2-crop gray-zone pass for widescreen native exports.
72
+ - **Stage 1 & 1.5 (`154` unit channels + `96` 2D gates + `82-d` open-set provider head + `67-d` open-world synthetic fusion):**
73
+ - Two-tower `512-d` ensemble in pure NumPy (`5` multi-seed Regime-FiLM `LayerNorm` + `SiLU` residual MLP trunks + `65` packed `HistGradientBoosting` specialist forests) feeding an `11`-channel regime-standardized acceptance detector, conditional attribution MLP, and an `82-d -> 64-d -> 12` open-set multimodal provider head (`10` providers vs `logsumexp(foreign_ai, real_non_ai)`) that recovers exact `label` on transcoded 10-provider images while keeping unseen generators as honest `unknown`.
74
+ - Anchored `67-d -> 48-d -> 1` `LayerNorm` + `SiLU` skip multimodal synthetic fusion head combining the `28-d` ViT output, bounded `11`-channel Stage-1.5 physics acceptance vector, positive/negative global physics cues, the `26-d` codec-invariant born-digital graphics score, and the `32-d` regime block. When container laundering or an unseen generator prevents 10-family attribution, `label` honestly abstains as `unknown` while `synthetic_detected` and `synthetic_probability` retain binary synthetic recall without sacrificing screenshot, diagram, or document specificity.
75
  - **Stage 2 (`9` stacked blended version heads, `666-d`):**
76
  - Vectorized `HistGradientBoosting` tree ensembles blended with standardized linear heads over the `512-d` descriptor concatenated with the `154` Stage-1 unit scores (`666-d`) to predict the canonical model/export subfamily (`version_subfamily`).
77
+ - **Artifact:** `multi-provider-source-v7.npz` (`allow_pickle=False`, `55.53 MB`)
78
+ - **SHA-256:** `4faef51eea48f8194ee804fab1782c48d626384e115e2ef70884f8e8393d7eb1`
79
 
80
+ The artifact contains only learned parameters, weight-fp16 ONNX graph bytes, normalization constants, tree arrays, labels, and calibrated thresholds. It does not contain training images, paths, image hashes, embeddings, or a training catalog.
81
 
82
+ ## Evaluation
83
 
84
+ ### Open 578-image multi-regime benchmark (`benchmark.py`)
85
 
86
+ Evaluated end-to-end via `classify_source` on `200` non-AI false-positive traps (`50` camera photos, `50` UI screenshots, `50` science diagrams, `50` scanned documents), `125` untouched native AI exports (`25` each across FLUX.1-dev, GPT-Image-1, Gemini Nano Banana Pro, SDXL, Midjourney v6.1), and `253` square-resized/transcoded crowd-arena AI images (`Rapidata` and `bitmind` `1024x1024` JPEG/WebP/PNG):
87
+
88
+ - **Non-AI false-positive rate (`200` traps):** **`0.0%` (`0 / 200`)** across all four slices (`0%` camera photo, `0%` UI screenshot, `0%` science diagram, `0%` scanned document) and **`100.0%` precision**.
89
+ - **Native AI exports (`125`):** **`99.2%` binary synthetic recall** (`124 / 125`, including `96.0%` on widescreen `1408x768` Gemini Nano Banana Pro and `100.0%` on widescreen `1456x816` Midjourney v6.1, FLUX.1-dev, GPT-Image-1, and SDXL) and **`71.2%` exact generator attribution** (`89 / 125`).
90
+ - **Transcoded crowd-arena AI (`253`):** **`87.0%` binary synthetic recall** (`220 / 253`, up from `30.4%` in `v6`) and **`18.6%` exact generator attribution** (`47 / 253`, up from `9.5%` in `v6` via open-set multimodal attribution while keeping honest `unknown` abstention when provider identity is unrecoverable; **`329 ms`** median single-image CPU latency).
91
+
92
+ ### Internal locked test & external blind multi-variety verification
93
+
94
+ The operating point was selected strictly on parent-disjoint calibration partitions (`parent_sha256` grouped). Across sealed held-out benchmarks:
95
+
96
+ - **End-to-end RGB + ViT on `4,415` resolved `locked_test` parents (`2,074` supported AI + `2,341` real non-AI across 15 real varieties):** **`0.09%` real synthetic FPR** (`2 / 2,341` false positives, `0` on camera photos, UI, diagrams, vectors, and documents; **`0.04%` real provider FPR**, `1 / 2,341`), **`97.54%` native synthetic recall** (`92.82%` exact provider recall; **`0.9995` ROC-AUC / `0.9994` PR-AUC**), and **`65.43%` synthetic recall** (`25.41%` exact provider recall) after forced `1024x1024` JPEG/WebP arena transcoding across all 10 provider families (`0.9740` ROC-AUC).
97
+ - **Sealed open-world foreign-generator check (`84` held-out views outside the 10 provider families):** **`97.62%` honest `label="unknown"` abstention** (`82 / 84`; `0 / 58` false attributions on `cal-fit` foreign AI) with **`69.05%` binary synthetic recall** across unseen generators including hard-flash DreamBooth style transfers.
98
+ - **External blind `selective-v8` end-to-end RGB + ViT (`1,512` untouched real-variety parents):** **`0 / 1,297` (`0.00%` FPR)** across all camera photo (`0 / 25`), `diagram` (`0 / 305`), `document` (`0 / 308`), `interface` (`0 / 327`), and `vector` (`0 / 332`) parents, and `4 / 215` on `game_art` (`4 / 1,512 = 0.26%` overall synthetic FPR; **`0 / 1,512 = 0.00%` provider FPR**; `1 / 2,267 = 0.04%` across all `2,267` `512-d` rows).
99
+ - **Full `10,585`-row `locked_test` `512-d` provider router:** `99.93%` `unknown` specificity (`3 / 4,538` false positives, `0.07%` FPR), `83.28%` exact provider recall (`92.45%` native, `92.95%` resized, `77.06%` social-recompressed), `99.94%` any-AI precision, and `95.93%` Stage-2 version accuracy given exact provider.
100
 
101
  | Provider | Test count | Standalone ROC AUC | Router recall | Router precision | Stage-2 version accuracy |
102
  |---|---:|---:|---:|---:|---:|
 
111
  | `firefly` | 103 | 0.9948 | 61.2% | 91.3% | 100.0% |
112
  | `xai` | 48 | 0.9990 | 45.8% | 91.7% | 77.3% |
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  ## Intended use
115
 
116
  Install `remove-ai-watermarks[source-classify]` and call the explicit Python API `classify_source(path)` or CLI command `remove-ai-watermarks classify-source <IMAGE>`. `identify` does not run this model. Set `RAIW_SOURCE_CLASSIFY_WEIGHTS` to the `.npz` file or its parent directory for offline deployments.
benchmark.py CHANGED
@@ -4,7 +4,7 @@
4
  # dependencies = [
5
  # "remove-ai-watermarks[source-classify]>=0.62.1",
6
  # "huggingface-hub>=0.26.0",
7
- # "onnxruntime>=1.19.0",
8
  # "peft>=0.14.0",
9
  # "pyarrow>=17.0.0",
10
  # "safetensors>=0.4.5",
@@ -19,7 +19,7 @@
19
  Streams pinned, un-gated datasets directly from Hugging Face Hub at immutable commit SHAs
20
  (no private files, no manual dataset setup) across three evaluation regimes:
21
  1. Non-AI false-positive traps (camera photos, UI screenshots, science diagrams,
22
- scanned receipts and invoices).
23
  2. Untouched native AI generator exports across FLUX.1-dev, OpenAI GPT-Image-1,
24
  Google Gemini Nano Banana Pro, Stable Diffusion XL, and Midjourney v6.1.
25
  3. Transcoded crowd-arena AI outputs across multi-provider preference shards re-encoded
@@ -209,10 +209,10 @@ NON_AI_SLICES: tuple[ParquetSliceSpec, ...] = (
209
  limit=50,
210
  ),
211
  ParquetSliceSpec(
212
- category="receipt_invoice",
213
- dataset_id="mychen76/invoices-and-receipts_ocr_v1",
214
- revision="83835c87346de32ac9223bdce5264e69ef3366ad",
215
- parquet_path="data/test-00000-of-00001-af2d92d1cee28514.parquet",
216
  limit=50,
217
  ),
218
  )
@@ -723,7 +723,7 @@ def _evaluate_rgb_detector(
723
 
724
 
725
  def evaluate_raiw(samples: list[SampleItem]) -> dict[str, Any]:
726
- """Evaluate `wiltodelta/raiw-source-classify` in pure NumPy on CPU."""
727
  from remove_ai_watermarks import source_classify as sc
728
 
729
  weights_file = sc.resolve_weights_path()
@@ -733,7 +733,7 @@ def evaluate_raiw(samples: list[SampleItem]) -> dict[str, Any]:
733
  with Image.open(io.BytesIO(raw_bytes)) as im:
734
  res = sc.classify_source(im, weights_path=weights_file)
735
  return {
736
- "pred_ai": res.label != "unknown",
737
  "pred_provider": None if res.label == "unknown" else res.label,
738
  }
739
 
@@ -749,16 +749,14 @@ def evaluate_raiw(samples: list[SampleItem]) -> dict[str, Any]:
749
  preds_by_idx[idx] = _classify_one(samples[idx].raw_bytes)
750
  latencies_ms.append((time.perf_counter() - t0) * 1000.0)
751
 
752
- untimed_indices = [idx for idx in range(len(samples)) if idx not in lat_idx_set]
753
- with ThreadPoolExecutor(max_workers=4) as pool:
754
- untimed_preds = list(pool.map(lambda i: _classify_one(samples[i].raw_bytes), untimed_indices))
755
- for idx, pred in zip(untimed_indices, untimed_preds, strict=True):
756
- preds_by_idx[idx] = pred
757
 
758
  return _summarize_predictions(
759
  model_id=sc.WEIGHTS_REPO,
760
  revision=sc.WEIGHTS_REVISION,
761
- runtime="NumPy + OpenCV (CPU)",
762
  weights_mb=weights_mb,
763
  license_id="apache-2.0",
764
  median_cpu_ms=round(statistics.median(latencies_ms), 1),
@@ -1211,7 +1209,7 @@ def format_markdown_table(results: list[dict[str, Any]]) -> str:
1211
  n_arena = results[0]["arena_ai"]["total"] if results else 0
1212
 
1213
  header = (
1214
- f"| Model | License | Size | CPU ms | Non-AI FPR (`{n_non_ai}`) | Photo / UI / Diag / Rcpt FPR "
1215
  f"| Native AI Recall (`{n_native}`) | Native Attribution (`{n_native}`) "
1216
  f"| Arena AI Recall (`{n_arena}`) | Arena Attribution (`{n_arena}`) | Precision |"
1217
  )
@@ -1223,7 +1221,7 @@ def format_markdown_table(results: list[dict[str, Any]]) -> str:
1223
  arn = r["arena_ai"]
1224
  slice_str = (
1225
  f"{sf.get('camera_photo', 0.0):.0f}% / {sf.get('ui_screenshot', 0.0):.0f}% / "
1226
- f"{sf.get('science_diagram', 0.0):.0f}% / {sf.get('receipt_invoice', 0.0):.0f}%"
1227
  )
1228
  lines.append(
1229
  f"| `{r['model_id']}` | `{r['license']}` | {r['weights_mb']:.1f} MB | {r['median_cpu_ms']:.0f} ms "
 
4
  # dependencies = [
5
  # "remove-ai-watermarks[source-classify]>=0.62.1",
6
  # "huggingface-hub>=0.26.0",
7
+ # "onnxruntime>=1.24.0",
8
  # "peft>=0.14.0",
9
  # "pyarrow>=17.0.0",
10
  # "safetensors>=0.4.5",
 
19
  Streams pinned, un-gated datasets directly from Hugging Face Hub at immutable commit SHAs
20
  (no private files, no manual dataset setup) across three evaluation regimes:
21
  1. Non-AI false-positive traps (camera photos, UI screenshots, science diagrams,
22
+ scanned documents).
23
  2. Untouched native AI generator exports across FLUX.1-dev, OpenAI GPT-Image-1,
24
  Google Gemini Nano Banana Pro, Stable Diffusion XL, and Midjourney v6.1.
25
  3. Transcoded crowd-arena AI outputs across multi-provider preference shards re-encoded
 
209
  limit=50,
210
  ),
211
  ParquetSliceSpec(
212
+ category="scanned_document",
213
+ dataset_id="lmms-lab/DocVQA",
214
+ revision="539088ef8a8ada01ac8e2e6d4e372586748a265e",
215
+ parquet_path="DocVQA/test-00000-of-00006.parquet",
216
  limit=50,
217
  ),
218
  )
 
723
 
724
 
725
  def evaluate_raiw(samples: list[SampleItem]) -> dict[str, Any]:
726
+ """Evaluate `wiltodelta/raiw-source-classify` on CPU."""
727
  from remove_ai_watermarks import source_classify as sc
728
 
729
  weights_file = sc.resolve_weights_path()
 
733
  with Image.open(io.BytesIO(raw_bytes)) as im:
734
  res = sc.classify_source(im, weights_path=weights_file)
735
  return {
736
+ "pred_ai": bool(getattr(res, "synthetic_detected", res.label != "unknown")),
737
  "pred_provider": None if res.label == "unknown" else res.label,
738
  }
739
 
 
749
  preds_by_idx[idx] = _classify_one(samples[idx].raw_bytes)
750
  latencies_ms.append((time.perf_counter() - t0) * 1000.0)
751
 
752
+ for idx in range(len(samples)):
753
+ if idx not in lat_idx_set:
754
+ preds_by_idx[idx] = _classify_one(samples[idx].raw_bytes)
 
 
755
 
756
  return _summarize_predictions(
757
  model_id=sc.WEIGHTS_REPO,
758
  revision=sc.WEIGHTS_REVISION,
759
+ runtime="NumPy + ONNX Runtime (CPU)",
760
  weights_mb=weights_mb,
761
  license_id="apache-2.0",
762
  median_cpu_ms=round(statistics.median(latencies_ms), 1),
 
1209
  n_arena = results[0]["arena_ai"]["total"] if results else 0
1210
 
1211
  header = (
1212
+ f"| Model | License | Size | CPU ms | Non-AI FPR (`{n_non_ai}`) | Photo / UI / Diag / Doc FPR "
1213
  f"| Native AI Recall (`{n_native}`) | Native Attribution (`{n_native}`) "
1214
  f"| Arena AI Recall (`{n_arena}`) | Arena Attribution (`{n_arena}`) | Precision |"
1215
  )
 
1221
  arn = r["arena_ai"]
1222
  slice_str = (
1223
  f"{sf.get('camera_photo', 0.0):.0f}% / {sf.get('ui_screenshot', 0.0):.0f}% / "
1224
+ f"{sf.get('science_diagram', 0.0):.0f}% / {sf.get('scanned_document', 0.0):.0f}%"
1225
  )
1226
  lines.append(
1227
  f"| `{r['model_id']}` | `{r['license']}` | {r['weights_mb']:.1f} MB | {r['median_cpu_ms']:.0f} ms "
config.json CHANGED
@@ -1,8 +1,8 @@
1
  {
2
  "model_type": "raiw-source-classify",
3
- "schema": "multi-provider-source-v5",
4
- "artifact_file": "multi-provider-source-v6.npz",
5
- "artifact_sha256": "87868eea08b8b811999f675186b82b067c4de655981cb7f25114aac00b1dd284",
6
  "feature_dimension": 512,
7
  "stacked_stage2_dimension": 666,
8
  "providers": [
@@ -18,7 +18,7 @@
18
  "xai"
19
  ],
20
  "abstain_label": "unknown",
21
- "library_name": "numpy",
22
  "package": "remove-ai-watermarks[source-classify]",
23
  "license": "apache-2.0"
24
  }
 
1
  {
2
  "model_type": "raiw-source-classify",
3
+ "schema": "multi-provider-source-v7",
4
+ "artifact_file": "multi-provider-source-v7.npz",
5
+ "artifact_sha256": "4faef51eea48f8194ee804fab1782c48d626384e115e2ef70884f8e8393d7eb1",
6
  "feature_dimension": 512,
7
  "stacked_stage2_dimension": 666,
8
  "providers": [
 
18
  "xai"
19
  ],
20
  "abstain_label": "unknown",
21
+ "library_name": "onnx",
22
  "package": "remove-ai-watermarks[source-classify]",
23
  "license": "apache-2.0"
24
  }
demo.ipynb CHANGED
@@ -5,12 +5,13 @@
5
  "id": "cell-intro",
6
  "metadata": {},
7
  "source": [
8
- "# RAIW 10-provider source-pipeline classifier (`multi-provider-source-v6`)\n",
9
  "\n",
10
- "This notebook demonstrates the compact (`15.52 MB`), CPU-only, pickle-free (`allow_pickle=False`) NumPy classifier published at [`wiltodelta/raiw-source-classify`](https://huggingface.co/wiltodelta/raiw-source-classify).\n",
11
  "\n",
12
  "- **10 AI provider families + open-set abstention:** `openai`, `google`, `bytedance`, `flux`, `stable_diffusion`, `meta`, `midjourney`, `ideogram`, `firefly`, `xai`, plus `unknown`.\n",
13
  "- **Stage-2 model/version attribution (`version_subfamily`):** identifies specific generator subfamilies when an image clears the calibrated regime-aware acceptance threshold.\n",
 
14
  "- **Scope boundary:** pixel source-pipeline classification is **not** provenance verification and **not** a SynthID or invisible-watermark detector (`watermark_truth=\"unknown\"`)."
15
  ]
16
  },
@@ -102,6 +103,8 @@
102
  " {\n",
103
  " \"label\": res.label,\n",
104
  " \"version_subfamily\": res.version_subfamily,\n",
 
 
105
  " \"reason\": res.reason,\n",
106
  " \"confidence\": round(res.confidence, 4),\n",
107
  " \"watermark_truth\": res.watermark_truth,\n",
 
5
  "id": "cell-intro",
6
  "metadata": {},
7
  "source": [
8
+ "# RAIW 10-provider source-pipeline classifier (`multi-provider-source-v7`)\n",
9
  "\n",
10
+ "This notebook demonstrates the unified (`55.53 MB`), CPU-only, pickle-free (`allow_pickle=False`) multimodal classifier published at [`wiltodelta/raiw-source-classify`](https://huggingface.co/wiltodelta/raiw-source-classify).\n",
11
  "\n",
12
  "- **10 AI provider families + open-set abstention:** `openai`, `google`, `bytedance`, `flux`, `stable_diffusion`, `meta`, `midjourney`, `ideogram`, `firefly`, `xai`, plus `unknown`.\n",
13
  "- **Stage-2 model/version attribution (`version_subfamily`):** identifies specific generator subfamilies when an image clears the calibrated regime-aware acceptance threshold.\n",
14
+ "- **Calibrated binary synthetic detection (`synthetic_detected`, `synthetic_probability`):** retains synthetic recall across foreign resize and container transcoding while abstaining from unidentifiable generator attribution (`label=\"unknown\"`).\n",
15
  "- **Scope boundary:** pixel source-pipeline classification is **not** provenance verification and **not** a SynthID or invisible-watermark detector (`watermark_truth=\"unknown\"`)."
16
  ]
17
  },
 
103
  " {\n",
104
  " \"label\": res.label,\n",
105
  " \"version_subfamily\": res.version_subfamily,\n",
106
+ " \"synthetic_detected\": res.synthetic_detected,\n",
107
+ " \"synthetic_probability\": round(res.synthetic_probability, 4),\n",
108
  " \"reason\": res.reason,\n",
109
  " \"confidence\": round(res.confidence, 4),\n",
110
  " \"watermark_truth\": res.watermark_truth,\n",
infer.py CHANGED
@@ -126,6 +126,22 @@ def inspect_weights(weights_path: Path | None = None) -> dict[str, Any]:
126
  version_subfamilies[prov] = subs
127
 
128
  array_count = len(data.files)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  summary: dict[str, Any] = {
131
  "artifact_file": resolved.name,
@@ -144,6 +160,10 @@ def inspect_weights(weights_path: Path | None = None) -> dict[str, Any]:
144
  }
145
  if global_ai_threshold is not None:
146
  summary["global_ai_threshold"] = global_ai_threshold
 
 
 
 
147
  return summary
148
 
149
 
@@ -198,8 +218,11 @@ def _write_human_predictions(rows: Sequence[dict[str, Any]]) -> None:
198
  for row in rows:
199
  sub = row.get("version_subfamily") or "-"
200
  conf = float(row.get("confidence", 0.0))
 
 
201
  sys.stdout.write(
202
  f"{row['path']}\tlabel={row['label']}\tversion={sub}\t"
 
203
  f"confidence={conf:.4f}\treason={row['reason']}\twatermark_truth={row['watermark_truth']}\n"
204
  )
205
 
 
126
  version_subfamilies[prov] = subs
127
 
128
  array_count = len(data.files)
129
+ synthetic_threshold: float | None = None
130
+ vit_onnx_size_bytes: int | None = None
131
+ if "syn_threshold" in data:
132
+ synthetic_threshold = round(float(np.asarray(data["syn_threshold"], dtype=np.float64).squeeze()), 6)
133
+ if "vit_onnx_bytes" in data:
134
+ import numpy.lib.format as npfmt
135
+
136
+ zf = getattr(data, "zip", None)
137
+ if zf is not None and "vit_onnx_bytes.npy" in zf.namelist():
138
+ with zf.open("vit_onnx_bytes.npy") as handle:
139
+ ver = npfmt.read_magic(handle)
140
+ hdr_fn = npfmt.read_array_header_1_0 if ver == (1, 0) else npfmt.read_array_header_2_0
141
+ shape, _fortran, _dtype = hdr_fn(handle)
142
+ vit_onnx_size_bytes = int(shape[0]) if len(shape) == 1 else int(np.prod(shape))
143
+ else:
144
+ vit_onnx_size_bytes = int(np.asarray(data["vit_onnx_bytes"], dtype=np.uint8).size)
145
 
146
  summary: dict[str, Any] = {
147
  "artifact_file": resolved.name,
 
160
  }
161
  if global_ai_threshold is not None:
162
  summary["global_ai_threshold"] = global_ai_threshold
163
+ if synthetic_threshold is not None:
164
+ summary["synthetic_threshold"] = synthetic_threshold
165
+ if vit_onnx_size_bytes is not None:
166
+ summary["vit_onnx_size_bytes"] = vit_onnx_size_bytes
167
  return summary
168
 
169
 
 
218
  for row in rows:
219
  sub = row.get("version_subfamily") or "-"
220
  conf = float(row.get("confidence", 0.0))
221
+ syn_flag = "yes" if row.get("synthetic_detected") else "no"
222
+ syn_prob = float(row.get("synthetic_probability", 0.0))
223
  sys.stdout.write(
224
  f"{row['path']}\tlabel={row['label']}\tversion={sub}\t"
225
+ f"synthetic={syn_flag}({syn_prob:.4f})\t"
226
  f"confidence={conf:.4f}\treason={row['reason']}\twatermark_truth={row['watermark_truth']}\n"
227
  )
228
 
metrics.json CHANGED
@@ -1,9 +1,13 @@
1
  {
2
- "claim": "abstaining 10-provider source-pipeline classification with version subfamily attribution; not SynthID detection",
3
- "schema": "multi-provider-source-v5",
4
- "artifact_file": "multi-provider-source-v6.npz",
5
- "artifact_sha256": "87868eea08b8b811999f675186b82b067c4de655981cb7f25114aac00b1dd284",
 
6
  "feature_dimension": 512,
 
 
 
7
  "stacked_stage2_dimension": 666,
8
  "classes": [
9
  "openai",
@@ -25,7 +29,104 @@
25
  "calibration": 8363,
26
  "calibration_recomp_neg": 3011,
27
  "calibration_crop_resize_dev": 2972,
28
- "test": 10585
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  },
30
  "locked_internal_test": {
31
  "n": 10585,
@@ -90,7 +191,6 @@
90
  "procedural_graphic": 1.0,
91
  "document": 1.0,
92
  "gov_scientific_doc": 1.0,
93
- "receipt_invoice": 1.0,
94
  "print_publishing": 1.0,
95
  "stress_recompressed": 1.0,
96
  "foreign_ai": 1.0
@@ -146,12 +246,6 @@
146
  }
147
  }
148
  },
149
- "external_phone_thermal_receipts": {
150
- "evaluated": 60,
151
- "false_positives": 0,
152
- "fpr": 0.0,
153
- "specificity": 1.0
154
- },
155
  "stage2_version_accuracy": {
156
  "openai": 0.9559147685525349,
157
  "google": 0.9698492462311558,
 
1
  {
2
+ "claim": "abstaining 10-provider source-pipeline classification with version subfamily attribution and calibrated binary synthetic-image detection; not SynthID detection",
3
+ "schema": "multi-provider-source-v7",
4
+ "artifact_file": "multi-provider-source-v7.npz",
5
+ "artifact_sha256": "4faef51eea48f8194ee804fab1782c48d626384e115e2ef70884f8e8393d7eb1",
6
+ "artifact_size_mb": 55.53,
7
  "feature_dimension": 512,
8
+ "vit_output_dimension": 28,
9
+ "synthetic_fusion_dimension": 67,
10
+ "multimodal_provider_dimension": 82,
11
  "stacked_stage2_dimension": 666,
12
  "classes": [
13
  "openai",
 
29
  "calibration": 8363,
30
  "calibration_recomp_neg": 3011,
31
  "calibration_crop_resize_dev": 2972,
32
+ "test": 10585,
33
+ "multimodal_v7_train_views": 14428,
34
+ "multimodal_v7_cal_views": 6694,
35
+ "sealed_foreign_eval_views": 84
36
+ },
37
+ "open_benchmark_v2_578": {
38
+ "non_ai_total": 200,
39
+ "non_ai_fp": 0,
40
+ "non_ai_fpr": 0.0,
41
+ "slice_fpr_pct": {
42
+ "camera_photo": 0.0,
43
+ "ui_screenshot": 0.0,
44
+ "science_diagram": 0.0,
45
+ "scanned_document": 0.0
46
+ },
47
+ "native_ai_total": 125,
48
+ "native_ai_synthetic_recall": 0.992,
49
+ "native_ai_provider_attribution": 0.712,
50
+ "arena_ai_total": 253,
51
+ "arena_ai_synthetic_recall": 0.8695652173913043,
52
+ "arena_ai_provider_attribution": 0.1857707509881423,
53
+ "overall_ai_recall": 0.91005291005291,
54
+ "overall_precision": 1.0,
55
+ "median_cpu_ms": 328.9
56
+ },
57
+ "sealed_foreign_openworld_eval": {
58
+ "evaluated_views": 84,
59
+ "synthetic_recall": 0.6905,
60
+ "honest_unknown_abstention_rate": 0.9762
61
+ },
62
+ "locked_internal_test_e2e_rgb": {
63
+ "evaluated_parents": 4415,
64
+ "supported_ai_parents": 2074,
65
+ "real_non_ai_parents": 2341,
66
+ "native": {
67
+ "synthetic_recall_supported_ai": 0.9754098360655737,
68
+ "exact_provider_recall_supported_ai": 0.9281581485053038,
69
+ "real_synthetic_fp": 2,
70
+ "real_synthetic_fpr": 0.0008543357539513029,
71
+ "real_provider_fp": 1,
72
+ "real_provider_fpr": 0.00042716787697565144,
73
+ "roc_auc": 0.9994764413002544,
74
+ "pr_auc": 0.9994285151447234
75
+ },
76
+ "arena_transcoded": {
77
+ "synthetic_recall_supported_ai": 0.654291224686596,
78
+ "exact_provider_recall_supported_ai": 0.2540983606557377,
79
+ "real_synthetic_fp": 20,
80
+ "real_synthetic_fpr": 0.00854335753951303,
81
+ "real_provider_fp": 4,
82
+ "roc_auc": 0.9739757136319278,
83
+ "pr_auc": 0.9720579688268834
84
+ }
85
+ },
86
+ "external_blind_selective_v8_e2e_rgb": {
87
+ "evaluated_parents": 1512,
88
+ "synthetic_fp": 4,
89
+ "synthetic_fpr": 0.0026455026455026454,
90
+ "provider_fp": 0,
91
+ "provider_fpr": 0.0,
92
+ "by_domain": {
93
+ "diagram": {
94
+ "evaluated": 305,
95
+ "synthetic_fp": 0,
96
+ "synthetic_fpr": 0.0,
97
+ "provider_fp": 0
98
+ },
99
+ "document": {
100
+ "evaluated": 308,
101
+ "synthetic_fp": 0,
102
+ "synthetic_fpr": 0.0,
103
+ "provider_fp": 0
104
+ },
105
+ "game_art": {
106
+ "evaluated": 215,
107
+ "synthetic_fp": 4,
108
+ "synthetic_fpr": 0.018604651162790697,
109
+ "provider_fp": 0
110
+ },
111
+ "interface": {
112
+ "evaluated": 327,
113
+ "synthetic_fp": 0,
114
+ "synthetic_fpr": 0.0,
115
+ "provider_fp": 0
116
+ },
117
+ "photo": {
118
+ "evaluated": 25,
119
+ "synthetic_fp": 0,
120
+ "synthetic_fpr": 0.0,
121
+ "provider_fp": 0
122
+ },
123
+ "vector": {
124
+ "evaluated": 332,
125
+ "synthetic_fp": 0,
126
+ "synthetic_fpr": 0.0,
127
+ "provider_fp": 0
128
+ }
129
+ }
130
  },
131
  "locked_internal_test": {
132
  "n": 10585,
 
191
  "procedural_graphic": 1.0,
192
  "document": 1.0,
193
  "gov_scientific_doc": 1.0,
 
194
  "print_publishing": 1.0,
195
  "stress_recompressed": 1.0,
196
  "foreign_ai": 1.0
 
246
  }
247
  }
248
  },
 
 
 
 
 
 
249
  "stage2_version_accuracy": {
250
  "openai": 0.9559147685525349,
251
  "google": 0.9698492462311558,
multi-provider-source-v7.npz ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4faef51eea48f8194ee804fab1782c48d626384e115e2ef70884f8e8393d7eb1
3
+ size 58226172