Datasets:
Download code/robohome/src/paper_eval/traversability/traverse.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 4.67 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/paper_eval/traversability/traverse.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/paper_eval/traversability/traverse.py
-
curl -L -o traverse.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/paper_eval/traversability/traverse.py
4.67 kB
| import json, os, yaml, sys | |
| from shapely.geometry import box, Point | |
| from shapely.ops import unary_union | |
| from shapely import affinity | |
| S = sys.argv[1] | |
| g1 = yaml.safe_load(open(S + "/engine/source/configs/robots/task_constraints_v1.yaml"))["robots"]["g1"] | |
| walk_r = max(g1["body_width_m"], g1["body_depth_m"]) / 2 + g1["depth_model"]["body_edge_clearance_m"] | |
| carry_r = g1["carry_corridor_width_m"] / 2 | |
| W = json.load(open("walls_all.json")); rows = [] | |
| def fp(e): | |
| w, d = e["dimensions_m"][:2]; cx, cy = e.get("actual_center_xy_m") or e["center_xy_m"] | |
| return affinity.rotate(box(cx - w / 2, cy - d / 2, cx + w / 2, cy + d / 2), e.get("yaw_deg", 0.0), origin=(cx, cy)) | |
| for seed, info in W.items(): | |
| G = os.path.dirname(info["blend"]); sm = json.load(open(G + "/SceneManifest.v16.json")) | |
| wt = sm.get("wall_thickness_m", 0.2) | |
| from shapely.geometry import MultiLineString | |
| walls = [MultiLineString(info["segments"]).buffer(0.02)] if info["segments"] else [] | |
| from shapely.geometry import LineString | |
| portals = [LineString(p["opening_segment_xy_m"]).buffer(0.45, cap_style=2) for p in sm["portals"] if p.get("opening_segment_xy_m")] | |
| house = unary_union([box(*r["bounds_m"]) for r in sm["rooms"]] + portals).difference(unary_union(walls)) | |
| floor_ents = [e for e in sm["entities"] if not (e.get("supported_by_entity_id") or e.get("support_entity_id")) and e.get("role") not in ("rug", "floor_cover")] | |
| entry = next(p for p in sm["portals"] if "entry" in p["portal_id"]); (x0, y0), (x1, y1) = entry["opening_segment_xy_m"]; mid = Point((x0 + x1) / 2, (y0 + y1) / 2) | |
| res = {"seed": seed, "rooms": [r["room_id"] for r in sm["rooms"]]} | |
| for tag, r_body, excl_roles in (("walk", walk_r, set()), ("walk_no_chairs", walk_r, {"dining_chair"}), ("carry", carry_r, set())): | |
| obst = unary_union([fp(e) for e in floor_ents if e.get("role") not in excl_roles]) | |
| free = house.buffer(-r_body).difference(obst.buffer(r_body)); comps = list(getattr(free, "geoms", [free])) | |
| ec = min(comps, key=lambda c: c.distance(mid)) if comps else None | |
| reach = [r["room_id"] for r in sm["rooms"] if ec is not None and ec.intersects(box(*r["bounds_m"]).buffer(-0.3))] | |
| res[tag] = sorted(set(res["rooms"]) - set(reach)) | |
| rows.append(res) | |
| print("%-11s rooms=%d unreachable(walk)=%s unreachable(walk, chairs moved)=%s unreachable(carry 0.55m)=%s" % (seed, len(res["rooms"]), res["walk"], res["walk_no_chairs"], res["carry"])) | |
| json.dump(rows, open("traversability_accepted.json", "w"), indent=1) | |
| n = len(rows); print("scenes with >=1 unreachable room: walk %d/%d, walk(chairs moved) %d/%d, carry %d/%d" % (sum(bool(r["walk"]) for r in rows), n, sum(bool(r["walk_no_chairs"]) for r in rows), n, sum(bool(r["carry"]) for r in rows), n)) | |
| # blocker attribution: for each unreachable room, which single floor item, if removed, restores walking access | |
| from collections import Counter | |
| blockers = Counter() | |
| for res in rows: | |
| if not res["walk"]: continue | |
| info = W[res["seed"]]; G = os.path.dirname(info["blend"]); sm = json.load(open(G + "/SceneManifest.v16.json")) | |
| from shapely.geometry import LineString, MultiLineString | |
| walls = [MultiLineString(info["segments"]).buffer(0.02)] | |
| portals = [LineString(p["opening_segment_xy_m"]).buffer(0.45, cap_style=2) for p in sm["portals"] if p.get("opening_segment_xy_m")] | |
| house = unary_union([box(*r["bounds_m"]) for r in sm["rooms"]] + portals).difference(unary_union(walls)) | |
| fe = [e for e in sm["entities"] if not (e.get("supported_by_entity_id") or e.get("support_entity_id")) and e.get("role") not in ("rug", "floor_cover")] | |
| entry = next(p for p in sm["portals"] if "entry" in p["portal_id"]); (x0, y0), (x1, y1) = entry["opening_segment_xy_m"]; mid = Point((x0 + x1) / 2, (y0 + y1) / 2) | |
| def unreachable(skip): | |
| obst = unary_union([fp(e) for e in fe if e["entity_id"] != skip]) | |
| free = house.buffer(-walk_r).difference(obst.buffer(walk_r)); comps = list(getattr(free, "geoms", [free])) | |
| ec = min(comps, key=lambda c: c.distance(mid)) | |
| return {r["room_id"] for r in sm["rooms"] if not ec.intersects(box(*r["bounds_m"]).buffer(-0.3))} | |
| base = unreachable(None); found = [] | |
| for e in fe: | |
| fixed = base - unreachable(e["entity_id"]) | |
| if fixed: found.append((e["entity_id"], e.get("role"), sorted(fixed))) | |
| res["single_blockers"] = found | |
| for _, role, _ in found: blockers[role] += 1 | |
| print("%-11s unreachable=%s single blockers=%s" % (res["seed"], sorted(base), [(a, c) for a, b, c in found])) | |
| print("blocker roles:", dict(blockers)) | |
| json.dump(rows, open("traversability_accepted.json", "w"), indent=1) | |