File size: 1,283 Bytes
6a08a28 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | """Check that sub-task samples carry exact masks and that MaskOverlay changes the images."""
import os, sys, argparse, pathlib
import numpy as np
SYT = pathlib.Path(os.environ["SYT"]); sys.path.insert(0, str(SYT / "code/aug")); sys.path.insert(0, str(SYT / "code/runner"))
import run as R
from openpi.training import data_loader as dl
cfg = R.build_config(argparse.Namespace(kind="subtask", repo_id=sys.argv[1]), batch_size=8, num_workers=0)
dc = cfg.data.create(cfg.assets_dirs, cfg.model)
ds = dl.create_torch_dataset(dc, cfg.model.action_horizon, cfg.model)
overlay = dc.repack_transforms.inputs[0]
print("overlay transform:", type(overlay).__name__)
for i in (100, 5000, 20000):
r = ds[i]
print(f"sample {i}: mask keys {[k for k in r if 'mask' in k]} prompt={r.get('prompt')!r}")
before = {k: np.asarray(r[k]).copy() for k in r if k.startswith("observation.images.")}
msum = {k: float(np.asarray(r[k]).astype(np.float32).sum()) for k in r if "mask" in k}
out = overlay(dict(r))
for k, b in before.items():
cam = k.split(".")[-1]
d = np.abs(np.asarray(out[k]).astype(np.float32) - b.astype(np.float32)).mean()
print(f" {cam}: target in exact mask={msum.get('observation.masks.' + cam, 0) > 0} mean|diff| after overlay={d:.3f}")
|