Download fair-comparison/flow-v1/code/lim/chunk_phase.py from OpenGHz/keypose-vs-dense: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/datasets/OpenGHz/keypose-vs-dense/resolve/main/fair-comparison/flow-v1/code/lim/chunk_phase.py
- Command line
-
hf download hf://datasets/OpenGHz/keypose-vs-dense/fair-comparison/flow-v1/code/lim/chunk_phase.py
-
curl -L -o chunk_phase.py https://huggingface.co/datasets/OpenGHz/keypose-vs-dense/resolve/main/fair-comparison/flow-v1/code/lim/chunk_phase.py
1.22 kB
| """Predicted primitive boundaries in fixed-anchor action chunks, without an FSM.""" | |
| import torch | |
| def phase_prefix(phases): | |
| """Count the first constant-label run; no observed change means horizon, not arrival.""" | |
| phases = torch.as_tensor(phases) | |
| if ( | |
| phases.ndim != 1 | |
| or len(phases) != 30 | |
| or not ((phases >= 0) & (phases < 6)).all() | |
| ): | |
| raise ValueError("Expected 30 predicted primitive indices in [0, 5]") | |
| changes = torch.nonzero(phases != phases[0]).flatten() | |
| return int(changes[0]) if len(changes) else 30 | |
| def chunk_selection(logits, mode): | |
| if logits.shape != (30, 6) or not torch.isfinite(logits).all(): | |
| raise ValueError("Expected finite prior logits with shape 30 x 6") | |
| if mode not in ("full", "boundary", "endpoint"): | |
| raise ValueError("Unknown phase chunk execution mode") | |
| labels = logits.argmax(-1) | |
| prefix = phase_prefix(labels) | |
| return { | |
| "phase_labels": labels.tolist(), | |
| "phase_prefix_length": prefix, | |
| "boundary_kind": "phase_change" if prefix < 30 else "horizon", | |
| "consume_length": 30 if mode == "full" else prefix, | |
| "selected_index": (30 if mode == "full" else prefix) - 1, | |
| } | |