Download astra/DualArmClothAlign-v1/features.py from Linslab/ManiLadder_Models: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/Linslab/ManiLadder_Models/resolve/main/astra/DualArmClothAlign-v1/features.py
- Command line
-
hf download hf://Linslab/ManiLadder_Models/astra/DualArmClothAlign-v1/features.py
-
curl -L -o features.py https://huggingface.co/Linslab/ManiLadder_Models/resolve/main/astra/DualArmClothAlign-v1/features.py
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) | |