Spaces:
Running
Dataset curation
This folder contains the scripts that produced the commercially-licensed training dataset for Stage 2 fine-tuning (DONE, 2026-05).
Stage 3A extends this folder with one new generation script per
approved open-source generator (initially AuraFlow, SDXL, and SD 3.5
Medium; PixArt-Ξ£ is deferred pending license/intended-use clarification).
The rest of the pipeline
(build_manifest.py, split.py, ../precompute_embeddings.py,
../train_head.py) is generator-agnostic and will be reused as-is β
the manifest format already supports multiple AI source labels.
See docs/plan.md Stage 3 for the full plan.
What we're building
A dataset of roughly 100k images total:
| Split | Source | Class | License |
|---|---|---|---|
| ~50k real | Open Images V7 (sampled) | authentic |
CC BY 2.0 |
| ~50k AI | Self-generated with Flux.1-schnell | ai_generated |
Apache 2.0 weights β outputs are unrestricted |
Stage 2 trains the CLIP classifier head on this 2-class data. The deepfake
and edited classes will be added later via separate scripts.
Workflow
fetch_open_images.pyβ downloads a stratified sample of Open Images intodata/raw/real/. Run once. Idempotent.generate_flux_synthetic.pyβ generates AI images with Flux.1-schnell intodata/raw/ai_generated/. Run on a rented cloud GPU (~$30 total at RunPod / Lambda Labs spot rates).generate_sdxl_synthetic.pyβ generates AI images with SDXL intodata/raw/ai_generated/sdxl/. Use--dry-runlocally before running on a GPU box.generate_sd35_synthetic.pyβ generates AI images with SD 3.5 Medium intodata/raw/ai_generated/sd35-medium/. This source is conditionally approved under the Stability AI Community License; reviewNOTICES.mdbefore running it.generate_auraflow_synthetic.pyβ generates AI images with AuraFlow v0.3 intodata/raw/ai_generated/auraflow-v0.3/. Use--dry-runlocally before running on a GPU box.Stage 3A generator scripts should reuse
generation_utils.pyfor prompt loading, deterministic seeds, stable output keys, file hashes, image dimensions, approved generator metadata, and manifest-row construction.build_manifest.pyβ producesdata/manifest.csvwith one row per image. Required columns arepath,class,source,license,license_url,sha256. Stage 3A adds optional generator metadata columns:generator,model_family,model_id,prompt,seed,width,height,generation_params_json. Missing optional values are written as empty strings, and approved AI-generator metadata is backfilled from knownsourcevalues when older fragments do not include the optional columns. You can pass fragments explicitly with--inputs, or point--input-diratdata/rawto discover all*_manifest.csvfragments recursively. This is the legal record that protects you when you commercialise and the source-of-truth for per-generator evaluation.split.pyβ produces train/val/test splits stratified by class. Stage 3A adds optional generator-aware splitting with--stratify-by class-generator, plus--holdout-generator <name>to write aheldout.csvevaluation split while excluding that generator from train/val/test.
After splitting, training itself lives outside this directory:
augment_images.pyβ creates deterministic Stage 3A robustness augmentations from any manifest or split CSV. It writes new JPEG images plus a manifest-compatible CSV withoriginal_path,augmentation,augmentation_seed, andaugmentation_params_json. Run it ontrain.csvfor augmented training rows, or onval.csv/test.csvinto separate manifests such astest_augmented.csvfor robustness evaluation while keeping the clean splits unchanged.../precompute_embeddings.pyβ encodes every image through frozen CLIP once and caches the 512-d feature vectors. Runs on CPU (1-4 hours on the dev laptop). One-shot per dataset version. By default it encodes cleantrain.csv,val.csv, andtest.csv. Stage 3A adds--train-augment-manifest train_augmented.csvto append augmented rows totrain.npz, and--extra-split test_augmented=test_augmented.csvfor explicit augmented robustness-eval embeddings.../train_head.pyβ trains the small classifier head on the cached features. Seconds per epoch on CPU; iterate hyperparameters freely. Stage 3A reports overall metrics, per-source/per-generator/per-family metrics when embedding metadata is available, and augmentation robustness metrics for explicitly encoded augmented eval splits. Use--report-outto save the JSON report.../evaluate_head.pyβ evaluates a candidate checkpoint, optionally against a Stage 2 baseline checkpoint, on any cached embedding split (test,heldout,test_augmented, etc.). It writes a reproducible JSON report with overall, per-generator, held-out-generator, uncertainty, and augmentation robustness metrics.run_stage3a_smoke.pyβ runs a tiny local fixture pipeline before expensive GPU work. It builds fixture images/manifests, splits with an SDXL holdout, creates train/test augmentations, writes deterministic mocked 512-d embeddings, trains a smoke head, and evaluates it against a constant baseline:python scripts/dataset/run_stage3a_smoke.py \ --work-dir /tmp/deepfakescanner-stage3a-smokeThis intentionally bypasses real CLIP precompute so the smoke test stays fast and offline; use
../precompute_embeddings.pyfor real dataset runs.../run_stage3a_pipeline.pyβ orchestrates the full Stage 3A sequence after the smoke test passes. It can plan the run, execute GPU generation, build the manifest, split, augment, precompute embeddings, train the candidate head, evaluate against the Stage 2 baseline, write a JSON ship/no-ship recommendation, and optionally upload an accepted checkpoint to the private HF Hub repo.python scripts/run_stage3a_pipeline.py --dry-run --stop-after evaluate python scripts/run_stage3a_pipeline.py --stop-after generate python scripts/run_stage3a_pipeline.py \ --skip-generation \ --baseline data/checkpoints/head_v1.ptPublishing is intentionally opt-in via
--publish-if-acceptedand requiresHF_TOKEN.
For a collaborator-facing GPU handoff, use
docs/stage3a-gpu-collaborator-guide.md.
Why each piece is licensed for commercial use
- Open Images V7 β Google's dataset, all images are CC BY 2.0 (commercial
use allowed with attribution). Attribution lives in
manifest.csv. - Flux.1-schnell β released by Black Forest Labs under Apache 2.0. Outputs
are not restricted; you own them. (Note:
flux.1-devis non-commercial β do NOT use it.) - Stage 3A approved additions β SDXL, SD 3.5 Medium, and AuraFlow were
reviewed on 2026-05-15. See
NOTICES.mdfor the exact license status and constraints before generating any images. - NOT used here: FaceForensics++, DFDC, Celeb-DF (research-only),
outputs from closed-API generators (Gemini, Midjourney, DALL-E, Grok,
Firefly β ToS restrictions or ambiguous terms),
flux.1-dev(non-commercial), and PixArt-Ξ£ until its model-card intended-use ambiguity is clarified. SeeNOTICES.mdfor the full list anddocs/decisions.md2026-05-14 and 2026-05-15 entries for the reasoning.
Running it
The scripts are designed to be run independently. See each script's docstring for prerequisites and command-line flags.