SpatialEvidenceBench / code /build_subset_prompts.py
spatial-evidence-bench's picture
Upload folder using huggingface_hub
a863f79 verified
Raw History Blame Contribute Delete
1.47 kB
import argparse
import json
from collections import defaultdict
from pathlib import Path
FAMILIES = ("left_right", "above_below", "front_behind", "on_not_on")
def family_of(scene_id):
for family in FAMILIES:
if scene_id.startswith(family):
return family
raise ValueError(f"无法从 scene_id 推断族: {scene_id}")
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--prompts", required=True)
parser.add_argument("--out", required=True)
parser.add_argument("--per-family", type=int, default=120)
args = parser.parse_args()
by_family = defaultdict(dict)
with open(args.prompts, encoding="utf-8") as handle:
for line in handle:
row = json.loads(line)
by_family[family_of(row["scene_id"])].setdefault(row["scene_id"], []).append(row)
kept = []
for family in FAMILIES:
scene_ids = sorted(by_family[family])[-args.per_family:]
if len(scene_ids) < args.per_family:
raise RuntimeError(f"{family} 只有 {len(scene_ids)} 个场景,少于 {args.per_family}")
for scene_id in scene_ids:
kept.extend(by_family[family][scene_id])
with open(args.out, "w", encoding="utf-8") as handle:
for row in kept:
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
print(json.dumps({"prompts": len(kept), "scenes": len({r['scene_id'] for r in kept})}))
if __name__ == "__main__":
main()