File size: 2,509 Bytes
14b31b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Load the dataset, print what one clip holds, and sanity-check the conventions.

    pip install datasets numpy
    python examples/load.py
"""
import numpy as np
from datasets import load_dataset, Video

REPO = "shinben0327/v2i-test"

# Reading any row decodes the `video` column, which needs torchcodec. Turn decoding off and
# we get the raw mp4 bytes instead, with no extra dependency.
ds = load_dataset(REPO, split="train").cast_column("video", Video(decode=False)).with_format("numpy")
print(f"{len(ds)} clips, {len(set(ds['object']))} objects, "
      f"{int(np.sum(ds['n_frames']))} frames, {np.sum(ds['duration_s'])/60:.1f} min\n")

c = ds[0]
print(f"clip_id : {c['clip_id']}")
print(f"frames  : {c['n_frames']} @ {c['fps']} fps  ({c['duration_s']:.2f} s)")
print(f"dof_pos : {c['dof_pos'].shape}   root_pos: {c['root_pos'].shape}")
print(f"object  : {c['object']}  scale={c['object_scale']:.2f}")
print(f"video   : {len(c['video']['bytes'])/1e3:.0f} kB of mp4 embedded in the row")

# --- clearance is a SUBTRACTION; calibrate it against the ground-contact flag ---
clearance = c["object_pos"][:, 2] - c["object_min_height_per_frame"]
on_floor = c["object_ground_contact_sequence"].astype(bool)
if on_floor.any() and (~on_floor).any():
    print(f"\nclearance while on the floor : {clearance[on_floor].mean():.4f} m  (expect ~0)")
    print(f"clearance while lifted       : {clearance[~on_floor].mean():.4f} m")

# --- quaternions are wxyz: index 0 of the FK cache is the pelvis, so it must match root_rot ---
fk = load_dataset(REPO, "fk", split="train").with_format("numpy")
row = {r["clip_id"]: r for r in fk}[c["clip_id"]]
assert np.array_equal(row["world_body_pos"][:, 0], c["root_pos"])
assert np.array_equal(row["world_body_orient"][:, 0], c["root_rot"])
print("\nfk[:,0] == root pose  ✓  (quaternions are wxyz)")

# --- contact points are NaN-masked, not zero-masked ---
pts, flags = c["fixed_contact_points_per_frame_in_object_frame"], c["per_link_contact_flags"]
assert np.array_equal(np.isnan(pts).all(-1), ~flags), "NaN mask should equal the contact flags"
print("NaN mask == per_link_contact_flags  ✓")

for i, link in enumerate(c["contact_link_names"]):
    print(f"  {link:24s} in contact {flags[:, i].mean()*100:5.1f}% of frames")

# --- filtering on the precomputed stats needs no trajectory read ---
lifts = ds.filter(lambda r: r["obj_airborne_frac"] > 0.3)
print(f"\n{len(lifts)}/{len(ds)} clips lift the object clear of the floor for >30% of frames")