File size: 4,412 Bytes
a863f79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import hashlib
import json
import shutil
import subprocess
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
REL = ROOT / "release" / "data_v1"


def sha256(path):
    h = hashlib.sha256()
    with open(path, "rb") as fh:
        for chunk in iter(lambda: fh.read(1 << 20), b""):
            h.update(chunk)
    return h.hexdigest()


def main():
    if REL.exists():
        shutil.rmtree(REL)
    (REL / "metadata").mkdir(parents=True)
    (REL / "images").mkdir()
    (REL / "truth").mkdir()
    (REL / "prompts").mkdir()
    (REL / "specs").mkdir()
    (REL / "assets").mkdir()

    for name in ("truth_all.jsonl", "truth_dev.jsonl", "truth_test.jsonl"):
        shutil.copy(ROOT / "dataset" / name, REL / "truth" / name)
    shutil.copy(ROOT / "dataset" / "prompts_all.jsonl", REL / "prompts" / "prompts_all.jsonl")
    for name in ("scene_specs_dev.jsonl", "scene_specs_test.jsonl"):
        shutil.copy(ROOT / "dataset" / name, REL / "specs" / name)
    for name in ("asset_catalog.jsonl", "licenses.csv"):
        shutil.copy(ROOT / "assets" / name, REL / "assets" / name)
    for name in ("croissant.json", "dataset_card.md"):
        shutil.copy(ROOT / "release" / name, REL / "metadata" / name)
    (REL / "code").mkdir()
    for src in sorted((ROOT / "scripts").glob("*.py")):
        shutil.copy(src, REL / "code" / src.name)
    for src in sorted((ROOT / "analysis").glob("*.py")):
        shutil.copy(src, REL / "code" / src.name)
    shutil.copy(ROOT / "release" / "reproduce.sh", REL / "code" / "reproduce.sh")

    # 逐条件预测:只收最终三模型的合成域与自然域文件
    pred = REL / "predictions"
    pred.mkdir()
    models = ("qwen3vl", "qwen25vl", "deepseekvl2s")
    for model in models:
        src_dir = ROOT / "predictions" / f"synth_{model}"
        dst_dir = pred / f"synth_{model}"
        dst_dir.mkdir()
        for src in sorted(src_dir.glob("*.jsonl")):
            shutil.copy(src, dst_dir / src.name)
    nat_src = ROOT / "predictions" / "natural"
    nat_dst = pred / "natural"
    nat_dst.mkdir()
    for src in sorted(nat_src.glob("*.jsonl")):
        if any(model in src.name for model in models):
            shutil.copy(src, nat_dst / src.name)

    # 分析结果:论文里每个数字都能由这些 JSON 重算
    results = REL / "results"
    results.mkdir()
    for model in models:
        for name in (f"synth_{model}.json", f"matrix_{model}.json", f"boot_{model}.json"):
            shutil.copy(ROOT / "analysis" / name, results / name)
    for name in ("paired_effects.json",):
        shutil.copy(ROOT / "analysis" / name, results / name)
    for src in sorted((ROOT / "analysis").glob("natural_*.json")):
        shutil.copy(src, results / src.name)

    subprocess.run(["cp", "-al", str(ROOT / "dataset" / "render_all"), str(REL / "images" / "render_all")], check=True)

    mismatched = []
    frames = []
    with open(ROOT / "dataset" / "truth_all.jsonl") as fh:
        for line in fh:
            row = json.loads(line)
            frames.append(row["image"])
            if row.get("computed") != row.get("declared"):
                mismatched.append(row)
    with open(REL / "metadata" / "truth_mismatch.json", "w") as fh:
        json.dump({"n_mismatch": len(mismatched), "records": mismatched}, fh, indent=2, ensure_ascii=False)

    split = {"seed": 20261106, "n_scenes": 2400, "n_images": len(frames),
             "dev_prefix_limit": 150, "note": "scene index below 150 per family is dev"}
    with open(REL / "metadata" / "split_manifest.json", "w") as fh:
        json.dump(split, fh, indent=2)

    sums = []
    for path in sorted(REL.rglob("*")):
        if path.is_file() and path.name != "CHECKSUMS.sha256":
            sums.append(f"{sha256(path)}  {path.relative_to(REL)}")
    (REL / "metadata" / "CHECKSUMS.sha256").write_text("\n".join(sums) + "\n")
    print(json.dumps({"files": len(sums), "mismatch": len(mismatched)}))


def checksums_only():
    sums = []
    for path in sorted(REL.rglob("*")):
        if path.is_file() and path.name != "CHECKSUMS.sha256":
            sums.append(f"{sha256(path)}  {path.relative_to(REL)}")
    (REL / "metadata" / "CHECKSUMS.sha256").write_text("\n".join(sums) + "\n")
    print(json.dumps({"rehashed": len(sums)}))


if __name__ == "__main__":
    import sys

    if "--checksums-only" in sys.argv:
        checksums_only()
    else:
        main()