Download scripts/_stub_openpi/openpi/transforms.py from simpk/single_pickplace: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/datasets/simpk/single_pickplace/resolve/main/scripts/_stub_openpi/openpi/transforms.py
- Command line
-
hf download hf://datasets/simpk/single_pickplace/scripts/_stub_openpi/openpi/transforms.py
-
curl -L -o transforms.py https://huggingface.co/datasets/simpk/single_pickplace/resolve/main/scripts/_stub_openpi/openpi/transforms.py
1.47 kB
| """Faithful minimal stand-ins for the openpi transforms used by g1_dex3_policy.""" | |
| import dataclasses | |
| from typing import Sequence | |
| import numpy as np | |
| class DataTransformFn: | |
| pass | |
| def pad_to_dim(x, target_dim, axis=-1): | |
| current = x.shape[axis] | |
| if current >= target_dim: return x | |
| pad = [(0,0)]*x.ndim | |
| pad[axis]=(0, target_dim-current) | |
| return np.pad(x, pad) | |
| def make_bool_mask(*dims): | |
| out=[] | |
| for d in dims: | |
| out.extend([True]*d if d>0 else [False]*(-d)) | |
| return tuple(out) | |
| class DeltaActions(DataTransformFn): | |
| mask: Sequence[bool] | None | |
| def __call__(self, data): | |
| if "actions" not in data or self.mask is None: return data | |
| state, actions = data["state"], np.array(data["actions"]) | |
| mask = np.asarray(self.mask); dims = mask.shape[-1] | |
| actions[..., :dims] = np.where(mask, actions[..., :dims]-state[..., :dims], actions[..., :dims]) | |
| data["actions"]=actions; return data | |
| class AbsoluteActions(DataTransformFn): | |
| mask: Sequence[bool] | None | |
| def __call__(self, data): | |
| if "actions" not in data or self.mask is None: return data | |
| state, actions = data["state"], np.array(data["actions"]) | |
| mask = np.asarray(self.mask); dims = mask.shape[-1] | |
| actions[..., :dims] = np.where(mask, actions[..., :dims]+state[..., :dims], actions[..., :dims]) | |
| data["actions"]=actions; return data | |