"""Fixed image descriptors; no neural model or trained weights.""" import cv2 import numpy as np CAMERAS=('top_camera','front_camera') PATHS=tuple('agent/panda-%d/%s'%(r,p) for r in range(2) for p in ('qpos','qvel')) def image_features(rgb): out=[] for name in CAMERAS: a=np.asarray(rgb[name]) if a.ndim==4 and a.shape[0]==1:a=a[0] if a.ndim!=3 or a.shape[2]!=3 or a.dtype!=np.uint8:raise ValueError('RGB must be uint8 HWC or 1HWC') h,w=a.shape[:2] # Central workspace, retaining robot fingers and tile positions. a=a[int(.22*h):int(.83*h),int(.13*w):int(.87*w)] small=cv2.resize(a,(32,32),interpolation=cv2.INTER_AREA).astype(np.float32)/255. green=np.maximum(small[:,:,1]-(small[:,:,0]+small[:,:,2])/2,0) white=np.maximum(small.min(axis=2)-.55,0) out.extend([small.ravel(),(3*green).ravel(),(2*white).ravel()]) return np.concatenate(out) def proprio_features(p): parts=[] for path in PATHS: a=np.asarray(p[path],dtype=np.float32).reshape(-1) if a.size!=9 or not np.isfinite(a).all():raise ValueError('invalid proprioception') # Physical scales chosen manually, not optimized. scale=np.array([.3]*7+[.02,.02],np.float32) if path.endswith('qpos') else np.array([2.]*9,np.float32) parts.append(a/scale) return np.concatenate(parts)