Download tools/validate_visual_semantics.py from LianeMarilin/CADBench-Extended-Multimodal-Dataset: direct link, hf CLI and curl.
- Browser
- Download file 4.28 kB
-
https://huggingface.co/datasets/LianeMarilin/CADBench-Extended-Multimodal-Dataset/resolve/main/tools/validate_visual_semantics.py
- Command line
-
hf download hf://datasets/LianeMarilin/CADBench-Extended-Multimodal-Dataset/tools/validate_visual_semantics.py
-
curl -L -o validate_visual_semantics.py https://huggingface.co/datasets/LianeMarilin/CADBench-Extended-Multimodal-Dataset/resolve/main/tools/validate_visual_semantics.py
4.28 kB
| #!/usr/bin/env python3 | |
| """Strict, reproducible checks for the 100 manually reviewed semantic records.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from collections import Counter | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| ANN = ROOT / "annotations" | |
| EXPECTED = {f"CBX100_{index:04d}" for index in range(1, 101)} | |
| def read_jsonl(path: Path) -> list[dict]: | |
| with path.open(encoding="utf-8") as handle: | |
| return [json.loads(line) for line in handle if line.strip()] | |
| def main() -> None: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--integrated", action="store_true", help="also verify metadata/prompt synchronization") | |
| args = parser.parse_args() | |
| rows = read_jsonl(ANN / "visual_semantics.jsonl") | |
| ids = [row.get("sample_id") for row in rows] | |
| errors: list[str] = [] | |
| if len(rows) != 100: | |
| errors.append(f"expected 100 rows, found {len(rows)}") | |
| if len(set(ids)) != len(ids): | |
| errors.append("duplicate sample IDs: " + str([item for item, count in Counter(ids).items() if count > 1])) | |
| if set(ids) != EXPECTED: | |
| errors.append(f"ID mismatch; missing={sorted(EXPECTED-set(ids))}, extra={sorted(set(ids)-EXPECTED)}") | |
| required = { | |
| "sample_id", "annotation_method", "primary_form", "visual_features", | |
| "visual_caption_en", "visual_caption_zh", "feature_tree_hint", "confidence", | |
| } | |
| feature_keys = {"openings", "recesses", "protrusions", "repeated_structures", "symmetry", "surface_character"} | |
| for row in rows: | |
| sid = row.get("sample_id", "<missing>") | |
| missing = required - row.keys() | |
| if missing: | |
| errors.append(f"{sid}: missing fields {sorted(missing)}") | |
| continue | |
| if row["annotation_method"] != "manual_visual_inspection_of_four_view_render": | |
| errors.append(f"{sid}: invalid annotation method") | |
| if set(row["visual_features"]) != feature_keys: | |
| errors.append(f"{sid}: visual_features schema mismatch") | |
| if not row["visual_caption_en"].strip() or not row["visual_caption_zh"].strip(): | |
| errors.append(f"{sid}: blank caption") | |
| if len(row["feature_tree_hint"]) < 2: | |
| errors.append(f"{sid}: insufficient feature-tree hints") | |
| image = ROOT / "data" / "multiview" / f"{sid}.png" | |
| if not image.is_file(): | |
| errors.append(f"{sid}: missing reviewed four-view image") | |
| if len({row["visual_caption_en"] for row in rows}) != 100: | |
| errors.append("English captions are not unique per sample") | |
| if len({row["visual_caption_zh"] for row in rows}) != 100: | |
| errors.append("Chinese captions are not unique per sample") | |
| if args.integrated: | |
| metadata = {row["sample_id"]: row for row in read_jsonl(ANN / "metadata_extended.jsonl")} | |
| prompts = {row["sample_id"]: row for row in read_jsonl(ANN / "prompts.jsonl")} | |
| if set(metadata) != EXPECTED or set(prompts) != EXPECTED: | |
| errors.append("integrated index IDs do not match the 100-sample set") | |
| for visual in rows: | |
| sid = visual["sample_id"] | |
| if sid not in metadata or sid not in prompts: | |
| continue | |
| if metadata[sid]["descriptions"]["en"] != visual["visual_caption_en"]: | |
| errors.append(f"{sid}: metadata English description is not synchronized") | |
| if prompts[sid]["descriptions"]["zh"] != visual["visual_caption_zh"]: | |
| errors.append(f"{sid}: prompt-index Chinese description is not synchronized") | |
| if metadata[sid]["prompts"] != prompts[sid]["prompts"]: | |
| errors.append(f"{sid}: prompt payloads are not synchronized") | |
| if errors: | |
| print("Visual-semantic validation: FAILED") | |
| for error in errors: | |
| print("-", error) | |
| raise SystemExit(1) | |
| print("Visual-semantic validation: PASSED") | |
| print("- 100/100 sample IDs present and unique") | |
| print("- 100/100 four-view images present") | |
| print("- 100/100 English and Chinese captions are sample-specific") | |
| print("- structured features and feature-tree hints complete") | |
| if args.integrated: | |
| print("- metadata and prompt indexes synchronized") | |
| if __name__ == "__main__": | |
| main() | |