| """ |
| check_force_range.py |
| |
| Scan ALL clips and report the RAW (std-normalized, pre-clip) force abs-max per |
| clip, so you know exactly how many clips have extreme forces (>10, >15, etc). |
| This does NOT depend on the loss ranking -- it reads the actual data magnitudes. |
| |
| Reports per-clip absmax (normalized by active std, BEFORE force_clip), sorted, |
| plus a histogram of how many clips exceed each threshold. |
| |
| Run: |
| python examples/wanvideo/model_training/check_force_range.py \ |
| --clips ... --stats ... --source_root ... |
| """ |
| import argparse, os, sys |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| import numpy as np |
| from tqdm import tqdm |
|
|
| |
| import json |
|
|
|
|
| def main(): |
| ap = argparse.ArgumentParser() |
| ap.add_argument("--clips", required=True) |
| ap.add_argument("--stats", required=True) |
| ap.add_argument("--source_root", required=True) |
| args = ap.parse_args() |
|
|
| stats = json.load(open(args.stats)) |
| |
| std = np.array(stats.get("force_ch_active_std", |
| stats.get("force_ch_std"))) |
| clips = json.load(open(args.clips))["clips"] |
|
|
| rows = [] |
| for i, c in enumerate(tqdm(clips, desc="clips")): |
| |
| ep = c["episode"] if isinstance(c, dict) and "episode" in c else "" |
| fpaths = None |
| for k in ("force_paths", "force", "force_npy"): |
| if isinstance(c, dict) and k in c: |
| fpaths = c[k]; break |
| if fpaths is None and "frame_indices" in c: |
| base = os.path.join("modalities", "force") |
| fpaths = [os.path.join(base, f"{idx:06d}.npy") for idx in c["frame_indices"]] |
| if fpaths is None: |
| continue |
|
|
| clip_absmax = 0.0 |
| per_ch_absmax = np.zeros(6) |
| n_loaded = 0 |
| for fp in fpaths: |
| |
| full = fp |
| if not os.path.isabs(full): |
| full = os.path.join(args.source_root, ep, fp) |
| if not os.path.exists(full): |
| continue |
| fp = full |
| n_loaded += 1 |
| f = np.load(fp).astype(np.float64) |
| fn = f / std[:, None, None] |
| a = np.abs(fn) |
| clip_absmax = max(clip_absmax, a.max()) |
| per_ch_absmax = np.maximum(per_ch_absmax, a.reshape(6, -1).max(1)) |
| if i == 0: |
| print(f"[debug] clip 0: episode={ep!r}, " |
| f"{len(fpaths)} paths, {n_loaded} loaded, " |
| f"example full path:\n " |
| f"{os.path.join(args.source_root, ep, fpaths[0])}") |
| rows.append((i, clip_absmax, per_ch_absmax)) |
|
|
| rows.sort(key=lambda r: -r[1]) |
| print("\n" + "="*72) |
| print("ALL clips sorted by normalized force abs-max (BEFORE clip):") |
| print(f"{'clip':>4s} {'absmax':>8s} per-channel absmax [Lfx Lfy Lfz Rfx Rfy Rfz]") |
| print("-"*72) |
| for i, am, pc in rows: |
| pcs = " ".join(f"{v:4.1f}" for v in pc) |
| print(f"{i:4d} {am:8.2f} [{pcs}]") |
|
|
| absmaxes = np.array([r[1] for r in rows]) |
| print("="*72) |
| for thr in [5, 8, 10, 12, 15, 20]: |
| n = (absmaxes > thr).sum() |
| print(f" clips with force absmax > {thr:2d}: {n}/{len(absmaxes)}") |
| print(f"\n overall max across all clips: {absmaxes.max():.2f}") |
| print(f" p50={np.percentile(absmaxes,50):.2f} " |
| f"p90={np.percentile(absmaxes,90):.2f} " |
| f"p99={np.percentile(absmaxes,99):.2f}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |