Linslab's picture
Move frozen Astra policies to astra/<task>/ (BuildTent-v1 .. DualArmFoldHandKerchief-v1)
592ea41 verified
Raw History Blame Contribute Delete
1.27 kB
"""Fixed, non-neural descriptors of legal observations."""
import cv2
import numpy as np
CAMERAS = ('top_camera', 'front_camera')
PATHS = tuple(f'agent/panda-{i}/{s}' for i in range(2) for s in ('qpos','qvel'))
def image_feature(value):
a = np.asarray(value)
if a.ndim == 4 and a.shape[0] == 1: a = a[0]
if a.ndim != 3 or a.shape[2] != 3: raise ValueError('Expected RGB HWC or 1HWC')
if not np.isfinite(a).all(): raise ValueError('Nonfinite RGB')
small = cv2.resize(a.astype(np.float32)/255., (24,32), interpolation=cv2.INTER_AREA)
# Cyan boundary pixels are thin; pooling preserves their location.
x=a.astype(np.float32)/255.
cyan=((x[:,:,1]-x[:,:,0]>.10)&(x[:,:,2]-x[:,:,0]>.10)).astype(np.float32)
cyan=cv2.resize(cyan,(24,32),interpolation=cv2.INTER_AREA)
return np.concatenate([small.reshape(-1), 4*cyan.reshape(-1)]).astype(np.float32)
def proprio_feature(obs):
out=[]
for p in PATHS:
x=np.asarray(obs['proprioception'][p],dtype=np.float32).reshape(-1)
if x.size!=9 or not np.isfinite(x).all(): raise ValueError('Invalid proprioception')
scale=np.array([.35]*7+[.025]*2) if p.endswith('qpos') else np.array([2.]*7+[.2]*2)
out.extend(x/scale)
return np.asarray(out,dtype=np.float32)