AsianPlayer/TriDrive / code /tests /test_pose_causal_layout.py
AsianPlayer's picture
download
raw
3.6 kB
"""Layout contract of cwm3/results/pose_causal/<clip_id>.npz (extract_pose_causal.py): shapes, HALPE-136 order, time base,
NaN policy. Runs on one materialised npz (the first one found, or POSE_CAUSAL_NPZ); skipped when none exists yet."""
import json, os
from pathlib import Path
import numpy as np, pytest
ROOT = Path(__file__).resolve().parents[1]
POSE = ROOT / "results" / "pose_causal"
CLIP_MAP = Path("/home/USER/cwm2/private/clip_map_full.json")
def _one():
p = os.environ.get("POSE_CAUSAL_NPZ")
if p: return Path(p)
files = sorted(POSE.glob("*.npz"))
if not files: pytest.skip("no pose_causal npz yet")
return files[0]
@pytest.fixture(scope="module")
def d():
return dict(np.load(_one(), allow_pickle=False))
def test_shapes_and_dtypes(d):
assert d["kpts"].shape == (75, 136, 3) and d["kpts"].dtype == np.float16
assert d["mask"].shape == (75, 136) and d["mask"].dtype == bool
for k in ("t_rel", "t_abs", "frame_idx", "frame_ok"): assert d[k].shape == (75,), k
assert d["person_box"].shape == (4,) and d["person_box_used"].shape == (4,) and d["native_wh"].shape == (2,)
assert str(d["kpt_order"]) == "halpe136"
def test_time_base(d):
k = np.arange(75)
assert np.allclose(d["t_rel"], -5.0 + 0.2 * k, atol=1e-5)
assert np.allclose(d["t_abs"], float(d["t0"]) - 5.0 + 0.2 * k, atol=1e-9)
assert np.array_equal(d["frame_idx"], np.round(d["t_abs"] * 20).astype(np.int64)) # frame/20, no container fps
assert d["t_abs"][25] == pytest.approx(float(d["t0"])) # k = 25 is the anchor
def test_nan_policy_and_mask(d):
k = d["kpts"].astype(np.float32)
assert np.isnan(k[:, 17]).all(), "HALPE 17 head_top must be NaN (RTMW has no head-top point)"
expect = np.isfinite(k).all(-1) & (np.nan_to_num(k[..., 2]) >= 0.3)
assert np.array_equal(d["mask"], expect)
assert not d["mask"][:, 17].any()
assert not np.isfinite(k[~d["frame_ok"]]).any() # frames outside the video carry no keypoints
ok = d["mask"] & np.isfinite(k[..., 0])
assert k[..., 0][ok].min() > -0.5 and k[..., 0][ok].max() < 1.5 and k[..., 1][ok].min() > -0.5 and k[..., 1][ok].max() < 1.5
def test_virtual_joints(d):
k = d["kpts"].astype(np.float32)
both = np.isfinite(k[:, 5, :2]).all(1) & np.isfinite(k[:, 6, :2]).all(1)
assert both.any()
assert np.allclose(k[both, 18, :2], (k[both, 5, :2] + k[both, 6, :2]) / 2, atol=2e-3) # f16 rounding
assert np.allclose(k[both, 18, 2], np.minimum(k[both, 5, 2], k[both, 6, 2]), atol=2e-3)
hips = np.isfinite(k[:, 11, :2]).all(1) & np.isfinite(k[:, 12, :2]).all(1)
if hips.any(): assert np.allclose(k[hips, 19, :2], (k[hips, 11, :2] + k[hips, 12, :2]) / 2, atol=2e-3)
def test_parts_populated(d):
m = d["mask"]
assert m[:, :17].mean() > 0.5, "body joints mostly valid on a driver crop"
assert m[:, 26:94].shape[1] == 68 and m[:, 94:115].shape[1] == 21 and m[:, 115:136].shape[1] == 21
def test_box_and_provenance(d):
W, H = [int(v) for v in d["native_wh"]]
b, u = d["person_box"], d["person_box_used"]
assert 0 <= u[0] <= b[0] and 0 <= u[1] <= b[1] and b[2] <= u[2] <= W and b[3] <= u[3] <= H
assert str(d["roi_source"]) in {"pose_detector", "seat_region_prior"}
assert "rtmw-dw-x-l" in str(d["model_id"]) and "onnx" in str(d["model_id"])
if CLIP_MAP.exists():
cm = json.load(open(CLIP_MAP)); cid = _one().stem
if cid in cm:
assert str(d["uid"]) == cm[cid]["uid"] and float(d["t0"]) == float(cm[cid]["t0"]) and [W, H] == [cm[cid]["cab"]["w"], cm[cid]["cab"]["h"]]

Xet Storage Details

Size:
3.6 kB
·
Xet hash:
b1796beac4c14444204e0268b4b1e060ca92c86eb0d1847ff48432b969c074e6

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.