Rewrite dataset card for the RoboCloth release; update croissant, sample README and loader for the new repo name
fbda165 verified | """ | |
| Minimal example: load one RoboCloth material from Hugging Face. | |
| What this shows: | |
| - downloading per-material files via huggingface_hub | |
| - extracting one HDR PNG from hdr.tar without unpacking the whole archive | |
| - reading the structured observations npz (xyz, rgbs, cam_pos, light_pos) | |
| - reading the supporting JSON metadata (camera poses, scan log) | |
| Run: | |
| pip install huggingface_hub numpy pillow | |
| python load_material.py --mid 145 | |
| """ | |
| import argparse | |
| import io | |
| import json | |
| import tarfile | |
| import numpy as np | |
| from huggingface_hub import hf_hub_download | |
| REPO_ID = "koalapenguin/RoboCloth" | |
| REPO_TYPE = "dataset" | |
| def material_path(mid: str, filename: str) -> str: | |
| return f"materials/{mid}/{filename}" | |
| def download(mid: str, filename: str) -> str: | |
| """Download one per-material file; returns the local cache path.""" | |
| return hf_hub_download( | |
| repo_id=REPO_ID, | |
| repo_type=REPO_TYPE, | |
| filename=material_path(mid, filename), | |
| ) | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__) | |
| ap.add_argument("--mid", default="145", | |
| help="material id, 0-499 (e.g. 145)") | |
| args = ap.parse_args() | |
| mid = args.mid | |
| print(f"=== loading material {mid} from {REPO_ID} ===\n") | |
| # 1. JSON metadata (small, ~MB) | |
| cam_path = download(mid, "rotated_camera.json") | |
| with open(cam_path) as f: | |
| cameras = json.load(f) | |
| print(f"rotated_camera.json: {len(cameras)} camera poses") | |
| print(f" first entry keys: {list(cameras[0].keys())}\n") | |
| scan_path = download(mid, "scan_log.json") | |
| with open(scan_path) as f: | |
| scan_log = json.load(f) | |
| print(f"scan_log.json: {len(scan_log)} scan entries") | |
| print(f" first entry keys: {list(scan_log[0].keys())}\n") | |
| # 2. Structured observations npz (~hundreds of MB) | |
| obs_path = download(mid, "observations_structured.npz") | |
| obs = np.load(obs_path) | |
| print(f"observations_structured.npz arrays:") | |
| for k in obs.files: | |
| a = obs[k] | |
| print(f" {k:14s} shape={a.shape} dtype={a.dtype}") | |
| print() | |
| # 3. Point positions (~tens of MB) | |
| pts_path = download(mid, "point_positions.npz") | |
| pts = np.load(pts_path) | |
| print(f"point_positions.npz arrays:") | |
| for k in pts.files: | |
| a = pts[k] | |
| print(f" {k:14s} shape={a.shape} dtype={a.dtype}") | |
| print() | |
| # 4. HDR images: one PNG extracted from the tar without full unpack | |
| tar_path = download(mid, "hdr.tar") | |
| with tarfile.open(tar_path, mode="r") as tf: | |
| names = tf.getnames() | |
| first_png = next((n for n in names if n.endswith(".png")), None) | |
| print(f"hdr.tar: {len(names)} entries, first PNG: {first_png}") | |
| if first_png: | |
| member = tf.extractfile(first_png) | |
| data = member.read() | |
| print(f" first PNG size: {len(data) / 1024:.1f} KiB") | |
| try: | |
| from PIL import Image | |
| img = Image.open(io.BytesIO(data)) | |
| print(f" decoded: mode={img.mode} size={img.size}") | |
| except ImportError: | |
| print(" (install Pillow to decode PNGs)") | |
| if __name__ == "__main__": | |
| main() | |