yuuu94's picture
Add 6k matching source and deployment configuration
b5511a3 verified
Raw History Blame Contribute Delete
2.55 kB
"""Stack bowls boundary. Four RGBs, one predicted-depth graph, joint actions."""
import copy
import numpy as np
CAMERAS = ('cam_third_person', 'cam_high', 'cam_left_wrist', 'cam_right_wrist')
CONTRACT = 'stack_v1_thirdperson_fourrgb_joint14'
def action_chunk(actions, index, horizon=16):
"""Stay inside one episode; hold its last recorded command at the tail."""
actions = np.asarray(actions, np.float32)
if actions.ndim != 2 or actions.shape[1] != 14 or not np.isfinite(actions).all():
raise ValueError('Expected finite joint-space actions [T,14]')
if not 0 <= index < len(actions): raise IndexError(index)
return actions[np.minimum(np.arange(index, index+horizon), len(actions)-1)].copy()
def prepare_example(images, instruction, objects, state, *, episode, step,
prompt_ids, K, action=None, phase=0):
if set(images) != set(CAMERAS): raise ValueError('All four synchronized RGB views required')
state = np.asarray(state, np.float32).reshape(1,14)
if not np.isfinite(state).all(): raise ValueError('Nonfinite state')
if phase not in range(8) or step < 0: raise ValueError('Invalid temporal context')
objects = copy.deepcopy(objects)
h,w = np.asarray(images[CAMERAS[0]]).shape[:2]
for o in objects:
if o.get('image_index',0) != 0: raise ValueError('Only third-person graph permitted')
o['image_index']=0
m=np.asarray(o['visual_mask'],bool)
if m.shape != (h,w): raise ValueError('Mask and third-person RGB must align')
if o.get('depth_source') not in ('da3_estimated','kinematic_tcp'):
raise ValueError('Recorded sensor depth is not permitted in this graph')
ex=dict(image=[images[c] for c in CAMERAS],lang=instruction,state=state,
pilot_objects=objects,graph_contract=CONTRACT,
graph_camera_intrinsics=np.asarray(K,np.float32))
if action is not None:
a=np.asarray(action,np.float32)
if a.shape != (16,14) or not np.isfinite(a).all(): raise ValueError('Action must be [16,14]')
ex['action']=a
ctx=dict(episode_key=str(episode),step=int(step),prompt_ids=list(prompt_ids),
sampling_offset=phase,geometry_generation=0)
return ex,ctx
def normalize(x, stats):
"""Train-split mean/std only; same transform for online proprioception."""
return (np.asarray(x,np.float32)-np.asarray(stats['mean']))/np.maximum(stats['std'],1e-6)
def denormalize(x, stats):
return np.asarray(x)*np.maximum(stats['std'],1e-6)+np.asarray(stats['mean'])