File size: 3,162 Bytes
42f19ad
fbda165
42f19ad
 
 
 
 
 
 
 
 
fbda165
42f19ad
 
 
 
 
 
 
 
 
fbda165
42f19ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbda165
 
42f19ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
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()