File size: 2,548 Bytes
f9ed2b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'Plan or execute zero-shot, joint-adaptation and retained-source evaluations.'
import argparse
import json
from pathlib import Path
import subprocess
import sys

ROOT = Path(__file__).resolve().parents[2]
def build_jobs(manifest_dir, training_root, wildgen_split, output):
    jobs = []
    for target in ["genimage", "forensynths"]:
        for model in ["univfd", "cnndetect"]:
            filename = "fc_weights_final.pth" if model == "univfd" else "model_final.pth"
            base = training_root / "runs" / f"binary_{model}" / "n900" / "exp_900" / filename
            for k in [0, 18, 90, 900]:
                name = f"{target}_k0_realratio_0p1_seed42.json" if k == 0 else f"{target}_joint_tr1p0_k{k}_realratio_0p1_seed42.json"
                run = output / target / model / f"k{k}"
                cmd = [sys.executable, str(ROOT / "scripts/launch/train_joint_adaptation.py"),
                    "--model-type", model, "--manifest", str(manifest_dir / name), "--output-dir", str(run),
                    "--strategy", "zero_shot" if k == 0 else "warm_start", "--checkpoint", str(base),
                    "--batch-size", "64", "--lr", "0.0001", "--seed", "42", "--total-samples-per-source", "9000"]
                if k == 0: cmd += ["--epochs", "0"]
                jobs.append(cmd)
                if k == 900:
                    jobs.append([sys.executable, str(ROOT / "scripts/eval/evaluate_binary_checkpoints.py"),
                        "--model-type", model, "--checkpoint", str(run / filename),
                        "--split-file", str(wildgen_split), "--output", str(run / "wildgen_retention.json")])
    return jobs

def main():
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument("--manifest-dir", type=Path, required=True)
    p.add_argument("--training-root", type=Path, required=True)
    p.add_argument("--wildgen-split", type=Path, required=True)
    p.add_argument("--output-dir", type=Path, required=True)
    p.add_argument("--execute", action="store_true")
    a = p.parse_args()
    jobs = build_jobs(a.manifest_dir.resolve(), a.training_root.resolve(), a.wildgen_split.resolve(), a.output_dir.resolve())
    a.output_dir.mkdir(parents=True, exist_ok=True)
    (a.output_dir / "jobs.json").write_text(json.dumps(jobs, indent=2), encoding="utf-8")
    if a.execute:
        for cmd in jobs: subprocess.run(cmd, cwd=ROOT, check=True)
    print(f"{len(jobs)} commands {'executed' if a.execute else 'planned'}")

if __name__ == "__main__": main()