Datasets:
Download code/robohome/src/paper_eval/envelope/run_envelope_eval.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 3.79 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/paper_eval/envelope/run_envelope_eval.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/paper_eval/envelope/run_envelope_eval.py
-
curl -L -o run_envelope_eval.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/paper_eval/envelope/run_envelope_eval.py
3.79 kB
| """Offline trial: re-lay a retained manifest with envelopes, swap the retained assets in, write a manifest the audits can read.""" | |
| import argparse | |
| import json | |
| import sys | |
| from collections import Counter | |
| from pathlib import Path | |
| sys.path.insert(0, str(Path(__file__).resolve().parent)) | |
| import envelope_layout as el | |
| def synthetic_wall_items(manifest): | |
| """Wall and ceiling pieces this scene does not request, added as envelopes only to exercise the 3-D part.""" | |
| extra = [] | |
| for room in manifest['floor_plan']['rooms']: | |
| rid, kind = room['room_id'], room['room_type'] | |
| have = {el.semantic_of(e) for e in manifest['entities'] if e['room_id'] == rid} | |
| if kind == 'kitchen': | |
| if 'kitchen_counter' in have: | |
| extra.append(dict(entity_id=f'{rid}__upper_cabinet', room_id=rid, role='upper_cabinet', category='upper_cabinet')) | |
| if 'stove' in have: | |
| extra.append(dict(entity_id=f'{rid}__range_hood', room_id=rid, role='range_hood', category='range_hood')) | |
| if 'bathroom_sink' in have: | |
| extra.append(dict(entity_id=f'{rid}__mirror', room_id=rid, role='mirror', category='mirror')) | |
| extra.append(dict(entity_id=f'{rid}__ceiling_lamp', room_id=rid, role='ceiling_lamp', category='ceiling_lamp')) | |
| return extra | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument('--manifest', required=True, type=Path) | |
| ap.add_argument('--pool', required=True, type=Path) | |
| ap.add_argument('--out-dir', required=True, type=Path) | |
| ap.add_argument('--no-extras', action='store_true') | |
| args = ap.parse_args() | |
| manifest = json.loads(args.manifest.read_text()) | |
| pool = json.loads(args.pool.read_text()) | |
| work = json.loads(json.dumps(manifest)) | |
| extras = [] if args.no_extras else synthetic_wall_items(manifest) | |
| work['entities'] += extras | |
| by_entity = {} | |
| for e in work['entities']: | |
| sem = el.semantic_of(e) | |
| by_entity[e['entity_id']] = [c for c in pool if el.accepts(sem, c)] | |
| result = el.layout_home(work, by_entity) | |
| out = el.apply_to_manifest(manifest, result) | |
| synthetic_ids = {e['entity_id'] for e in extras} | |
| args.out_dir.mkdir(parents=True, exist_ok=True) | |
| (args.out_dir / 'manifest_envelope.json').write_text(json.dumps(out)) | |
| summary = dict( | |
| rooms={rid: dict(passed=r['passed'], failure=r['failure'], nodes=r['nodes'], elapsed_s=r['elapsed_s'], unplaced=r['unplaced'], | |
| envelopes={k: v.to_json() for k, v in r['envelopes'].items()}) for rid, r in result['rooms'].items()}, | |
| assets={eid: dict(asset_id=c['asset_id'], **{k: p[k] for k in ('fill', 'size_m', 'yaw_deg', 'base_z_m')}) for eid, (c, p) in result['assignments'].items()}, | |
| no_fitting_asset=[x for x in result['missing']], | |
| synthetic=sorted(synthetic_ids)) | |
| (args.out_dir / 'envelope_result.json').write_text(json.dumps(summary, indent=1, ensure_ascii=False)) | |
| problems = el.validate(result) | |
| summary['validation_problems'] = problems | |
| (args.out_dir / 'envelope_result.json').write_text(json.dumps(summary, indent=1, ensure_ascii=False)) | |
| print('3d validation problems', problems) | |
| count = Counter(('placed' if not r['unplaced'] else 'incomplete') for r in result['rooms'].values()) | |
| print('rooms', dict(count), 'unplaced', {rid: r['unplaced'] for rid, r in result['rooms'].items() if r['unplaced']}) | |
| print('failures', {rid: r['failure'] for rid, r in result['rooms'].items() if r['failure']}) | |
| print('assets swapped in', len(result['assignments']), 'no fitting asset', result['missing']) | |
| for eid, (c, p) in sorted(result['assignments'].items()): | |
| print(f' {eid:40s} fill={p["fill"]:.2f} size={[round(v, 2) for v in p["size_m"]]}') | |
| if __name__ == '__main__': | |
| main() | |