mirror of
https://github.com/wiltodelta/remove-ai-watermarks.git
synced 2026-12-05 19:53:26 +01:00
Fix the P0 findings of the 0.81.0 review across metadata, audio, video, text, visible marks, and scripts, with regression tests. When no metadata, visible mark, or caller names the model, remove only metadata and visible marks. Infer Google audio only from Google evidence or an explicit SynthID profile. Keep ordinary tags and chapters when stripping AI metadata from ffmpeg-handled containers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
139 lines
5.8 KiB
Python
139 lines
5.8 KiB
Python
"""Consolidate the hand-labeled contact-sheet rounds into ONE ground-truth file.
|
|
|
|
Ground truth is `uid -> the set of visible marks actually present`, hand-labeled
|
|
blind against contact sheets with a two-sided control in every round. Rounds so far:
|
|
|
|
2026-07-18 text-mark/pill round : 423 cells (doubao / jimeng / jimeng_pill arms)
|
|
2026-07-18 gemini round : 356 cells (gemini relaxation additions)
|
|
|
|
DATA SAFETY: treat the input dataset as sensitive. This script reads a gitignored
|
|
dataset and writes a gitignored ground-truth file. Neither the images nor this
|
|
output may be committed; only the harness is. See the repo CLAUDE.md.
|
|
|
|
The labels record what the labeler saw in the crop, one of:
|
|
doubao | jimeng | pill | sparkle | other_ai_label | none | uncertain
|
|
`other_ai_label` is a real visible AI label from a vendor we do NOT have a mark for
|
|
(千问 / 百度 / 星绘 / 抖音); it is NOT a positive for any registered mark, but it is
|
|
also not "clean" -- it is exactly what the relaxed jimeng detector confuses.
|
|
`uncertain` rows are EXCLUDED from scoring rather than coerced, so a labeler's
|
|
honest doubt never becomes a fabricated data point.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import csv
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
|
|
# Schema 2 records provenance and vetoed_marks from the production context.
|
|
GROUNDTRUTH_SCHEMA = 2
|
|
SEEN_TO_MARK = {
|
|
"doubao": "doubao",
|
|
"jimeng": "jimeng",
|
|
"pill": "jimeng_pill",
|
|
"sparkle": "gemini",
|
|
}
|
|
# Which marks a crop centered on `key` lets the labeler rule on (same corner = visible
|
|
# in the same crop). Doubao and Jimeng share the bottom-right corner.
|
|
_ADJUDICATES = {
|
|
"doubao": ("doubao", "jimeng"),
|
|
"jimeng": ("doubao", "jimeng"),
|
|
"jimeng_pill": ("jimeng_pill",),
|
|
"gemini": ("gemini",),
|
|
"samsung": ("samsung",),
|
|
}
|
|
|
|
ROUNDS = [
|
|
("textmark", "labels.csv", "manifest.csv"),
|
|
("gemini", "gemini_labels.csv", "gemini_manifest.csv"),
|
|
]
|
|
_HELP_DESCRIPTION = "Consolidate hand-labeled contact-sheet rounds into one ground-truth file."
|
|
|
|
|
|
def metadata_context(path: str) -> dict[str, list[str]]:
|
|
"""The provenance and vetoes LOCAL METADATA confirms -- ``api._visible_context``.
|
|
|
|
Must come from the file's own metadata, never from the labels: deriving it from
|
|
the ground truth would hand the detector the answer it is being scored on (a
|
|
relaxation only fires when provenance names the vendor, so label-derived
|
|
provenance makes every arm look near-perfect).
|
|
"""
|
|
from remove_ai_watermarks import api
|
|
|
|
# _visible_context reads every failure as "no provenance"; refuse a missing file here.
|
|
if not Path(path).is_file():
|
|
raise FileNotFoundError(path)
|
|
provenance, vetoed = api._visible_context(Path(path))
|
|
return {"provenance": sorted(provenance), "vetoed_marks": sorted(vetoed)}
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description=_HELP_DESCRIPTION)
|
|
parser.add_argument(
|
|
"root",
|
|
type=Path,
|
|
nargs="?",
|
|
default=Path(".local-eval/textmark-relaxation"),
|
|
help="Directory containing the blinded labeling rounds",
|
|
)
|
|
root = parser.parse_args().root
|
|
out = root / "groundtruth.jsonl"
|
|
rows: dict[str, dict] = {}
|
|
stats: dict[str, int] = {}
|
|
for round_name, labels_file, manifest_file in ROUNDS:
|
|
with (root / labels_file).open() as fh:
|
|
labels = {int(r["idx"]): r["seen"] for r in csv.DictReader(fh)}
|
|
with (root / manifest_file).open() as fh:
|
|
manifest_rows = list(csv.DictReader(fh))
|
|
for m in manifest_rows:
|
|
seen = labels.get(int(m["idx"]))
|
|
if seen is None:
|
|
continue
|
|
stats[seen] = stats.get(seen, 0) + 1
|
|
if seen == "uncertain":
|
|
continue # excluded by design -- never coerce a doubt into a label
|
|
rec = rows.setdefault(
|
|
m["uid"],
|
|
{"uid": m["uid"], "path": m["path"], "present": [], "seen": [], "rounds": [], "adjudicated": []},
|
|
)
|
|
# ADJUDICATION SCOPE -- load-bearing. A crop centered on one mark only lets
|
|
# the labeler rule on marks visible IN THAT CROP. A pill crop (top-left)
|
|
# says nothing about a bottom-right wordmark, so scoring jimeng against a
|
|
# pill-round image would book real detections as false fires (~61% of pills
|
|
# carry a wordmark). Bottom-right marks co-adjudicate each other: one crop
|
|
# of that corner shows whichever of Doubao/Jimeng is there.
|
|
for k in _ADJUDICATES.get(m["key"], (m["key"],)):
|
|
if k not in rec["adjudicated"]:
|
|
rec["adjudicated"].append(k)
|
|
mark = SEEN_TO_MARK.get(seen)
|
|
if mark and mark not in rec["present"]:
|
|
rec["present"].append(mark)
|
|
if seen not in rec["seen"]:
|
|
rec["seen"].append(seen)
|
|
if round_name not in rec["rounds"]:
|
|
rec["rounds"].append(round_name)
|
|
|
|
for r in rows.values():
|
|
r["schema"] = GROUNDTRUTH_SCHEMA
|
|
r.update(metadata_context(r["path"]))
|
|
with out.open("w") as fh:
|
|
for r in rows.values():
|
|
fh.write(json.dumps(r) + "\n")
|
|
print(f"wrote {out} images={len(rows)}")
|
|
print("label distribution across all rounds:", dict(sorted(stats.items(), key=lambda kv: -kv[1])))
|
|
n_pos = sum(1 for r in rows.values() if r["present"])
|
|
print(f"images with at least one registered mark: {n_pos}; clean-of-registered-marks: {len(rows) - n_pos}")
|
|
adj: dict[str, int] = {}
|
|
for r in rows.values():
|
|
for k in r["adjudicated"]:
|
|
adj[k] = adj.get(k, 0) + 1
|
|
print("images each mark can be SCORED on (adjudication scope):", dict(sorted(adj.items())))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|