Package exact adaptive implementation: code/examples/realRobots/Piper/eval_files/evaluate_adaptive_bspline_open_loop.py
Browse files
models/piper-pick-white-block-25hz-qwenpi-v3-adaptive-left-exclude-gripper-native-controls13-gb32-50k-20260905/code/examples/realRobots/Piper/eval_files/evaluate_adaptive_bspline_open_loop.py
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Native-variable-horizon open-loop evaluation for adaptive-left B-splines."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import json
|
| 8 |
+
import os
|
| 9 |
+
import time
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
import torch
|
| 14 |
+
from omegaconf import OmegaConf
|
| 15 |
+
from torch.utils.data import DataLoader, Subset
|
| 16 |
+
|
| 17 |
+
os.environ.setdefault("NO_ALBUMENTATIONS_UPDATE", "1")
|
| 18 |
+
|
| 19 |
+
REPO_ROOT = Path(__file__).resolve().parents[4]
|
| 20 |
+
DEFAULT_RUN_DIR = REPO_ROOT / (
|
| 21 |
+
"results/Checkpoints/piper_pick_white_block_20260818_qwenpi_25hz_"
|
| 22 |
+
"adaptive_left_bspline_excl_gripper_native_c13_gb32_50k"
|
| 23 |
+
)
|
| 24 |
+
DEFAULT_CHECKPOINT = DEFAULT_RUN_DIR / "checkpoints/steps_50000_pytorch_model.pt"
|
| 25 |
+
DEFAULT_CONFIG = REPO_ROOT / (
|
| 26 |
+
"examples/realRobots/Piper/train_files/"
|
| 27 |
+
"starvla_qwenpi_piper_20260818_25hz_adaptive_left_bspline_gb32_50k.yaml"
|
| 28 |
+
)
|
| 29 |
+
ACTION_NAMES = ["joint_1", "joint_2", "joint_3", "joint_4", "joint_5", "joint_6", "gripper"]
|
| 30 |
+
PARAMETER_NAMES = ACTION_NAMES + ["duration"]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _collate_samples(samples):
|
| 34 |
+
return samples
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _metric_summary(values: np.ndarray) -> dict:
|
| 38 |
+
values = np.asarray(values, dtype=np.float64)
|
| 39 |
+
absolute = np.abs(values)
|
| 40 |
+
return {
|
| 41 |
+
"count": int(values.size),
|
| 42 |
+
"mse": float(np.mean(np.square(values))),
|
| 43 |
+
"rmse": float(np.sqrt(np.mean(np.square(values)))),
|
| 44 |
+
"mae": float(np.mean(absolute)),
|
| 45 |
+
"p95_absolute_error": float(np.percentile(absolute, 95)),
|
| 46 |
+
"max_absolute_error": float(np.max(absolute)),
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _trajectory_metrics(error: np.ndarray, valid: np.ndarray) -> dict:
|
| 51 |
+
values = np.asarray(error)
|
| 52 |
+
mask = np.asarray(valid, dtype=bool)
|
| 53 |
+
if values.ndim != 3 or mask.shape != values.shape[:2] or not mask.any():
|
| 54 |
+
raise ValueError(f"invalid trajectory/mask shapes: {values.shape}, {mask.shape}")
|
| 55 |
+
per_horizon = []
|
| 56 |
+
for step in range(values.shape[1]):
|
| 57 |
+
step_values = values[mask[:, step], step]
|
| 58 |
+
per_horizon.append(None if not len(step_values) else _metric_summary(step_values))
|
| 59 |
+
return {
|
| 60 |
+
"overall": _metric_summary(values[mask]),
|
| 61 |
+
"arm": _metric_summary(values[..., :6][mask]),
|
| 62 |
+
"gripper": _metric_summary(values[..., 6][mask]),
|
| 63 |
+
"per_horizon": per_horizon,
|
| 64 |
+
"per_dimension": {
|
| 65 |
+
name: _metric_summary(values[..., dim][mask])
|
| 66 |
+
for dim, name in enumerate(ACTION_NAMES)
|
| 67 |
+
},
|
| 68 |
+
"first_action": _metric_summary(values[:, 0]),
|
| 69 |
+
"valid_plan_steps": int(mask.sum()),
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _parameter_metrics(error: np.ndarray) -> dict:
|
| 74 |
+
return {
|
| 75 |
+
"overall": _metric_summary(error),
|
| 76 |
+
"controls": _metric_summary(error[..., :7]),
|
| 77 |
+
"duration": _metric_summary(error[..., 7]),
|
| 78 |
+
"per_row": [_metric_summary(error[:, row]) for row in range(error.shape[1])],
|
| 79 |
+
"per_dimension": {
|
| 80 |
+
name: _metric_summary(error[..., dim])
|
| 81 |
+
for dim, name in enumerate(PARAMETER_NAMES)
|
| 82 |
+
},
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _load_raw_episode_actions(dataset) -> dict[int, np.ndarray]:
|
| 87 |
+
result = {}
|
| 88 |
+
for trajectory_id, trajectory_length in zip(dataset.trajectory_ids, dataset.trajectory_lengths):
|
| 89 |
+
episode_id = int(trajectory_id)
|
| 90 |
+
frame = dataset.get_trajectory_data(episode_id)
|
| 91 |
+
actions = np.stack(frame["action"].to_numpy()).astype(np.float32)
|
| 92 |
+
if actions.shape != (int(trajectory_length), 7) or not np.isfinite(actions).all():
|
| 93 |
+
raise ValueError(f"Episode {episode_id} action mismatch: {actions.shape}")
|
| 94 |
+
result[episode_id] = actions
|
| 95 |
+
return result
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def _raw_action_chunks(dataset, raw_actions, sample_indices, horizon):
|
| 99 |
+
episode_ids = np.empty(len(sample_indices), dtype=np.int64)
|
| 100 |
+
frame_ids = np.empty(len(sample_indices), dtype=np.int64)
|
| 101 |
+
chunks = np.empty((len(sample_indices), horizon, 7), dtype=np.float32)
|
| 102 |
+
available = np.zeros((len(sample_indices), horizon), dtype=bool)
|
| 103 |
+
for row, sample_index in enumerate(sample_indices):
|
| 104 |
+
episode_id, frame_id = map(int, dataset.all_steps[int(sample_index)])
|
| 105 |
+
trajectory = raw_actions[episode_id]
|
| 106 |
+
offsets = np.arange(horizon)
|
| 107 |
+
available[row] = offsets < len(trajectory) - frame_id
|
| 108 |
+
chunks[row] = trajectory[np.minimum(frame_id + offsets, len(trajectory) - 1)]
|
| 109 |
+
episode_ids[row] = episode_id
|
| 110 |
+
frame_ids[row] = frame_id
|
| 111 |
+
return chunks, available, episode_ids, frame_ids
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _decode(model, parameters, output_horizon):
|
| 115 |
+
from starVLA.model.framework.VLM4A.QwenPI_v3_AdaptiveBSpline import decode_adaptive_parameters
|
| 116 |
+
|
| 117 |
+
return decode_adaptive_parameters(
|
| 118 |
+
parameters,
|
| 119 |
+
action_dim=model.spline_action_dim,
|
| 120 |
+
degree=model.spline_degree,
|
| 121 |
+
duration_min=model.duration_min,
|
| 122 |
+
duration_max=model.duration_max,
|
| 123 |
+
output_horizon=output_horizon,
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def _horizon_summary(values: np.ndarray) -> dict:
|
| 128 |
+
values = np.asarray(values, dtype=np.int64)
|
| 129 |
+
return {
|
| 130 |
+
"min": int(values.min()),
|
| 131 |
+
"median": float(np.median(values)),
|
| 132 |
+
"mean": float(values.mean()),
|
| 133 |
+
"p95": float(np.quantile(values, 0.95)),
|
| 134 |
+
"max": int(values.max()),
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
def main() -> None:
|
| 139 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 140 |
+
parser.add_argument("--checkpoint", type=Path, default=DEFAULT_CHECKPOINT)
|
| 141 |
+
parser.add_argument("--config", type=Path, default=DEFAULT_CONFIG)
|
| 142 |
+
parser.add_argument("--output-dir", type=Path, default=DEFAULT_RUN_DIR)
|
| 143 |
+
parser.add_argument("--batch-size", type=int, default=16)
|
| 144 |
+
parser.add_argument("--num-workers", type=int, default=8)
|
| 145 |
+
parser.add_argument("--seed", type=int, default=42)
|
| 146 |
+
parser.add_argument("--max-samples", type=int)
|
| 147 |
+
args = parser.parse_args()
|
| 148 |
+
if args.batch_size <= 0 or args.num_workers < 0:
|
| 149 |
+
raise ValueError("--batch-size must be positive and --num-workers non-negative")
|
| 150 |
+
|
| 151 |
+
checkpoint = args.checkpoint.expanduser().resolve()
|
| 152 |
+
config_path = args.config.expanduser().resolve()
|
| 153 |
+
output_dir = args.output_dir.expanduser().resolve()
|
| 154 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 155 |
+
torch.manual_seed(args.seed)
|
| 156 |
+
np.random.seed(args.seed)
|
| 157 |
+
|
| 158 |
+
from deployment.model_server.action_constraints import GripperConstraint
|
| 159 |
+
from deployment.model_server.policy_wrapper import PolicyServerWrapper
|
| 160 |
+
from starVLA.dataloader.lerobot_datasets import get_vla_dataset
|
| 161 |
+
|
| 162 |
+
cfg = OmegaConf.load(config_path)
|
| 163 |
+
representation = cfg.framework.action_representation
|
| 164 |
+
if representation.execution_horizon_mode != "predicted_duration_sum":
|
| 165 |
+
raise ValueError("evaluation requires native variable-length execution")
|
| 166 |
+
horizon_cap = int(representation.max_native_horizon)
|
| 167 |
+
dataset = get_vla_dataset(cfg.datasets.vla_data, mode="val").datasets[0]
|
| 168 |
+
total_observations = len(dataset)
|
| 169 |
+
if args.max_samples is None or args.max_samples >= total_observations:
|
| 170 |
+
sample_indices = np.arange(total_observations, dtype=np.int64)
|
| 171 |
+
elif args.max_samples <= 0:
|
| 172 |
+
raise ValueError("--max-samples must be positive")
|
| 173 |
+
else:
|
| 174 |
+
sample_indices = np.unique(
|
| 175 |
+
np.linspace(0, total_observations - 1, args.max_samples, dtype=np.int64)
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
raw_actions = _load_raw_episode_actions(dataset)
|
| 179 |
+
raw_targets, available, episode_ids, frame_ids = _raw_action_chunks(
|
| 180 |
+
dataset, raw_actions, sample_indices, horizon_cap
|
| 181 |
+
)
|
| 182 |
+
loader_kwargs = {
|
| 183 |
+
"batch_size": args.batch_size,
|
| 184 |
+
"shuffle": False,
|
| 185 |
+
"num_workers": args.num_workers,
|
| 186 |
+
"pin_memory": True,
|
| 187 |
+
"collate_fn": _collate_samples,
|
| 188 |
+
}
|
| 189 |
+
if args.num_workers:
|
| 190 |
+
loader_kwargs.update(persistent_workers=True, prefetch_factor=2)
|
| 191 |
+
loader = DataLoader(Subset(dataset, sample_indices.tolist()), **loader_kwargs)
|
| 192 |
+
|
| 193 |
+
policy = PolicyServerWrapper(
|
| 194 |
+
ckpt_path=str(checkpoint), device="cuda", use_bf16=True, unnorm_key="new_embodiment"
|
| 195 |
+
)
|
| 196 |
+
model = policy._framework
|
| 197 |
+
processor = policy.get_norm_processor()
|
| 198 |
+
constraint = GripperConstraint(
|
| 199 |
+
mode="binary", dimension=6, minimum=0.0, maximum=1.0, threshold=0.3
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
collected = {key: [] for key in (
|
| 203 |
+
"predicted_parameters", "target_parameters", "predicted_durations",
|
| 204 |
+
"target_durations", "predicted_horizons", "target_horizons",
|
| 205 |
+
"predicted_actions", "target_actions",
|
| 206 |
+
)}
|
| 207 |
+
inference_seconds = []
|
| 208 |
+
for batch_number, samples in enumerate(loader, start=1):
|
| 209 |
+
requests = [{key: sample[key] for key in ("image", "lang", "state")} for sample in samples]
|
| 210 |
+
target_parameters = np.asarray([sample["action"] for sample in samples], dtype=np.float32)
|
| 211 |
+
start = time.perf_counter()
|
| 212 |
+
predicted_parameters = np.asarray(
|
| 213 |
+
model.predict_action_parameters(examples=requests)["normalized_actions"], dtype=np.float32
|
| 214 |
+
)
|
| 215 |
+
inference_seconds.append(time.perf_counter() - start)
|
| 216 |
+
predicted_normalized, predicted_durations, predicted_horizons = _decode(
|
| 217 |
+
model, predicted_parameters, horizon_cap
|
| 218 |
+
)
|
| 219 |
+
target_normalized, target_durations, target_horizons = _decode(
|
| 220 |
+
model, target_parameters, horizon_cap
|
| 221 |
+
)
|
| 222 |
+
predicted_actions = np.stack([
|
| 223 |
+
processor.unapply_actions(value) for value in predicted_normalized
|
| 224 |
+
]).astype(np.float32)
|
| 225 |
+
target_actions = np.stack([
|
| 226 |
+
processor.unapply_actions(value) for value in target_normalized
|
| 227 |
+
]).astype(np.float32)
|
| 228 |
+
for key, value in (
|
| 229 |
+
("predicted_parameters", predicted_parameters),
|
| 230 |
+
("target_parameters", target_parameters),
|
| 231 |
+
("predicted_durations", predicted_durations),
|
| 232 |
+
("target_durations", target_durations),
|
| 233 |
+
("predicted_horizons", predicted_horizons),
|
| 234 |
+
("target_horizons", target_horizons),
|
| 235 |
+
("predicted_actions", predicted_actions),
|
| 236 |
+
("target_actions", target_actions),
|
| 237 |
+
):
|
| 238 |
+
collected[key].append(value)
|
| 239 |
+
if batch_number % 100 == 0 or batch_number == len(loader):
|
| 240 |
+
done = min(batch_number * args.batch_size, len(sample_indices))
|
| 241 |
+
print(f"evaluated {done}/{len(sample_indices)} observations", flush=True)
|
| 242 |
+
|
| 243 |
+
values = {key: np.concatenate(items) for key, items in collected.items()}
|
| 244 |
+
predicted_effective = np.minimum(values["predicted_horizons"], horizon_cap)
|
| 245 |
+
target_effective = np.minimum(values["target_horizons"], horizon_cap)
|
| 246 |
+
steps = np.arange(horizon_cap)[None]
|
| 247 |
+
predicted_valid = steps < predicted_effective[:, None]
|
| 248 |
+
target_valid = steps < target_effective[:, None]
|
| 249 |
+
prediction_raw_valid = predicted_valid & available
|
| 250 |
+
target_raw_valid = target_valid & available
|
| 251 |
+
overlap_valid = predicted_valid & target_valid & available
|
| 252 |
+
|
| 253 |
+
parameter_error = values["predicted_parameters"] - values["target_parameters"]
|
| 254 |
+
duration_error = values["predicted_durations"] - values["target_durations"]
|
| 255 |
+
prediction_vs_raw = values["predicted_actions"] - raw_targets
|
| 256 |
+
representation_vs_raw = values["target_actions"] - raw_targets
|
| 257 |
+
prediction_vs_representation = values["predicted_actions"] - values["target_actions"]
|
| 258 |
+
persistence = np.repeat(raw_targets[:, :1], horizon_cap, axis=1)
|
| 259 |
+
constrained_prediction = constraint.apply(values["predicted_actions"])
|
| 260 |
+
constrained_target = constraint.apply(raw_targets)
|
| 261 |
+
timing = np.asarray(inference_seconds, dtype=np.float64)
|
| 262 |
+
|
| 263 |
+
report = {
|
| 264 |
+
"evaluation": "open_loop_recorded_observations_native_variable_horizon",
|
| 265 |
+
"definition": (
|
| 266 |
+
"Each prediction uses a recorded observation; plans are sampled at native 25 Hz and "
|
| 267 |
+
"masked at sum(first 10 predicted durations), never resampled to a fixed action count."
|
| 268 |
+
),
|
| 269 |
+
"checkpoint": str(checkpoint),
|
| 270 |
+
"seed": args.seed,
|
| 271 |
+
"dataset_observations": total_observations,
|
| 272 |
+
"evaluated_observations": int(len(sample_indices)),
|
| 273 |
+
"episodes": int(len(np.unique(episode_ids))),
|
| 274 |
+
"action_frequency_hz": 25.0,
|
| 275 |
+
"native_horizon_safety_cap": horizon_cap,
|
| 276 |
+
"parameter_shape_per_observation": [13, 8],
|
| 277 |
+
"parameter_layout": "[control_dim_0 ... control_dim_6, duration]",
|
| 278 |
+
"normalized_parameter_prediction": _parameter_metrics(parameter_error),
|
| 279 |
+
"integer_duration_prediction": {
|
| 280 |
+
**_metric_summary(duration_error),
|
| 281 |
+
"exact_accuracy": float(np.mean(duration_error == 0)),
|
| 282 |
+
"predicted_native_horizon": _horizon_summary(values["predicted_horizons"]),
|
| 283 |
+
"target_native_horizon": _horizon_summary(values["target_horizons"]),
|
| 284 |
+
"horizon_mae_steps": float(np.mean(np.abs(
|
| 285 |
+
values["predicted_horizons"] - values["target_horizons"]
|
| 286 |
+
))),
|
| 287 |
+
"predicted_truncation_fraction": float(np.mean(
|
| 288 |
+
values["predicted_horizons"] > horizon_cap
|
| 289 |
+
)),
|
| 290 |
+
"target_truncation_fraction": float(np.mean(
|
| 291 |
+
values["target_horizons"] > horizon_cap
|
| 292 |
+
)),
|
| 293 |
+
},
|
| 294 |
+
"physical_action_prediction_vs_original_target": _trajectory_metrics(
|
| 295 |
+
prediction_vs_raw, prediction_raw_valid
|
| 296 |
+
),
|
| 297 |
+
"physical_action_prediction_vs_spline_target": _trajectory_metrics(
|
| 298 |
+
prediction_vs_representation, overlap_valid
|
| 299 |
+
),
|
| 300 |
+
"spline_representation_vs_original_target": _trajectory_metrics(
|
| 301 |
+
representation_vs_raw, target_raw_valid
|
| 302 |
+
),
|
| 303 |
+
"current_action_persistence_baseline_vs_original_target": _trajectory_metrics(
|
| 304 |
+
persistence - raw_targets, prediction_raw_valid
|
| 305 |
+
),
|
| 306 |
+
"binary_gripper_postprocess_vs_binary_target": _trajectory_metrics(
|
| 307 |
+
constrained_prediction - constrained_target, prediction_raw_valid
|
| 308 |
+
),
|
| 309 |
+
"availability": {
|
| 310 |
+
"unavailable_tail_fraction_of_target_plan": float(np.mean(
|
| 311 |
+
target_valid & ~available
|
| 312 |
+
)),
|
| 313 |
+
"predicted_valid_steps": int(predicted_valid.sum()),
|
| 314 |
+
"target_valid_steps": int(target_valid.sum()),
|
| 315 |
+
"overlap_available_steps": int(overlap_valid.sum()),
|
| 316 |
+
},
|
| 317 |
+
"inference_timing": {
|
| 318 |
+
"batches": int(len(timing)),
|
| 319 |
+
"total_seconds": float(timing.sum()),
|
| 320 |
+
"mean_batch_seconds": float(timing.mean()),
|
| 321 |
+
"mean_observation_seconds_amortized": float(timing.sum() / len(sample_indices)),
|
| 322 |
+
},
|
| 323 |
+
}
|
| 324 |
+
suffix = "all" if len(sample_indices) == total_observations else f"subset_{len(sample_indices)}"
|
| 325 |
+
report_path = output_dir / f"adaptive_open_loop_evaluation_{suffix}.json"
|
| 326 |
+
arrays_path = output_dir / f"adaptive_open_loop_errors_{suffix}.npz"
|
| 327 |
+
report_path.write_text(json.dumps(report, indent=2) + "\n")
|
| 328 |
+
np.savez_compressed(
|
| 329 |
+
arrays_path,
|
| 330 |
+
sample_index=sample_indices,
|
| 331 |
+
episode_index=episode_ids,
|
| 332 |
+
frame_index=frame_ids,
|
| 333 |
+
parameter_error=parameter_error.astype(np.float32),
|
| 334 |
+
predicted_durations=values["predicted_durations"].astype(np.int16),
|
| 335 |
+
target_durations=values["target_durations"].astype(np.int16),
|
| 336 |
+
duration_error=duration_error.astype(np.int16),
|
| 337 |
+
predicted_horizons=values["predicted_horizons"].astype(np.int16),
|
| 338 |
+
target_horizons=values["target_horizons"].astype(np.int16),
|
| 339 |
+
predicted_valid=predicted_valid,
|
| 340 |
+
target_valid=target_valid,
|
| 341 |
+
available=available,
|
| 342 |
+
prediction_vs_spline_error=prediction_vs_representation.astype(np.float32),
|
| 343 |
+
prediction_vs_original_error=prediction_vs_raw.astype(np.float32),
|
| 344 |
+
spline_vs_original_error=representation_vs_raw.astype(np.float32),
|
| 345 |
+
persistence_vs_original_error=(persistence - raw_targets).astype(np.float32),
|
| 346 |
+
constrained_prediction_vs_target_error=(
|
| 347 |
+
constrained_prediction - constrained_target
|
| 348 |
+
).astype(np.float32),
|
| 349 |
+
)
|
| 350 |
+
print(json.dumps({
|
| 351 |
+
"report": str(report_path),
|
| 352 |
+
"arrays": str(arrays_path),
|
| 353 |
+
"evaluated_observations": int(len(sample_indices)),
|
| 354 |
+
"parameter_rmse": report["normalized_parameter_prediction"]["overall"]["rmse"],
|
| 355 |
+
"decoded_vs_original_rmse": report["physical_action_prediction_vs_original_target"]["overall"]["rmse"],
|
| 356 |
+
"decoded_arm_rmse": report["physical_action_prediction_vs_original_target"]["arm"]["rmse"],
|
| 357 |
+
"representation_arm_rmse": report["spline_representation_vs_original_target"]["arm"]["rmse"],
|
| 358 |
+
"predicted_horizon": report["integer_duration_prediction"]["predicted_native_horizon"],
|
| 359 |
+
}, indent=2))
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
if __name__ == "__main__":
|
| 363 |
+
main()
|