Download astra/ClothWipe-v1/build_reference.py from Linslab/ManiLadder_Models: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/Linslab/ManiLadder_Models/resolve/main/astra/ClothWipe-v1/build_reference.py
- Command line
-
hf download hf://Linslab/ManiLadder_Models/astra/ClothWipe-v1/build_reference.py
-
curl -L -o build_reference.py https://huggingface.co/Linslab/ManiLadder_Models/resolve/main/astra/ClothWipe-v1/build_reference.py
2.42 kB
| """Compile legal demonstration observations/labels; no parameter optimization.""" | |
| import importlib.util | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| from controller import image_feature, CAMERAS | |
| spec=importlib.util.spec_from_file_location('worker_api','/worker_api.py') | |
| m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m) | |
| api=m.API();manifest=json.loads(Path('/demo_manifest.json').read_text()) | |
| assert len(manifest['episodes'])==20 | |
| rows={k:[] for k in ['q','v','visual','actions','phase','phase_rate','demo_index','frame_index']} | |
| index=[] | |
| for di,e in enumerate(manifest['episodes']): | |
| d=api.read_demo(e['demo_id'],fields=['actions','obs/agent/qpos','obs/agent/qvel']) | |
| a=d['actions'];n=len(a) | |
| changes=np.flatnonzero(np.any(np.abs(np.diff(a[:,6:],axis=0))>.05,axis=1))+1 | |
| assert len(changes)==6 | |
| bounds=np.r_[0,changes,n] | |
| ids=sorted(set(range(0,n,2)) | set(changes.tolist()) | set((changes-1).tolist()) | {n-1}) | |
| # Read RGB in modest chunks through the authorized API, not service RPCs. | |
| for start in range(0,n,64): | |
| stop=min(n,start+64) | |
| rgb=api.read_demo(e['demo_id'],start,stop,fields=['obs/sensor_data/'+c+'/rgb' for c in CAMERAS]) | |
| for t in ids: | |
| if not start<=t<stop:continue | |
| seg=min(6,np.searchsorted(bounds,t,side='right')-1) | |
| duration=bounds[seg+1]-bounds[seg] | |
| vals={'q':d['obs/agent/qpos'][t],'v':d['obs/agent/qvel'][t], | |
| 'visual':image_feature({c:rgb['obs/sensor_data/'+c+'/rgb'][t-start] for c in CAMERAS}), | |
| 'actions':a[t],'phase':seg+(t-bounds[seg])/duration,'phase_rate':1/duration, | |
| 'demo_index':di,'frame_index':t} | |
| for k,val in vals.items():rows[k].append(val) | |
| index.append({'demo_id':e['demo_id'],'numerical_actions':[0,n-1], | |
| 'numerical_proprioception':[0,n], 'rgb_feature_indices':ids, | |
| 'rgb_read_intervals':[[i,min(n,i+64)] for i in range(0,n,64)], | |
| 'cameras':list(CAMERAS),'phase_boundaries':bounds.tolist()}) | |
| print(e['demo_id'],len(ids),'references',flush=True) | |
| arrays={k:np.asarray(v,dtype=np.int32 if k.endswith('index') else np.float32) for k,v in rows.items()} | |
| arrays['q_scale']=np.maximum(arrays['q'].std(0),.12) | |
| arrays['v_scale']=np.maximum(arrays['v'].std(0),.2) | |
| np.savez_compressed(Path(__file__).with_name('reference_bank.npz'),**arrays) | |
| Path('/workspace/evidence/computational_access.json').write_text(json.dumps(index,indent=2)) | |
| print('Total references',len(arrays['q'])) | |