B-DoPED / scripts /load_examples.py
1Konny's picture
Initial release: B-DoPED dataset (library + scripts + rendered outputs)
40980f7
Raw
History Blame Contribute Delete
2.27 kB
"""
load_examples.py — quickstart for the SMAL dog dataset.
Shows how to read the library (poses / shapes / textures) and how to stream a render
shard (rgb + npz) without unpacking it. Run from the repo root:
python scripts/load_examples.py
"""
import io
import os
import glob
import tarfile
import numpy as np
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
LIB = os.path.join(REPO, "library")
OUTPUTS = os.path.join(REPO, "outputs")
def show_library():
poses = np.load(os.path.join(LIB, "poses", "poses.npz"))
print("poses.npz:")
print(" pose_6d", poses["pose_6d"].shape, poses["pose_6d"].dtype, " # (N, 34 joints, 6D rot)")
shapes = np.load(os.path.join(LIB, "shapes", "shapes.npz"), allow_pickle=True)
print("shapes.npz:")
for k in ["beta", "betas_limbs", "pose_6d"]:
print(f" {k}", shapes[k].shape, shapes[k].dtype)
print(" logscale_part_list", list(shapes["logscale_part_list"]))
tex = sorted(glob.glob(os.path.join(LIB, "textures", "texture_*.png")))
has_atlas = os.path.exists(os.path.join(LIB, "textures", "uv_atlas.pth"))
print(f"textures: {len(tex)} PNGs (2048^2) + single shared uv_atlas.pth "
f"({'present' if has_atlas else 'MISSING'})")
def stream_one_render():
shards = sorted(glob.glob(os.path.join(OUTPUTS, "shard_*.tar")))
if not shards:
print("\n(no render shards present — download outputs/ to try this)")
return
print(f"\nstreaming first sample from {os.path.basename(shards[0])}:")
with tarfile.open(shards[0], "r") as tar:
members = tar.getmembers()
rgb = next(m for m in members if m.name.endswith("/rgb/00.png"))
pose = rgb.name.split("/")[0] # pose_NNNNNN
npz_m = tar.getmember(f"{pose}/npz/00.npz")
data = np.load(io.BytesIO(tar.extractfile(npz_m).read()), allow_pickle=True)
png_bytes = tar.extractfile(rgb).read()
print(f" {pose} rgb {len(png_bytes)} bytes, npz keys: {sorted(data.files)}")
print(" npz pose_6d", data["smal/pose_6d"].shape, "| keyp_2d_all", data["smal/keyp_2d_all"].shape,
"| model", str(data["smal/smal_model_type"]))
if __name__ == "__main__":
show_library()
stream_one_render()