Download model/common/slice.py from ducido/diffusion_policy_gbc: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/ducido/diffusion_policy_gbc/resolve/main/model/common/slice.py
- Command line
-
hf download hf://ducido/diffusion_policy_gbc/model/common/slice.py
-
curl -L -o slice.py https://huggingface.co/ducido/diffusion_policy_gbc/resolve/main/model/common/slice.py
1.22 kB
| import torch | |
| import numpy as np | |
| def slice_episode(episode, horizon, stride, start=0): | |
| is_torch = hasattr(episode, 'cuda') | |
| shape = episode.shape | |
| N, T = shape[:2] | |
| sliced_fragments = [] | |
| for current_start in range(start, T, stride): | |
| end = current_start + horizon | |
| if end > T: | |
| current_start = max(0, T - horizon) | |
| end = T | |
| fragment = episode[:, current_start:end, ...] | |
| sliced_fragments.append(fragment) | |
| if end == T: | |
| break | |
| if is_torch: | |
| return torch.stack(sliced_fragments) | |
| else: | |
| return np.stack(sliced_fragments) | |
| def slice_episode_time(episode, horizon, stride): | |
| is_torch = hasattr(episode, 'cuda') | |
| shape = episode.shape | |
| T = shape[0] | |
| sliced_fragments = [] | |
| for start in range(0, T, stride): | |
| end = start + horizon | |
| if end > T: | |
| start = max(0, T - horizon) | |
| end = T | |
| fragment = episode[start:end, ...] | |
| sliced_fragments.append(fragment) | |
| if end == T: | |
| break | |
| if is_torch: | |
| return torch.stack(sliced_fragments) | |
| else: | |
| return np.stack(sliced_fragments) |