Nadeem-Shoukath115113/opensarm / local /_target_baseline.py
Nadeem-Shoukath115113's picture
download
raw
1.69 kB
import sys, yaml, torch, numpy as np
from pathlib import Path
from torch.utils.data import DataLoader
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
cfg = yaml.safe_load(open(ROOT / "config/sarm2.yaml"))["cfg"]
m, g = cfg["model"], cfg["general"]
from lerobot.common.datasets.rm_act_pri_lerobot_dataset import FrameGapLeRobotDataset
from utils.data_utils import adapt_lerobot_batch_act_pri
ds = FrameGapLeRobotDataset(
repo_id=g["repo_id"], image_names=g["camera_names"],
n_obs_steps=m["n_obs_steps"], frame_gap=m["frame_gap"],
max_rewind_steps=m["max_rewind_steps"], task_list=m["task_list"], stage_model=False)
torch.manual_seed(0)
dl = DataLoader(ds, batch_size=128, shuffle=True, num_workers=8)
chunks = []
for i, batch in enumerate(dl):
b = adapt_lerobot_batch_act_pri(batch, n_obs_steps=m["n_obs_steps"], camera_names=g["camera_names"])
chunks.append(b["steps_to_go"].float()) # use_future_step: True -> this is the target
if i >= 19:
break
t = torch.cat(chunks) # (N, T)
print("target = steps_to_go, shape:", tuple(t.shape))
print("range: min=%.4f max=%.4f mean=%.4f" % (t.min(), t.mean().new_tensor(t.max()), t.mean()))
print()
print("MSE if we always predict the global mean : %.5f <-- 'learned nothing' baseline" % t.var(unbiased=False))
print()
print("per-position (0=episode start, 1..6=mid window, 7..9=rewind):")
for p in range(t.shape[1]):
col = t[:, p]
print(" pos %d mean=%.4f var=%.5f" % (p, col.mean(), col.var(unbiased=False)))
print()
pred_col_mean = ((t - t.mean(0, keepdim=True)) ** 2).mean()
print("MSE if we predict each position's own mean: %.5f" % pred_col_mean)

Xet Storage Details

Size:
1.69 kB
·
Xet hash:
7b9dcbf3e244444e753c58c26300cbdcb50b32dc8e566982bede42fda152d7cc

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