File size: 1,760 Bytes
d94c87e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Add q01/q10/q50/q90/q99 to a v3.0 dataset's meta/stats.json, computed from the
parquet data files directly. No video decode (VISUAL normalization is IDENTITY for
pi0/pi05), and no hub push."""
import json
import sys
from pathlib import Path

import numpy as np
import pandas as pd

ROOT = Path(sys.argv[1] if len(sys.argv) > 1 else "/mnt/drive2/vla_traning_ws/pi0/smoth_data_50_upper")
QUANTILES = [0.01, 0.10, 0.50, 0.90, 0.99]
QKEYS = [f"q{int(q * 100):02d}" for q in QUANTILES]

info = json.load(open(ROOT / "meta" / "info.json"))
stats = json.load(open(ROOT / "meta" / "stats.json"))

frames = [pd.read_parquet(f) for f in sorted((ROOT / "data").rglob("file-*.parquet"))]
df = pd.concat(frames, ignore_index=True)
print(f"loaded {len(df)} frames from {len(frames)} data file(s)")

for key in stats:
    if key not in df.columns:
        print(f"  {key}: SKIP (not a data column)")
        continue
    col = df[key]
    if isinstance(col.iloc[0], (np.ndarray, list)):
        data = np.stack([np.asarray(v, dtype=np.float64) for v in col])  # (n_frames, dim)
    else:
        data = np.asarray(col, dtype=np.float64).reshape(-1, 1)

    qvals = np.quantile(data, QUANTILES, axis=0)  # (n_q, dim)
    for qkey, row in zip(QKEYS, qvals, strict=True):
        stats[key][qkey] = row.tolist()

    # Recompute min/max/mean/std from the same data so everything is self-consistent.
    for stat_name, fn in (("min", np.min), ("max", np.max), ("mean", np.mean), ("std", np.std)):
        stats[key][stat_name] = fn(data, axis=0).tolist()
    stats[key]["count"] = [int(data.shape[0])]
    print(f"  {key}: dim={data.shape[1]} -> added {QKEYS}")

json.dump(stats, open(ROOT / "meta" / "stats.json", "w"), indent=4)
print("wrote", ROOT / "meta" / "stats.json")