Linslab's picture
Move frozen Astra policies to astra/<task>/ (DualArmHammerHandover-v1 .. DualArmPushBox-v1)
67e0b67 verified
Raw History Blame Contribute Delete
1.74 kB
"""Offline authorized demonstration indexing only; no fitting or simulator."""
import json, h5py, numpy as np
from pathlib import Path
from controller import visual_features, CAMERAS, QPATHS, VPATHS
root=Path(__file__).parent
manifest=json.load(open('/demo_manifest.json'))
rows={k:[] for k in ('q','v','features','actions','phase','demo','frame')}
access=[]
for di,e in enumerate(manifest['episodes']):
n=e['length']
indices=sorted(set(range(0,n,4))|{n-1})
with h5py.File('/demonstrations/'+e['file'],'r') as h:
q=np.concatenate([h['obs/'+k][:] for k in QPATHS],1)
v=np.concatenate([h['obs/'+k][:] for k in VPATHS],1)
a=np.concatenate([h['actions/panda_leaphand-'+str(r)][:] for r in range(2)],1)
cache_start = -1
for t in indices:
start = (t // 98) * 98
if start != cache_start:
cache = {c:h['obs/sensor_data/'+c+'/rgb'][start:min(start+98,n)] for c in CAMERAS}
cache_start = start
rgb={c:cache[c][t-cache_start] for c in CAMERAS}
rows['features'].append(visual_features(rgb))
rows['q'].append(q[t]);rows['v'].append(v[t]);rows['actions'].append(a[t])
rows['phase'].append(t);rows['demo'].append(di);rows['frame'].append(t)
access.append({'demo_id':e['demo_id'],'machine_feature_frames':indices,'cameras':list(CAMERAS),'all_action_indices':[0,n-1],'all_proprio_indices':[0,n]})
print(e['demo_id'],len(indices),flush=True)
np.savez_compressed(root/'memory.npz',**{k:np.asarray(v,dtype=np.int32 if k in ('demo','frame') else np.float32) for k,v in rows.items()})
json.dump(access,open('/workspace/evidence/machine_access.json','w'),indent=2)
print('rows',len(rows['q']))