Download scripts/_debug_hand_binding.py from LiYacheng/r4d-bench-qa: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/datasets/LiYacheng/r4d-bench-qa/resolve/main/scripts/_debug_hand_binding.py
- Command line
-
hf download hf://datasets/LiYacheng/r4d-bench-qa/scripts/_debug_hand_binding.py
-
curl -L -o _debug_hand_binding.py https://huggingface.co/datasets/LiYacheng/r4d-bench-qa/resolve/main/scripts/_debug_hand_binding.py
2.07 kB
| """Print spatial binding for hand-like tracks in selected scenes.""" | |
| from __future__ import annotations | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| sys.path.insert(0, str(ROOT)) | |
| from scripts.predictions_ground_truth import ( # noqa: E402 | |
| SCENES_CONFIG, | |
| build_track_spatial_mapping, | |
| frame_number_from_coco_image, | |
| load_scene_files, | |
| ) | |
| SCENES = ["cook_spinach", "cut_roasted_beef", "sear_steak", "flame_steak", "cut_lemon", "keyboard", "flame_salmon"] | |
| def main(): | |
| for cfg in SCENES_CONFIG: | |
| if cfg["folder"] not in SCENES: | |
| continue | |
| coco, queries, tracks = load_scene_files(cfg) | |
| if coco is None: | |
| print("fail load", cfg["folder"]) | |
| continue | |
| cat_name_to_id = {c["name"]: c["id"] for c in coco["categories"]} | |
| mapping = build_track_spatial_mapping(coco, tracks, cat_name_to_id) | |
| # mapping: (image_id, track_id) -> ann | |
| print(f"\n==== {cfg['folder']} ====") | |
| for t in tracks["tracks"]: | |
| cat = (t.get("category") or "").lower() | |
| if not any(k in cat for k in ("hand", "arm")): | |
| continue | |
| # find a few frames | |
| samples = [(iid, ann) for (iid, tid), ann in mapping.items() if tid == t["track_id"]] | |
| samples = samples[:3] | |
| print( | |
| f" {t['track_id']}: {t['category']} | {t.get('description_zh','')[:50]}" | |
| ) | |
| for iid, ann in samples: | |
| bbox = [float(x) for x in ann["bbox"]] | |
| cx = bbox[0] + bbox[2] / 2 | |
| im = next(i for i in coco["images"] if i["id"] == iid) | |
| w = float(im["width"]) | |
| fid = frame_number_from_coco_image(im) | |
| print( | |
| f" frame={fid} img={iid} bbox_cx={cx:.0f}/{w:.0f} " | |
| f"ann_id={ann['id']} area={ann.get('area')} cat={ann['category_id']}" | |
| ) | |
| if __name__ == "__main__": | |
| main() | |