Adam-Weisman's picture
Every verdict of the Vereye benchmark on the SynthID-Image protocol (no images, no code)
5ab6d2e verified
Raw History Blame Contribute Delete
21.1 kB
#!/usr/bin/env python3
"""score.py - recomputes EVERY number of this benchmark from the folder's tables (Python 3, standard library only), prints them
(results/summary.txt is this printout) and writes results/summary.json; check.py compares both with the published copies.
Inputs, per set (sets/<set>/):
results/cells.csv one row per attacked copy verified by Vereye's verify code: set, photo, transformation, mode, group, marked (1 = a
copy of the SEALED photo, 0 = its identically attacked UNMARKED twin), label, params, pixel_sha256, file_sha256,
verdict, identified (1 = the exact key registered for this photo was read), owners_named (registered keys read),
other_owners (registered keys of OTHER photos read), crc_keys (keys read that pass the check, registered or not), ms
results/rivals.csv the same photos and seeds for WAM and TrustMark (when run): method, ..., marked, bitacc, rawacc, mask, present, ident
Numbers:
* owner identified per mode over the SynthID-Image paper's 29 transformations (group 'extra' - our own jpeg row - is reported apart),
with the pre-registered conservative bounds (PREREGISTRATION.md section 5): the wider of a photo-resampled 95 % interval and an
exact Clopper-Pearson interval on the effective sample size n / deff (Kish's design effect of the photo clusters);
* unmarked twins: owners named, and twins on which ANY check-valid key was read; the design bound of the decoder's check;
* the rivals at the SynthID-Image paper's calibration (a threshold at 0.1 % false positives on the WORST-mode unmarked twins, each twin
decoded against its own photo's message), strict and counting ties, next to the values the paper reports for them;
* the pre-registered comparison with SynthID-O on the 512 px held-out set; every place Vereye is lower; a per-transformation table.
python3 scripts/score.py [--json results/summary.json]"""
import collections, csv, glob, json, math, os, random, sys
KIT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SYNTHID = {'table1_detection': {'random': 99.98, 'worst': 99.72}, 'table2_payload': {'random': (99.96, 99.97), 'worst': (98.84, 98.90)},
'source': 'Gowal et al., "SynthID-Image: Image watermarking at internet scale", arXiv:2510.09263 (2025), Tables 1 and 2: '
'10,000 ImageNet validation images at 512 x 512, TPR at 0.1 % FPR; not run here (SynthID is not public)'}
# what the paper reports for the rivals we re-ran (aggregate random / worst; the lower end of an interval): the calibration check
PAPER_RIVALS = {('wam', 'mask'): ((90.62, 83.37), 'Table 1'), ('wam', 'bitacc'): ((81.26, 69.11), 'Table 2'), ('trustmark', 'rawacc'): ((78.61, 68.73), 'Table 1'),
('trustmark', 'bitacc'): ((78.61, 68.73), 'Table 1')}
# the paper's per-group values (Table 1: detection; Table 2: payload; the lower end of an interval), group -> (random, worst)
GROUPS_REPORTED = {
'SynthID-O, Table 1': {'color': (100.00, 100.00), 'combination': (99.96, 98.06), 'noise': (99.98, 99.96), 'overlay': (100.00, 100.00), 'quality': (99.99, 99.99), 'spatial': (99.98, 99.97)},
'SynthID-O, Table 2': {'color': (99.99, 99.99), 'combination': (99.92, 91.96), 'noise': (99.89, 99.74), 'overlay': (100.00, 100.00), 'quality': (99.96, 99.97), 'spatial': (99.98, 99.97)},
'WAM, Table 1': {'color': (81.29, 84.00), 'combination': (96.08, 55.96), 'noise': (100.00, 100.00), 'overlay': (100.00, 100.00), 'quality': (99.97, 99.38), 'spatial': (84.34, 76.04)},
'TrustMark-Q, Table 1': {'color': (99.65, 98.93), 'combination': (64.00, 21.22), 'noise': (100.00, 99.99), 'overlay': (99.99, 99.87), 'quality': (100.00, 99.99), 'spatial': (40.75, 25.76)}}
SYNTHID['groups_reported'] = GROUPS_REPORTED
# the decoder's check (Vereye's code constants): a 24-bit CRC; at most 512 check attempts in a first read, 1,771 in all
CRC_BITS, CHECKS_FIRST, CHECKS_MAX = 24, 512, 1771
# the calibration gate's rivals and their Table 1 scores, and the photos the pre-registration (version b, section 2) declares for them
GATE_SCORES, GATE_PHOTOS = (('wam', 'mask'), ('trustmark', 'rawacc')), 50
MODES = ('random', 'worst')
# ---- exact intervals, standard library only
def betacf(a, b, x):
"""the continued fraction of the regularized incomplete beta function (Numerical Recipes 6.4, Lentz)"""
qab, qap, qam = a + b, a + 1, a - 1; c = 1.0; d = 1 - qab * x / qap; d = 1 / (d if abs(d) > 1e-300 else 1e-300); h = d
for m in range(1, 400):
m2 = 2 * m; aa = m * (b - m) * x / ((qam + m2) * (a + m2)); d = 1 + aa * d; d = 1 / (d if abs(d) > 1e-300 else 1e-300); c = 1 + aa / c; c = c if abs(c) > 1e-300 else 1e-300; h *= d * c
aa = -(a + m) * (qab + m) * x / ((a + m2) * (qap + m2)); d = 1 + aa * d; d = 1 / (d if abs(d) > 1e-300 else 1e-300); c = 1 + aa / c; c = c if abs(c) > 1e-300 else 1e-300; de = d * c; h *= de
if abs(de - 1) < 3e-14: break
return h
def ibeta(a, b, x):
if x <= 0: return 0.0
if x >= 1: return 1.0
lb = math.lgamma(a + b) - math.lgamma(a) - math.lgamma(b) + a * math.log(x) + b * math.log(1 - x)
return math.exp(lb) * betacf(a, b, x) / a if x < (a + 1) / (a + b + 2) else 1 - math.exp(lb) * betacf(b, a, 1 - x) / b
def beta_q(q, a, b):
lo, hi = 0.0, 1.0
for _ in range(200):
mid = (lo + hi) / 2
if ibeta(a, b, mid) < q: lo = mid
else: hi = mid
return (lo + hi) / 2
def clopper_pearson(x, n):
"""95 % two-sided exact interval for x successes in n trials (x, n may be non-integer: an effective sample size)"""
lo = (0.025) ** (1 / n) if x >= n else 0.0 if x <= 0 else beta_q(0.025, x, n - x + 1)
hi = 1.0 if x >= n else 1 - (0.025) ** (1 / n) if x <= 0 else beta_q(0.975, x + 1, n - x)
return lo, hi
def deff_of(rows):
"""Kish's design effect 1 + (m - 1) ICC of the misses clustered by photo (ANOVA ICC, at least 0)"""
by = collections.defaultdict(list)
for r in rows: by[r['photo']].append(0 if r['identified'] == '1' else 1)
P = len(by); m = sum(len(v) for v in by.values()) / P; ps = [sum(v) / len(v) for v in by.values()]; pb = sum(ps) / P
if P < 2 or m < 2 or pb in (0, 1): return 1.0
msb = m * sum((p - pb) ** 2 for p in ps) / (P - 1); msw = sum(m * p * (1 - p) for p in ps) / (P * (m - 1))
icc = max(0.0, (msb - msw) / (msb + (m - 1) * msw)) if msb + (m - 1) * msw > 0 else 0.0
return max(1.0, 1 + (m - 1) * icc)
def photo_bootstrap(rows, B=4000, seed=20261028):
"""95 % interval of the identified rate when the PHOTOS are resampled with replacement (copies of one photo are not independent)"""
by = collections.defaultdict(lambda: [0, 0])
for r in rows: by[r['photo']][0] += r['identified'] == '1'; by[r['photo']][1] += 1
P = sorted(by); rng = random.Random(seed); v = []
for _ in range(B):
s = [by[rng.choice(P)] for _ in P]; v.append(100 * sum(a for a, _ in s) / sum(b for _, b in s))
v.sort(); return (round(v[int(0.025 * B)], 2), round(v[int(0.975 * B) - 1], 2))
def vereye(rows):
out = {}
m29 = [r for r in rows if r['marked'] == '1' and r['group'] != 'extra']
for md in MODES:
m = [r for r in m29 if r['mode'] == md]; ok = sum(r['identified'] == '1' for r in m)
g = collections.defaultdict(lambda: [0, 0]); t = collections.defaultdict(lambda: [0, 0])
for r in m: g[r['group']][0] += r['identified'] == '1'; g[r['group']][1] += 1; t[r['transformation']][0] += r['identified'] == '1'; t[r['transformation']][1] += 1
u = [r for r in rows if r['marked'] == '0' and r['mode'] == md]
ex = [r for r in rows if r['marked'] == '1' and r['group'] == 'extra' and r['mode'] == md]
bs = photo_bootstrap(m) if m else (None, None); de = deff_of(m) if m else 1.0; ne = len(m) / de; cp = clopper_pearson(ok / de, ne) if m else (0, 0)
out[md] = {'identified': ok, 'copies': len(m), 'pct': round(100 * ok / len(m), 2) if m else None, 'photo_bootstrap95': bs,
'deff': round(de, 3), 'clopper_pearson95_eff': (round(100 * cp[0], 2), round(100 * cp[1], 2)),
'bounds95': (round(min(bs[0], 100 * cp[0]), 2), round(max(bs[1], 100 * cp[1]), 2)) if m else None,
'misses_on_photos': len({r['photo'] for r in m if r['identified'] != '1'}),
'groups': {k: [a, b] for k, (a, b) in sorted(g.items())}, 'transformations': {k: [a, b] for k, (a, b) in sorted(t.items())},
'unmarked_twins': len(u), 'unmarked_owner_named': sum(int(r['owners_named'] or 0) > 0 for r in u),
'unmarked_any_key': sum(int(r['crc_keys'] or 0) > 0 for r in u),
'marked_other_owner': sum(int(r['other_owners'] or 0) > 0 for r in m),
'extra_jpeg': [sum(r['identified'] == '1' for r in ex), len(ex)]}
return out
def fnum(x):
try: return float(x)
except (TypeError, ValueError): return None
def rivals(rows):
"""per method and score: the 0.1 %-FPR threshold on worst-mode twins and the paper's TPR (mean over the 29 transformations), strict
(a score above the threshold) and counting ties at the threshold, next to what the SynthID-Image paper reports for the method"""
out = {}
for meth in sorted({r['method'] for r in rows}):
R = [r for r in rows if r['method'] == meth and r['group'] != 'extra']; scores = ('bitacc', 'rawacc') if meth == 'trustmark' else ('bitacc', 'mask')
out[meth] = {'photos': len({r['photo'] for r in R})}
for sc in scores:
un = sorted((fnum(r[sc]) if fnum(r[sc]) is not None else 0.0) for r in R if r['marked'] == '0' and r['mode'] == 'worst')
if not un or all(fnum(r[sc]) is None for r in R if r['marked'] == '1'): continue
thr = un[min(len(un) - 1, math.ceil(0.999 * len(un)) - 1)]
res = {'threshold': thr, 'worst_twins': len(un), 'photos': out[meth]['photos'], 'fpr_worst_pct': round(100 * sum(x > thr for x in un) / len(un), 3),
'fpr_worst_with_ties_pct': round(100 * sum(x >= thr for x in un) / len(un), 3)}
if (meth, sc) in PAPER_RIVALS: res['paper_reported'], res['paper_table'] = PAPER_RIVALS[(meth, sc)]
for md in MODES:
t = collections.defaultdict(list); te = collections.defaultdict(list)
for r in R:
if r['marked'] == '1' and r['mode'] == md: x = fnum(r[sc]) or 0.0; t[r['transformation']].append(x > thr); te[r['transformation']].append(x >= thr)
res[md] = round(100 * sum(sum(v) / len(v) for v in t.values()) / len(t), 2) if t else None
res[md + '_with_ties'] = round(100 * sum(sum(v) / len(v) for v in te.values()) / len(te), 2) if te else None
res[md + '_by_transformation'] = {k: round(100 * sum(v) / len(v), 1) for k, v in sorted(t.items())}
res[md + '_marked_copies'] = sum(len(v) for v in t.values())
out[meth][sc] = res
ex = collections.defaultdict(list)
for r in R:
if r['marked'] == '1': ex[(r['mode'], r['transformation'])].append(r['ident'] in ('1', 'True', 'true'))
out[meth]['exact_message'] = {md: round(100 * sum(sum(v) / len(v) for (m, _), v in ex.items() if m == md) / max(1, len({k for k in ex if k[0] == md})), 2) for md in MODES}
if meth == 'trustmark':
tw = [r for r in R if r['marked'] == '0']; mk = [r for r in R if r['marked'] == '1']
out[meth]['present_flag'] = {'twins_pct': round(100 * sum(r['present'] in ('1', 'True', 'true') for r in tw) / max(1, len(tw)), 2),
'marked_pct': round(100 * sum(r['present'] in ('1', 'True', 'true') for r in mk) / max(1, len(mk)), 2)}
ps = [fnum(r['psnr']) for r in R if r['marked'] == '1' and fnum(r.get('psnr'))]
out[meth]['psnr_db'] = round(sum(ps) / len(ps), 2) if ps else None
return out
def rival_bounds95(rows, meth, sc, thr, md):
"""a rival's 95 % interval EXACTLY like Vereye's (the wider of the photo bootstrap and Clopper-Pearson on the effective sample size),
of its rate counting ties at the threshold as detected (the higher rate: the stricter gate for Vereye). Addendum 2026-10-28 (critic
round 3, F1): the margin it replaces (a Wald interval times a typed-in sqrt(29)) could not trip on the real rival rows."""
R = [{'photo': r['photo'], 'identified': '1' if (fnum(r[sc]) or 0.0) >= thr else '0'} for r in rows
if r['method'] == meth and r['group'] != 'extra' and r['marked'] == '1' and r['mode'] == md]
if not R: return None
ok = sum(r['identified'] == '1' for r in R); bs = photo_bootstrap(R); de = deff_of(R); cp = clopper_pearson(ok / de, len(R) / de)
return (round(min(bs[0], 100 * cp[0]), 2), round(max(bs[1], 100 * cp[1]), 2))
def rivals_ok(riv, rows=None):
"""the pre-registered calibration gate: no rival scores higher here than the paper reports for it by more than its own 95 % interval
(its lower bound above the reported value); FAILS CLOSED: without rival rows "ahead" cannot be declared (critic round 3, M2)"""
bad = []
if not riv or not rows: return ['no rival rows: the calibration gate cannot run, so "ahead" cannot be declared']
# BOTH rivals, each scored by its Table 1 score, on at least the photos the pre-registration declares (critic round 4, M2: with one
# rival, a subset of photos or an empty score column the gate passed by default)
for meth, k in GATE_SCORES:
x = (riv.get(meth) or {}).get(k)
if not (isinstance(x, dict) and 'threshold' in x): bad.append(f'{meth} {k}: missing, so "ahead" cannot be declared'); continue
if x.get('photos', 0) < GATE_PHOTOS: bad.append(f'{meth} {k}: {x.get("photos", 0)} photos, fewer than the {GATE_PHOTOS} declared')
for meth, sc in riv.items():
for k, x in sc.items():
if not (isinstance(x, dict) and 'paper_reported' in x) or x['paper_table'] != 'Table 1': continue
for i, md in enumerate(MODES):
b = rival_bounds95(rows, meth, k, x['threshold'], md); x[md + '_bounds95_with_ties'] = b
if b is None: bad.append(f'{meth} {k} {md}: no marked rows'); continue
if b[0] > x['paper_reported'][i]: bad.append(f'{meth} {k} {md}: {x[md + "_with_ties"]:.2f} % here (95 % {b[0]:.2f}-{b[1]:.2f}) vs {x["paper_reported"][i]:.2f} % reported')
return bad
def prereg(v, riv, rows=None):
"""PREREGISTRATION.md section 5 (version b), its own words for the three statements (critic round 3, M5)"""
s, why = {}, rivals_ok(riv, rows)
for md in MODES:
lo, hi = v[md]['bounds95']; t1 = SYNTHID['table1_detection'][md]; t2lo, t2hi = SYNTHID['table2_payload'][md]
if lo > t1 and lo > t2hi and not why: s[md] = 'ahead of SynthID-O'
elif lo > t1 and lo > t2hi: s[md] = 'ahead by the bounds, NOT declared: the rival calibration gate failed' # critic round 4 (minor)
elif hi < min(t1, t2lo): s[md] = 'behind SynthID-O'
else: s[md] = 'not distinguishable from SynthID-O at this sample size'
s[md + '_bounds95'] = [lo, hi]
s[md + '_miss_ratio'] = round((100 - v[md]['pct']) / (100 - t1), 2) if t1 < 100 else None
s['rival_calibration_flags'] = why
return s
def weaker(v, riv, vsub):
"""every group where a value REPORTED in the SynthID-Image paper is above Vereye's, and every transformation where a rival measured
here is (on exactly the rivals' photos)"""
out = {'groups': [], 'transformations': []}
for md_i, md in enumerate(MODES):
for g, (a, b) in v[md]['groups'].items():
for who, G in GROUPS_REPORTED.items():
if g in G and G[g][md_i] > 100 * a / b: out['groups'].append(f'{md} {g}: Vereye {100 * a / b:.2f} % < {who} {G[g][md_i]:.2f} %')
for meth, sc in (riv or {}).items():
key = 'mask' if meth == 'wam' else 'rawacc'
if key not in sc: continue
for t, x in sc[key][md + '_by_transformation'].items():
a, b = (vsub or v)[md]['transformations'].get(t, (None, None))
if a is not None and x > 100 * a / b: out['transformations'].append(f'{md} {t}: Vereye {100 * a / b:.1f} % < {meth} {x:.1f} % (same photos)')
return out
if __name__ == '__main__':
J = {'synthid_reported': SYNTHID, 'sets': {}}
for d in sorted(glob.glob(os.path.join(KIT, 'sets', '*'))):
S = os.path.basename(d); meta = json.load(open(os.path.join(d, 'set.json'))); cells = list(csv.DictReader(open(os.path.join(d, 'results', 'cells.csv'), newline='')))
e = {'role': meta['role'], 'size': meta['size'], 'photos': len({r['photo'] for r in cells}), 'copies': len(cells), 'vereye': vereye(cells)}
ps = [json.load(open(f))['sealed']['psnr_db_vs_original'] for f in sorted(glob.glob(os.path.join(d, 'photos', '*', 'info.json')))]
e['vereye']['psnr_db'] = round(sum(ps) / len(ps), 2) if ps else None
rf = os.path.join(d, 'results', 'rivals.csv'); vsub = None; rr = None
if os.path.exists(rf):
rr = list(csv.DictReader(open(rf, newline=''))); e['rivals'] = rivals(rr); ph = {r['photo'] for r in rr}
if ph and len(ph) < e['photos']: # the rivals ran on part of the set: Vereye on exactly those photos too (like for like)
vsub = vereye([r for r in cells if r['photo'] in ph])
e['vereye_on_rival_photos'] = {'photos': len(ph), **{md: {'pct': vsub[md]['pct'], 'identified': vsub[md]['identified'], 'copies': vsub[md]['copies']} for md in MODES}}
if meta.get('synthid_comparison'): e['preregistered_statement'] = prereg(e['vereye'], e.get('rivals'), rr)
e['where_vereye_is_lower'] = weaker(e['vereye'], e.get('rivals'), vsub)
J['sets'][S] = e
tw = sum(e['vereye'][m]['unmarked_twins'] for e in J['sets'].values() for m in MODES)
J['design_bound'] = {'crc_bits': CRC_BITS, 'checks_first_read': CHECKS_FIRST, 'checks_max': CHECKS_MAX, 'twins': tw,
'per_image_low_pct': 100 * CHECKS_FIRST / 2 ** CRC_BITS, 'per_image_high_pct': 100 * CHECKS_MAX / 2 ** CRC_BITS,
'expected_low': tw * CHECKS_FIRST / 2 ** CRC_BITS, 'expected_high': tw * CHECKS_MAX / 2 ** CRC_BITS}
out = sys.argv[sys.argv.index('--json') + 1] if '--json' in sys.argv else None
if out: json.dump(J, open(out, 'w'), indent=1, sort_keys=True)
for S, e in J['sets'].items():
print(f'\n== {S} ({e["role"]}, {e["size"]} px): {e["photos"]} photos, {e["copies"]} copies, Vereye PSNR {e["vereye"]["psnr_db"]} dB')
for md in MODES:
v = e['vereye'][md]
print(f' Vereye {md}: owner identified {v["identified"]} / {v["copies"]} = {v["pct"]} % bounds {v["bounds95"]} (photo bootstrap {v["photo_bootstrap95"]}, '
f'exact on n/deff {v["clopper_pearson95_eff"]}, deff {v["deff"]}; misses on {v["misses_on_photos"]} photos) | twins: owner named {v["unmarked_owner_named"]} / '
f'{v["unmarked_twins"]}, any key {v["unmarked_any_key"]} | marked copies with another owner named {v["marked_other_owner"]} | extra jpeg {v["extra_jpeg"][0]}/{v["extra_jpeg"][1]}')
print(' groups: ' + ' '.join(f'{g} {a}/{b}' for g, (a, b) in v['groups'].items()))
if 'vereye_on_rival_photos' in e:
x = e['vereye_on_rival_photos']; print(f' Vereye on the {x["photos"]} photos the rivals ran on: random {x["random"]["pct"]} %, worst {x["worst"]["pct"]} %')
for meth, sc in e.get('rivals', {}).items():
print(f' {meth} ({sc["photos"]} photos): ' + ' | '.join(f'{k} thr {x["threshold"]:.4g} (fpr {x["fpr_worst_pct"]} %, with ties {x["fpr_worst_with_ties_pct"]} %) random {x["random"]} ({x["random_with_ties"]}) '
f'worst {x["worst"]} ({x["worst_with_ties"]})' + (f' [paper {x["paper_reported"][0]} / {x["paper_reported"][1]}, {x["paper_table"]}]' if 'paper_reported' in x else '')
for k, x in sc.items() if isinstance(x, dict) and 'threshold' in x) + f' | exact message {sc["exact_message"]} | psnr {sc["psnr_db"]} dB'
+ (f' | presence flag on twins {sc["present_flag"]["twins_pct"]} %' if 'present_flag' in sc else ''))
if 'preregistered_statement' in e: print(f' PRE-REGISTERED STATEMENT vs SynthID-O: {e["preregistered_statement"]}')
wl = e['where_vereye_is_lower']
print(f' WHERE VEREYE IS LOWER ({len(wl["groups"])} group values reported in the SynthID-Image paper, {len(wl["transformations"])} transformations measured here):')
for x in wl['groups'] + wl['transformations']: print(' ' + x)
print(' PER TRANSFORMATION (identified / detected %, random | worst):')
R = e.get('rivals', {})
for t in sorted(e['vereye']['random']['transformations']):
cells_ = []
for md in MODES:
a, b = e['vereye'][md]['transformations'][t]; c = [f'Vereye {100 * a / b:.1f}']
for meth, key in (('wam', 'mask'), ('trustmark', 'rawacc')):
if key in R.get(meth, {}): c.append(f'{meth} {R[meth][key][md + "_by_transformation"].get(t, float("nan")):.1f}')
cells_.append(' '.join(c))
print(f' {t:26s} ' + ' | '.join(cells_))
DB = J['design_bound']
print(f'\nDesign bound of the check: at most {CHECKS_FIRST}-{CHECKS_MAX} attempts per image at 2^-{CRC_BITS} each = {DB["per_image_low_pct"]:.4f}-{DB["per_image_high_pct"]:.4f} % '
f'per image; {DB["expected_low"]:.2f}-{DB["expected_high"]:.2f} wrong keys expected over the {tw:,} unmarked twins (a wrong key must also be registered to name anyone)')
print(f'SynthID-O (reported, not run): Table 1 {SYNTHID["table1_detection"]} Table 2 {SYNTHID["table2_payload"]}')