Spaces:
Running
Running
Download scripts/build_apt0_scene_zip.py from ManiacWallnut/ManiTaskGen: direct link, hf CLI and curl.
- Browser
- Download file 4.21 kB
-
https://huggingface.co/spaces/ManiacWallnut/ManiTaskGen/resolve/main/scripts/build_apt0_scene_zip.py
- Command line
-
hf download hf://spaces/ManiacWallnut/ManiTaskGen/scripts/build_apt0_scene_zip.py
-
curl -L -o build_apt0_scene_zip.py https://huggingface.co/spaces/ManiacWallnut/ManiTaskGen/resolve/main/scripts/build_apt0_scene_zip.py
4.21 kB
| """ | |
| Build a `scene.zip` pack for ReplicaCAD `apt_0` from the local dataset | |
| downloaded by `scripts/download_habitat_datasets.py`. | |
| The resulting pack can be uploaded to the ManiTaskGen demo exactly like the | |
| built-in `example_scene.zip`. The pack is NOT shipped in the repository | |
| (~80 MB, ReplicaCAD assets are CC-BY-NC 4.0 by Meta). | |
| Usage (from the repository root, after downloading the dataset): | |
| python scripts/build_apt0_scene_zip.py [--out output/apt_0_scene.zip] | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| import zipfile | |
| REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| DATASET_ROOT = os.path.join(REPO_ROOT, "data", "datasets", "replica_cad_dataset") | |
| SCENE_INSTANCE = os.path.join( | |
| DATASET_ROOT, "configs", "scenes", "apt_0.scene_instance.json" | |
| ) | |
| # Objects excluded by config/default_config.yml (keep the pack consistent with | |
| # the paper's default preprocessing). | |
| NOT_DESIRED_OBJECTS = { | |
| "frl_apartment_handbag", "frl_apartment_cushion_01", | |
| "frl_apartment_monitor", "frl_apartment_cloth_01", | |
| "frl_apartment_cloth_02", "frl_apartment_cloth_03", | |
| "frl_apartment_cloth", "frl_apartment_umbrella", | |
| "frl_apartment_tv_screen", "frl_apartment_indoor_plant_01", | |
| "frl_apartment_monitor_stand", "frl_apartment_setupbox", | |
| "frl_apartment_beanbag", "frl_apartment_bike_01", | |
| "frl_apartment_bike_02", "frl_apartment_indoor_plant_02", | |
| "frl_apartment_picture_01", "frl_apartment_towel", | |
| "frl_apartment_rug_01", "frl_apartment_rug_02", | |
| "frl_apartment_rug_03", "frl_apartment_mat", "frl_apartment_tv_object", | |
| } | |
| def main(out_path: str) -> None: | |
| with open(SCENE_INSTANCE) as f: | |
| scene = json.load(f) | |
| scene["object_instances"] = [ | |
| o | |
| for o in scene.get("object_instances", []) | |
| if o.get("template_name", "").split("/")[-1] not in NOT_DESIRED_OBJECTS | |
| ] | |
| stage_template = scene["stage_instance"]["template_name"] | |
| collected = set() | |
| missing = [] | |
| def add(path: str) -> None: | |
| rel = os.path.relpath(path, DATASET_ROOT) | |
| if rel in collected: | |
| return | |
| if os.path.isfile(path): | |
| collected.add(rel) | |
| else: | |
| missing.append(rel) | |
| add(os.path.join(DATASET_ROOT, f"{stage_template}.glb")) | |
| for obj in scene["object_instances"]: | |
| template = obj["template_name"].split("/")[-1] | |
| cfg_path = os.path.join( | |
| DATASET_ROOT, "configs", "objects", f"{template}.object_config.json" | |
| ) | |
| if not os.path.isfile(cfg_path): | |
| missing.append(f"configs/objects/{template}.object_config.json") | |
| continue | |
| add(cfg_path) | |
| with open(cfg_path) as f: | |
| cfg = json.load(f) | |
| for key in ("render_asset", "collision_asset"): | |
| asset = cfg.get(key) | |
| if asset: | |
| add(os.path.normpath(os.path.join(os.path.dirname(cfg_path), asset))) | |
| for art in scene.get("articulated_object_instances", []): | |
| base = os.path.basename(art.get("template_name", "")) | |
| urdf_dir = os.path.join(DATASET_ROOT, "urdf", base) | |
| if os.path.isdir(urdf_dir): | |
| for root, _, files in os.walk(urdf_dir): | |
| for name in files: | |
| add(os.path.join(root, name)) | |
| if missing: | |
| print("Missing files (not in dataset?):") | |
| for m in missing[:20]: | |
| print(f" - {m}") | |
| sys.exit(1) | |
| os.makedirs(os.path.dirname(os.path.abspath(out_path)), exist_ok=True) | |
| with open(SCENE_INSTANCE) as f: | |
| scene_json = json.dumps(scene, indent=2) | |
| with zipfile.ZipFile(out_path, "w", zipfile.ZIP_DEFLATED) as zf: | |
| zf.writestr( | |
| "configs/scenes/apt_0.scene_instance.json", scene_json | |
| ) | |
| for rel in sorted(collected): | |
| zf.write(os.path.join(DATASET_ROOT, rel), arcname=rel) | |
| size_mb = os.path.getsize(out_path) / 1e6 | |
| print(f"Wrote {out_path} ({size_mb:.1f} MB, {len(collected)} files)") | |
| if __name__ == "__main__": | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument( | |
| "--out", default=os.path.join(REPO_ROOT, "output", "apt_0_scene.zip") | |
| ) | |
| args = parser.parse_args() | |
| main(args.out) | |