Datasets:
Download make_judge_evaluation.py from iisys-hof/situate-diffuse: direct link, hf CLI and curl.
- Browser
- Download file 2.77 kB
-
https://huggingface.co/datasets/iisys-hof/situate-diffuse/resolve/main/make_judge_evaluation.py
- Command line
-
hf download hf://datasets/iisys-hof/situate-diffuse/make_judge_evaluation.py
-
curl -L -o make_judge_evaluation.py https://huggingface.co/datasets/iisys-hof/situate-diffuse/resolve/main/make_judge_evaluation.py
2.77 kB
| """Writes the judge_evaluation subset: one row per SITUATE+ test question (720), the picture and every judge's answer next to it. | |
| python make_judge_evaluation.py ../SITUATE-DIFFUSER26 | |
| """ | |
| import json | |
| import sys | |
| from pathlib import Path | |
| from datasets import Dataset, Features, Image, Value | |
| HERE = Path(__file__).resolve().parent | |
| PROJECT = Path(sys.argv[1]) | |
| SITUATE_PLUS = PROJECT / "data/situate_plus" | |
| RESULTS = PROJECT / "2_judge_evaluation/results" | |
| OUT = HERE / "judge_evaluation" | |
| SHARDS = 2 # parquet files of about 200 MB | |
| JUDGES = {"lisa_pro": "lisa-pro", # column name -> results folder | |
| "qwen3_vl_8b": "qwen3-vl-8b", | |
| "qwen3_8_27b": "qwen3.8-27b", | |
| "groundingpi_prompt": "groundingpi-prompt", | |
| "groundingpi_calc": "groundingpi-calc", | |
| "locateanything_prompt": "locateanything-prompt", | |
| "locateanything_calc": "locateanything-calc", | |
| "sam3_1": "sam3.1"} | |
| QUESTION = ["category", "subtask", "question", "adversarial", "groundtruth_number"] | |
| def key(item): # a question is its picture plus its text | |
| return item["image-filename"], item["question"] | |
| def features(): | |
| fields = {"image": Image(), | |
| "file_name": Value("string"), | |
| "category": Value("string"), | |
| "subtask": Value("string"), | |
| "question": Value("string"), | |
| "adversarial": Value("bool"), | |
| "groundtruth_number": Value("int32")} | |
| for name in JUDGES: | |
| fields[f"{name}_predicted"] = Value("int32") | |
| fields[f"{name}_correct"] = Value("bool") | |
| return Features(fields) | |
| def rows(): | |
| test = [json.loads(line) for line in (SITUATE_PLUS / "test.jsonl").read_text().splitlines()] | |
| answers = {} | |
| for name, folder in JUDGES.items(): | |
| answers[name] = {} | |
| for line in (RESULTS / folder / "answers.jsonl").read_text().splitlines(): | |
| answer = json.loads(line) | |
| answers[name][key(answer)] = answer | |
| for item in test: | |
| image = SITUATE_PLUS / "media" / item["image-filename"] | |
| row = {"image": {"bytes": image.read_bytes(), "path": item["image-filename"]}, "file_name": item["image-filename"]} | |
| for field in QUESTION: | |
| row[field] = item[field] | |
| for name in JUDGES: | |
| answer = answers[name][key(item)] | |
| row[f"{name}_predicted"] = answer["predicted"] | |
| row[f"{name}_correct"] = answer["correct"] | |
| yield row | |
| data = Dataset.from_generator(rows, features=features()) | |
| OUT.mkdir(exist_ok=True) | |
| for index in range(SHARDS): | |
| shard = data.shard(SHARDS, index, contiguous=True) | |
| shard.to_parquet(OUT / f"test-{index:05d}-of-{SHARDS:05d}.parquet") | |
| print(f"{len(data)} questions, {len(data.column_names)} columns -> {OUT}") | |