Update public VPB evaluator and VLAC-Cut evaluation docs
Browse files- README.md +41 -0
- docs/vpb_public_evaluation.md +268 -0
- scripts/build_vpb_inference_manifest.py +303 -0
- scripts/evaluate_vpb_predictions.py +1276 -0
- scripts/upload_vlac2_release_archives_to_hf.sbatch +159 -0
- scripts/vlac2_release_common.py +6 -7
- scripts/vpb_public_eval_utils.py +366 -0
README.md
CHANGED
|
@@ -25,6 +25,14 @@ benchmark_splits/
|
|
| 25 |
scripts/
|
| 26 |
unpack_data.sh
|
| 27 |
extract_vlac2_release_frames.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
data/
|
| 30 |
train_videos.tar
|
|
@@ -69,6 +77,39 @@ __VLAC2_FRAMES_ROOT__/
|
|
| 69 |
|
| 70 |
Replace `__VLAC2_FRAMES_ROOT__` with the absolute path to the extracted-frame directory. For example, `__VLAC2_FRAMES_ROOT__/...` should be resolved as `/path/to/data_extracted_frames/...`.
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
## Notes
|
| 73 |
|
| 74 |
* This repository contains only the raw videos required by the released benchmark splits.
|
|
|
|
| 25 |
scripts/
|
| 26 |
unpack_data.sh
|
| 27 |
extract_vlac2_release_frames.py
|
| 28 |
+
build_vpb_inference_manifest.py
|
| 29 |
+
evaluate_vpb_predictions.py
|
| 30 |
+
vlac2_release_common.py
|
| 31 |
+
vpb_public_eval_utils.py
|
| 32 |
+
upload_vlac2_release_archives_to_hf.sbatch
|
| 33 |
+
|
| 34 |
+
docs/
|
| 35 |
+
vpb_public_evaluation.md
|
| 36 |
|
| 37 |
data/
|
| 38 |
train_videos.tar
|
|
|
|
| 77 |
|
| 78 |
Replace `__VLAC2_FRAMES_ROOT__` with the absolute path to the extracted-frame directory. For example, `__VLAC2_FRAMES_ROOT__/...` should be resolved as `/path/to/data_extracted_frames/...`.
|
| 79 |
|
| 80 |
+
### 4. Build an inference manifest
|
| 81 |
+
|
| 82 |
+
```bash
|
| 83 |
+
python scripts/build_vpb_inference_manifest.py \
|
| 84 |
+
--benchmark-root benchmark_splits \
|
| 85 |
+
--frames-root /path/to/data_extracted_frames \
|
| 86 |
+
--out manifests/vpb_test_1hz.jsonl
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
The default manifest uses 2Hz video input frames and also records the public 1Hz evaluation frames from the main view of each trajectory. This keeps model inference aligned with the VLAC-Cut input protocol while keeping evaluation aligned with the formal 1Hz benchmark protocol.
|
| 90 |
+
|
| 91 |
+
For trajectory-level VLAC-Cut predictions, keep the manifest's 2Hz `frames` list in each prediction row. The evaluator maps predictions by original frame id and scores only the public 1Hz `eval_frames` for global progress and terminal metrics.
|
| 92 |
+
|
| 93 |
+
By default, each manifest row is one trajectory with a list of sampled frame paths for video-model inference. For frame-level models, add `--record-format point`.
|
| 94 |
+
|
| 95 |
+
### 5. Evaluate predictions
|
| 96 |
+
|
| 97 |
+
```bash
|
| 98 |
+
python scripts/evaluate_vpb_predictions.py \
|
| 99 |
+
--benchmark-root benchmark_splits \
|
| 100 |
+
--predictions predictions.jsonl \
|
| 101 |
+
--out-json reports/vpb_eval.json \
|
| 102 |
+
--out-md reports/vpb_eval.md
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
The evaluator reports global progress metrics, terminal success metrics, local direction AP on adjacent semantic anchors, and local keypoint progress metrics. Global and local-keypoint progress are shown for the 4-bucket overall split and each bucket; terminal metrics are shown for 4-bucket overall, seen merged, and unseen merged. See `docs/vpb_public_evaluation.md` for the accepted prediction schema and metric definitions.
|
| 106 |
+
|
| 107 |
+
### 6. Evaluate VLAC-Cut
|
| 108 |
+
|
| 109 |
+
VLAC-Cut is released separately at <https://huggingface.co/InternRobotics/VLAC-Cut>. This benchmark release does not vendor model weights or a VLAC-Cut batch inference runner; it only defines the benchmark frames, prediction schema, and evaluator.
|
| 110 |
+
|
| 111 |
+
For strict VLAC-Cut evaluation, run the model on the 2Hz `image_paths` from the trajectory manifest instead of re-sampling the full raw video. Write one prediction row per trajectory with `global_episode_id`, `frames`, and either the raw VLAC-Cut `response` or an aligned `pred_progress_sequence`, then run `evaluate_vpb_predictions.py` as above. The evaluator parses VLAC-style keypoint responses, reconstructs the prediction curve, and reports the same public benchmark sections: global progress, terminal success, local direction AP, and local keypoint progress. The exact adapter contract is documented in `docs/vpb_public_evaluation.md`.
|
| 112 |
+
|
| 113 |
## Notes
|
| 114 |
|
| 115 |
* This repository contains only the raw videos required by the released benchmark splits.
|
docs/vpb_public_evaluation.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Public Video-Progress Benchmark Evaluation
|
| 2 |
+
|
| 3 |
+
This release evaluates model progress predictions from the public benchmark files only.
|
| 4 |
+
It does not require any private workspace paths or private metric code.
|
| 5 |
+
|
| 6 |
+
## Protocol
|
| 7 |
+
|
| 8 |
+
The default public protocol uses 2Hz video input for model inference, then
|
| 9 |
+
evaluates predictions on the 1Hz formal evaluation points reconstructed from
|
| 10 |
+
each released dense video timeline:
|
| 11 |
+
|
| 12 |
+
- split scope: `test_expert_seen`, `test_expert_unseen`, `test_nonexpert_seen`, `test_nonexpert_unseen`
|
| 13 |
+
- view scope: the `metadata.main_path` view only
|
| 14 |
+
- video input points: `--input-sample-hz 2.0`
|
| 15 |
+
- evaluation points: `--eval-points time_hz --sample-hz 1.0`
|
| 16 |
+
- global progress metrics: `MAE`, `PRC`, and `VOC` for expert bucket rows
|
| 17 |
+
- terminal metrics: final progress threshold `90%`
|
| 18 |
+
- local direction metrics: `AP+`, `AP-`, and `MacroAP_D` on adjacent `semantic_anchors` with `tau=0`
|
| 19 |
+
- local keypoint progress metrics: `MAE`, `PRC`, and `VOC` for expert bucket rows on `semantic_anchors`
|
| 20 |
+
|
| 21 |
+
The released JSON files also contain dense frame-level progress. Use
|
| 22 |
+
`--eval-points dense` only for diagnostics; it is not the paper-comparable default.
|
| 23 |
+
|
| 24 |
+
## End-to-End Workflow
|
| 25 |
+
|
| 26 |
+
Unpack videos:
|
| 27 |
+
|
| 28 |
+
```bash
|
| 29 |
+
bash scripts/unpack_data.sh /path/to/data
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
Extract frames:
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
python scripts/extract_vlac2_release_frames.py \
|
| 36 |
+
--data-root /path/to/data \
|
| 37 |
+
--frames-root /path/to/frames
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
Build a 2Hz-input / 1Hz-evaluation inference manifest:
|
| 41 |
+
|
| 42 |
+
```bash
|
| 43 |
+
python scripts/build_vpb_inference_manifest.py \
|
| 44 |
+
--benchmark-root benchmark_splits \
|
| 45 |
+
--frames-root /path/to/frames \
|
| 46 |
+
--out manifests/vpb_test_1hz.jsonl
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
By default, the manifest is trajectory-level: each row contains `frames`,
|
| 50 |
+
`timestamps_sec`, and `image_paths` lists for one 2Hz video trajectory. The row
|
| 51 |
+
also contains `eval_frames` and `eval_timestamps_sec`, which define the 1Hz
|
| 52 |
+
frames used by the evaluator. For frame-level models, add `--record-format point`
|
| 53 |
+
to emit one row per 1Hz evaluation frame.
|
| 54 |
+
|
| 55 |
+
### 2Hz input and 1Hz evaluation mapping
|
| 56 |
+
|
| 57 |
+
The public benchmark GT is evaluated at 1Hz, but VLAC-Cut is run with 2Hz video
|
| 58 |
+
input. The release keeps these two frame sets explicit:
|
| 59 |
+
|
| 60 |
+
- `frames` / `input_frames`: the 2Hz frames passed to the video model.
|
| 61 |
+
- `image_paths` / `input_image_paths`: the frame images corresponding to those
|
| 62 |
+
2Hz frames.
|
| 63 |
+
- `eval_frames`: the 1Hz frames used for global progress and terminal metrics.
|
| 64 |
+
|
| 65 |
+
For the default protocol, `eval_frames` are a subset of `input_frames`. A
|
| 66 |
+
VLAC-Cut prediction row should therefore write the same 2Hz `frames` list used
|
| 67 |
+
for inference, together with either the raw `response` or a
|
| 68 |
+
`pred_progress_sequence` aligned to that list. The evaluator stores predictions
|
| 69 |
+
by original frame id. When computing the 1Hz metrics, it compares only the
|
| 70 |
+
predictions at the 1Hz `eval_frames` against the released
|
| 71 |
+
`dense_kinematic_progress` GT.
|
| 72 |
+
|
| 73 |
+
Run your model on the manifest and write predictions as JSONL. The canonical
|
| 74 |
+
episode-level format is:
|
| 75 |
+
|
| 76 |
+
```json
|
| 77 |
+
{
|
| 78 |
+
"global_episode_id": "ARX-data/.../episode_000000",
|
| 79 |
+
"pred_progress_by_frame": {
|
| 80 |
+
"0": 0.0,
|
| 81 |
+
"30": 12.5,
|
| 82 |
+
"60": 28.0
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
The point-level format is also accepted:
|
| 88 |
+
|
| 89 |
+
```json
|
| 90 |
+
{
|
| 91 |
+
"global_episode_id": "ARX-data/.../episode_000000",
|
| 92 |
+
"frame": 30,
|
| 93 |
+
"pred_progress": 12.5
|
| 94 |
+
}
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
If your inference output is a sequence aligned with the trajectory manifest,
|
| 98 |
+
include the frame list so the evaluator can map 2Hz predictions back to frame ids:
|
| 99 |
+
|
| 100 |
+
```json
|
| 101 |
+
{
|
| 102 |
+
"global_episode_id": "ARX-data/.../episode_000000",
|
| 103 |
+
"frames": [0, 15, 30, 45, 60],
|
| 104 |
+
"pred_progress_sequence": [0.0, 5.0, 12.5, 20.0, 28.0]
|
| 105 |
+
}
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
For VLAC-style keypoint responses, the evaluator also accepts the raw response
|
| 109 |
+
or parsed keypoints and applies the same index-normalized curve alignment as the
|
| 110 |
+
formal VLAC evaluation code:
|
| 111 |
+
|
| 112 |
+
```json
|
| 113 |
+
{
|
| 114 |
+
"global_episode_id": "ARX-data/.../episode_000000",
|
| 115 |
+
"frames": [0, 15, 30, 45, 60],
|
| 116 |
+
"response": "时间: 0.5s, 进度: 0%\n时间: 2.0s, 进度: 30%"
|
| 117 |
+
}
|
| 118 |
+
```
|
| 119 |
+
|
| 120 |
+
In the released benchmark, the default 1Hz evaluation frames are a subset of the
|
| 121 |
+
default 2Hz input frames, so the evaluator can take the 1Hz subset directly from
|
| 122 |
+
2Hz frame-level predictions. Use `--interpolate-missing` only for sparse outputs
|
| 123 |
+
that do not contain the 1Hz frame ids.
|
| 124 |
+
|
| 125 |
+
Evaluate:
|
| 126 |
+
|
| 127 |
+
```bash
|
| 128 |
+
python scripts/evaluate_vpb_predictions.py \
|
| 129 |
+
--benchmark-root benchmark_splits \
|
| 130 |
+
--predictions predictions.jsonl \
|
| 131 |
+
--out-json reports/vpb_eval.json \
|
| 132 |
+
--out-md reports/vpb_eval.md
|
| 133 |
+
```
|
| 134 |
+
|
| 135 |
+
## Evaluating VLAC-Cut
|
| 136 |
+
|
| 137 |
+
The VLAC-Cut model release is hosted separately at
|
| 138 |
+
<https://huggingface.co/InternRobotics/VLAC-Cut>. The benchmark release does
|
| 139 |
+
not vendor model weights or a separate VLAC-Cut batch inference runner. Use the
|
| 140 |
+
model release to produce a prediction JSONL in the evaluator schema above.
|
| 141 |
+
|
| 142 |
+
For the strict benchmark setting, do not run the model quick-start directly on
|
| 143 |
+
the full raw video and let it re-sample from frame `0`. Instead, read the
|
| 144 |
+
trajectory manifest produced by `build_vpb_inference_manifest.py` and feed the
|
| 145 |
+
listed 2Hz `image_paths` to VLAC-Cut as the video frames. This preserves the
|
| 146 |
+
benchmark `start_idx`, main-view selection, and 2Hz input protocol.
|
| 147 |
+
|
| 148 |
+
A minimal VLAC-Cut adapter should do only this:
|
| 149 |
+
|
| 150 |
+
1. Read each trajectory row from `manifests/vpb_test_1hz.jsonl`.
|
| 151 |
+
2. Build the same `chunk_all` prompt from `task_instruction` and
|
| 152 |
+
`task_description`.
|
| 153 |
+
3. Run VLAC-Cut on `image_paths` with the frame list order unchanged.
|
| 154 |
+
4. Write one prediction row per trajectory with the raw response:
|
| 155 |
+
|
| 156 |
+
```json
|
| 157 |
+
{
|
| 158 |
+
"global_episode_id": "ARX-data/.../episode_000000",
|
| 159 |
+
"frames": [0, 15, 30, 45, 60],
|
| 160 |
+
"response": "时间: 0.5s, 进度: 0%\n时间: 2.0s, 进度: 30%"
|
| 161 |
+
}
|
| 162 |
+
```
|
| 163 |
+
|
| 164 |
+
The evaluator parses the keypoints, aligns them to the 2Hz frame list using the
|
| 165 |
+
formal VLAC index-normalized alignment rule, and then takes the 1Hz subset from
|
| 166 |
+
the aligned 2Hz predictions:
|
| 167 |
+
|
| 168 |
+
```bash
|
| 169 |
+
python scripts/evaluate_vpb_predictions.py \
|
| 170 |
+
--benchmark-root benchmark_splits \
|
| 171 |
+
--predictions vlac_cut_predictions.jsonl \
|
| 172 |
+
--out-json reports/vlac_cut_vpb_eval.json \
|
| 173 |
+
--out-md reports/vlac_cut_vpb_eval.md
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
This keeps the pipeline simple: the benchmark release defines the frames,
|
| 177 |
+
prediction schema, evaluator, and metrics; the VLAC-Cut model release is
|
| 178 |
+
responsible only for inference. The resulting benchmark report includes global
|
| 179 |
+
progress, terminal success, local direction AP, local keypoint progress, and
|
| 180 |
+
prediction diagnostics.
|
| 181 |
+
|
| 182 |
+
## Metrics
|
| 183 |
+
|
| 184 |
+
### Global Progress
|
| 185 |
+
|
| 186 |
+
For each trajectory, the evaluator compares predictions against the released
|
| 187 |
+
`dense_kinematic_progress` values at the selected 1Hz frames.
|
| 188 |
+
|
| 189 |
+
- `MAE`: mean absolute error over valid points in one trajectory, then averaged equally over trajectories.
|
| 190 |
+
- `PRC`: Spearman correlation between GT progress and predicted progress in one trajectory, then averaged equally over valid trajectories.
|
| 191 |
+
- `VOC`: Spearman correlation between predicted progress and chronological frame order in one trajectory, then averaged equally over valid expert-bucket trajectories.
|
| 192 |
+
|
| 193 |
+
The report shows 4-bucket overall and four per-bucket rows. VOC is omitted for
|
| 194 |
+
the 4-bucket overall and non-expert bucket rows.
|
| 195 |
+
|
| 196 |
+
### Terminal Success
|
| 197 |
+
|
| 198 |
+
Terminal success uses the last selected evaluation frame:
|
| 199 |
+
|
| 200 |
+
- GT success: final GT progress `>= 90`
|
| 201 |
+
- predicted success: final predicted progress `>= 90`
|
| 202 |
+
- reported metrics: `TSA`, `F1_S`, `F1_F`, `MacroF1_T`, and `TP/FN/FP/TN`
|
| 203 |
+
|
| 204 |
+
The report shows 4-bucket overall, seen merged, and unseen merged rows.
|
| 205 |
+
|
| 206 |
+
### Local Direction AP
|
| 207 |
+
|
| 208 |
+
Local direction is computed on adjacent released `semantic_anchors`. For each
|
| 209 |
+
transition:
|
| 210 |
+
|
| 211 |
+
```text
|
| 212 |
+
Delta_gt = gt_anchor_progress_end - gt_anchor_progress_start
|
| 213 |
+
Delta_pred = pred_progress_end - pred_progress_start
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
Prediction values at anchor frames are obtained by linear interpolation over the
|
| 217 |
+
model's valid predicted curve. The formal public report uses `tau=0`:
|
| 218 |
+
|
| 219 |
+
```text
|
| 220 |
+
AP+ = AP(y = 1[Delta_gt > 0], score = Delta_pred)
|
| 221 |
+
AP- = AP(y = 1[Delta_gt < 0], score = -Delta_pred)
|
| 222 |
+
MacroAP_D = (AP+ + AP-) / 2
|
| 223 |
+
```
|
| 224 |
+
|
| 225 |
+
Stagnation transitions are negatives inside each AP ranking, but are not
|
| 226 |
+
averaged as a separate third AP class. The report shows 4-bucket overall, seen
|
| 227 |
+
merged, and unseen merged rows.
|
| 228 |
+
|
| 229 |
+
### Local Keypoint Progress
|
| 230 |
+
|
| 231 |
+
Local keypoint progress evaluates predictions at all released
|
| 232 |
+
`semantic_anchors`. Prediction values at anchor frames are obtained by linear
|
| 233 |
+
interpolation over the model's valid predicted curve.
|
| 234 |
+
|
| 235 |
+
- `MAE`: trajectory-equal mean absolute error over semantic-anchor keypoints.
|
| 236 |
+
- `PRC`: trajectory-equal Spearman correlation between anchor GT progress and predicted anchor progress.
|
| 237 |
+
- `VOC`: trajectory-equal Spearman correlation between predicted anchor progress and chronological anchor order for expert bucket rows.
|
| 238 |
+
|
| 239 |
+
The report shows 4-bucket overall and four per-bucket rows. VOC is omitted for
|
| 240 |
+
the 4-bucket overall and non-expert bucket rows.
|
| 241 |
+
|
| 242 |
+
Missing predictions are not silently filled in strict mode. The report includes
|
| 243 |
+
coverage, missing final counts, duplicate prediction counts, unknown episode ids,
|
| 244 |
+
and counts for predictions outside the nominal `[0, 100]` range. Those nominal
|
| 245 |
+
range counts are diagnostics only; predictions are not clipped unless
|
| 246 |
+
`--clip-pred` is set.
|
| 247 |
+
|
| 248 |
+
Use `--interpolate-missing` only when evaluating sparse model outputs that do
|
| 249 |
+
not include the 1Hz evaluation frame ids. Reports generated with interpolation
|
| 250 |
+
are not strict paper-comparable outputs.
|
| 251 |
+
|
| 252 |
+
## Quick Checks
|
| 253 |
+
|
| 254 |
+
Run the evaluator self-test:
|
| 255 |
+
|
| 256 |
+
```bash
|
| 257 |
+
python scripts/evaluate_vpb_predictions.py --self-test
|
| 258 |
+
```
|
| 259 |
+
|
| 260 |
+
Build a small smoke-test manifest:
|
| 261 |
+
|
| 262 |
+
```bash
|
| 263 |
+
python scripts/build_vpb_inference_manifest.py \
|
| 264 |
+
--benchmark-root benchmark_splits \
|
| 265 |
+
--frames-root /path/to/frames \
|
| 266 |
+
--out /tmp/vpb_manifest_smoke.jsonl \
|
| 267 |
+
--limit-trajectories 2
|
| 268 |
+
```
|
scripts/build_vpb_inference_manifest.py
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import math
|
| 7 |
+
import sys
|
| 8 |
+
from collections import Counter
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
SCRIPT_DIR = Path(__file__).resolve().parent
|
| 13 |
+
if str(SCRIPT_DIR) not in sys.path:
|
| 14 |
+
sys.path.insert(0, str(SCRIPT_DIR))
|
| 15 |
+
|
| 16 |
+
from vlac2_release_common import absolute_frame_path_from_any
|
| 17 |
+
from vpb_public_eval_utils import (
|
| 18 |
+
TEST_BUCKETS,
|
| 19 |
+
iter_benchmark_rows,
|
| 20 |
+
main_view_for_row,
|
| 21 |
+
selected_frames_for_row,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def parse_args() -> argparse.Namespace:
|
| 26 |
+
release_root = SCRIPT_DIR.parent
|
| 27 |
+
parser = argparse.ArgumentParser(
|
| 28 |
+
description="Build a public Video-Progress Benchmark inference manifest."
|
| 29 |
+
)
|
| 30 |
+
parser.add_argument(
|
| 31 |
+
"--benchmark-root",
|
| 32 |
+
type=Path,
|
| 33 |
+
default=release_root / "benchmark_splits",
|
| 34 |
+
help="Directory containing the benchmark split folders.",
|
| 35 |
+
)
|
| 36 |
+
parser.add_argument(
|
| 37 |
+
"--frames-root",
|
| 38 |
+
type=Path,
|
| 39 |
+
default=release_root / "_extracted_frames",
|
| 40 |
+
help="Root directory produced by extract_vlac2_release_frames.py.",
|
| 41 |
+
)
|
| 42 |
+
parser.add_argument("--out", type=Path, required=True, help="Output JSONL manifest path.")
|
| 43 |
+
parser.add_argument(
|
| 44 |
+
"--record-format",
|
| 45 |
+
choices=["trajectory", "point"],
|
| 46 |
+
default="trajectory",
|
| 47 |
+
help="Manifest row format. Use trajectory for video models and point for frame-level models.",
|
| 48 |
+
)
|
| 49 |
+
parser.add_argument(
|
| 50 |
+
"--buckets",
|
| 51 |
+
nargs="+",
|
| 52 |
+
default=list(TEST_BUCKETS),
|
| 53 |
+
choices=list(TEST_BUCKETS),
|
| 54 |
+
help="Benchmark buckets to include.",
|
| 55 |
+
)
|
| 56 |
+
parser.add_argument(
|
| 57 |
+
"--eval-points",
|
| 58 |
+
choices=["time_hz", "dense", "semantic_anchors"],
|
| 59 |
+
default="time_hz",
|
| 60 |
+
help="Evaluation frame points. Default time_hz with --sample-hz 1.0 matches the public 1Hz evaluation protocol.",
|
| 61 |
+
)
|
| 62 |
+
parser.add_argument(
|
| 63 |
+
"--sample-hz",
|
| 64 |
+
type=float,
|
| 65 |
+
default=1.0,
|
| 66 |
+
help="Evaluation sampling rate used when --eval-points=time_hz.",
|
| 67 |
+
)
|
| 68 |
+
parser.add_argument(
|
| 69 |
+
"--input-sample-hz",
|
| 70 |
+
type=float,
|
| 71 |
+
default=2.0,
|
| 72 |
+
help="Trajectory-level video input sampling rate. The default matches the VLAC-Cut 2Hz input protocol.",
|
| 73 |
+
)
|
| 74 |
+
parser.add_argument(
|
| 75 |
+
"--view",
|
| 76 |
+
default=None,
|
| 77 |
+
help="Override the view for all rows. By default, the view is inferred from metadata.main_path.",
|
| 78 |
+
)
|
| 79 |
+
parser.add_argument(
|
| 80 |
+
"--limit-trajectories",
|
| 81 |
+
type=int,
|
| 82 |
+
default=None,
|
| 83 |
+
help="Optional smoke-test limit per full manifest, applied after bucket filtering.",
|
| 84 |
+
)
|
| 85 |
+
parser.add_argument(
|
| 86 |
+
"--check-files",
|
| 87 |
+
action="store_true",
|
| 88 |
+
help="Check whether resolved frame files exist and report missing paths.",
|
| 89 |
+
)
|
| 90 |
+
return parser.parse_args()
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def build_record(
|
| 94 |
+
*,
|
| 95 |
+
bucket: str,
|
| 96 |
+
row_idx: int,
|
| 97 |
+
row: dict[str, Any],
|
| 98 |
+
frame: int,
|
| 99 |
+
timestamp_sec: float | None,
|
| 100 |
+
image_path: Path,
|
| 101 |
+
view: str,
|
| 102 |
+
is_terminal_point: bool,
|
| 103 |
+
selected_count: int,
|
| 104 |
+
eval_points: str,
|
| 105 |
+
sample_hz: float,
|
| 106 |
+
) -> dict[str, Any]:
|
| 107 |
+
meta = dict(row.get("metadata") or {})
|
| 108 |
+
record: dict[str, Any] = {
|
| 109 |
+
"bucket": bucket,
|
| 110 |
+
"row_index": row_idx,
|
| 111 |
+
"global_episode_id": str(row.get("global_episode_id") or ""),
|
| 112 |
+
"frame": int(frame),
|
| 113 |
+
"timestamp_sec": timestamp_sec,
|
| 114 |
+
"image_path": str(image_path),
|
| 115 |
+
"view": view,
|
| 116 |
+
"task_instruction": str(meta.get("task_instruction") or ""),
|
| 117 |
+
"task_description": str(meta.get("task_description") or ""),
|
| 118 |
+
"is_terminal_point": bool(is_terminal_point),
|
| 119 |
+
"selected_frame_count": int(selected_count),
|
| 120 |
+
"eval_points": eval_points,
|
| 121 |
+
}
|
| 122 |
+
if eval_points == "time_hz":
|
| 123 |
+
record["sample_hz"] = float(sample_hz)
|
| 124 |
+
if eval_points != "time_hz" or not math.isclose(float(sample_hz), 1.0):
|
| 125 |
+
record["non_strict_eval_input"] = True
|
| 126 |
+
return record
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def build_trajectory_record(
|
| 130 |
+
*,
|
| 131 |
+
bucket: str,
|
| 132 |
+
row_idx: int,
|
| 133 |
+
row: dict[str, Any],
|
| 134 |
+
input_frames: list[int],
|
| 135 |
+
input_timestamps_sec: list[float | None],
|
| 136 |
+
input_image_paths: list[Path],
|
| 137 |
+
eval_frames: list[int],
|
| 138 |
+
eval_timestamps_sec: list[float | None],
|
| 139 |
+
view: str,
|
| 140 |
+
eval_points: str,
|
| 141 |
+
eval_sample_hz: float,
|
| 142 |
+
input_sample_hz: float,
|
| 143 |
+
) -> dict[str, Any]:
|
| 144 |
+
meta = dict(row.get("metadata") or {})
|
| 145 |
+
record: dict[str, Any] = {
|
| 146 |
+
"bucket": bucket,
|
| 147 |
+
"row_index": row_idx,
|
| 148 |
+
"global_episode_id": str(row.get("global_episode_id") or ""),
|
| 149 |
+
"frames": [int(frame) for frame in input_frames],
|
| 150 |
+
"timestamps_sec": input_timestamps_sec,
|
| 151 |
+
"image_paths": [str(path) for path in input_image_paths],
|
| 152 |
+
"input_frames": [int(frame) for frame in input_frames],
|
| 153 |
+
"input_timestamps_sec": input_timestamps_sec,
|
| 154 |
+
"input_image_paths": [str(path) for path in input_image_paths],
|
| 155 |
+
"eval_frames": [int(frame) for frame in eval_frames],
|
| 156 |
+
"eval_timestamps_sec": eval_timestamps_sec,
|
| 157 |
+
"view": view,
|
| 158 |
+
"task_instruction": str(meta.get("task_instruction") or ""),
|
| 159 |
+
"task_description": str(meta.get("task_description") or ""),
|
| 160 |
+
"terminal_frame": int(eval_frames[-1]) if eval_frames else None,
|
| 161 |
+
"selected_frame_count": len(input_frames),
|
| 162 |
+
"input_frame_count": len(input_frames),
|
| 163 |
+
"eval_frame_count": len(eval_frames),
|
| 164 |
+
"eval_points": eval_points,
|
| 165 |
+
"input_sample_hz": float(input_sample_hz),
|
| 166 |
+
}
|
| 167 |
+
if eval_points == "time_hz":
|
| 168 |
+
record["sample_hz"] = float(eval_sample_hz)
|
| 169 |
+
record["eval_sample_hz"] = float(eval_sample_hz)
|
| 170 |
+
if eval_points != "time_hz" or not math.isclose(float(eval_sample_hz), 1.0):
|
| 171 |
+
record["non_strict_eval_input"] = True
|
| 172 |
+
return record
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def main() -> None:
|
| 176 |
+
args = parse_args()
|
| 177 |
+
if args.sample_hz <= 0:
|
| 178 |
+
raise SystemExit("--sample-hz must be positive")
|
| 179 |
+
if args.input_sample_hz <= 0:
|
| 180 |
+
raise SystemExit("--input-sample-hz must be positive")
|
| 181 |
+
|
| 182 |
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
| 183 |
+
stats: Counter[str] = Counter()
|
| 184 |
+
emitted_trajectories = 0
|
| 185 |
+
|
| 186 |
+
with args.out.open("w", encoding="utf-8") as f:
|
| 187 |
+
for bucket, row_idx, row in iter_benchmark_rows(args.benchmark_root, args.buckets):
|
| 188 |
+
if args.limit_trajectories is not None and emitted_trajectories >= args.limit_trajectories:
|
| 189 |
+
break
|
| 190 |
+
|
| 191 |
+
eval_selected = selected_frames_for_row(
|
| 192 |
+
row,
|
| 193 |
+
eval_points=args.eval_points,
|
| 194 |
+
sample_hz=float(args.sample_hz),
|
| 195 |
+
)
|
| 196 |
+
if not eval_selected.frames:
|
| 197 |
+
stats["skipped_empty_selection"] += 1
|
| 198 |
+
continue
|
| 199 |
+
input_selected = selected_frames_for_row(
|
| 200 |
+
row,
|
| 201 |
+
eval_points="time_hz",
|
| 202 |
+
sample_hz=float(args.input_sample_hz),
|
| 203 |
+
)
|
| 204 |
+
if args.record_format == "trajectory" and not input_selected.frames:
|
| 205 |
+
stats["skipped_empty_input_selection"] += 1
|
| 206 |
+
continue
|
| 207 |
+
|
| 208 |
+
selected_view = str(args.view or main_view_for_row(row) or "").strip()
|
| 209 |
+
if not selected_view:
|
| 210 |
+
stats["skipped_missing_view"] += 1
|
| 211 |
+
continue
|
| 212 |
+
|
| 213 |
+
frame_index = dict(row.get("frame_index") or {})
|
| 214 |
+
full_eval_frames = eval_selected.frames
|
| 215 |
+
terminal_frame = full_eval_frames[-1]
|
| 216 |
+
source_selection = input_selected if args.record_format == "trajectory" else eval_selected
|
| 217 |
+
resolved_frames: list[int] = []
|
| 218 |
+
resolved_timestamps: list[float | None] = []
|
| 219 |
+
resolved_paths: list[Path] = []
|
| 220 |
+
missing_view = False
|
| 221 |
+
for frame, timestamp_sec in zip(source_selection.frames, source_selection.timestamps_sec):
|
| 222 |
+
image_map = frame_index.get(str(frame))
|
| 223 |
+
if not isinstance(image_map, dict) or selected_view not in image_map:
|
| 224 |
+
stats["missing_view_points"] += 1
|
| 225 |
+
missing_view = True
|
| 226 |
+
continue
|
| 227 |
+
image_path = absolute_frame_path_from_any(str(image_map[selected_view]), args.frames_root)
|
| 228 |
+
if args.check_files and not image_path.exists():
|
| 229 |
+
stats["missing_frame_files"] += 1
|
| 230 |
+
resolved_frames.append(frame)
|
| 231 |
+
resolved_timestamps.append(timestamp_sec)
|
| 232 |
+
resolved_paths.append(image_path)
|
| 233 |
+
|
| 234 |
+
if not resolved_frames:
|
| 235 |
+
stats["skipped_no_resolved_frames"] += 1
|
| 236 |
+
continue
|
| 237 |
+
if args.record_format == "trajectory" and missing_view:
|
| 238 |
+
stats["skipped_incomplete_trajectory"] += 1
|
| 239 |
+
continue
|
| 240 |
+
|
| 241 |
+
emitted_for_traj = 0
|
| 242 |
+
if args.record_format == "trajectory":
|
| 243 |
+
record = build_trajectory_record(
|
| 244 |
+
bucket=bucket,
|
| 245 |
+
row_idx=row_idx,
|
| 246 |
+
row=row,
|
| 247 |
+
input_frames=resolved_frames,
|
| 248 |
+
input_timestamps_sec=resolved_timestamps,
|
| 249 |
+
input_image_paths=resolved_paths,
|
| 250 |
+
eval_frames=eval_selected.frames,
|
| 251 |
+
eval_timestamps_sec=eval_selected.timestamps_sec,
|
| 252 |
+
view=selected_view,
|
| 253 |
+
eval_points=args.eval_points,
|
| 254 |
+
eval_sample_hz=float(args.sample_hz),
|
| 255 |
+
input_sample_hz=float(args.input_sample_hz),
|
| 256 |
+
)
|
| 257 |
+
f.write(json.dumps(record, ensure_ascii=False) + "\n")
|
| 258 |
+
stats["records"] += 1
|
| 259 |
+
stats["trajectory_records"] += 1
|
| 260 |
+
emitted_for_traj = 1
|
| 261 |
+
else:
|
| 262 |
+
for frame, timestamp_sec, image_path in zip(
|
| 263 |
+
resolved_frames,
|
| 264 |
+
resolved_timestamps,
|
| 265 |
+
resolved_paths,
|
| 266 |
+
):
|
| 267 |
+
record = build_record(
|
| 268 |
+
bucket=bucket,
|
| 269 |
+
row_idx=row_idx,
|
| 270 |
+
row=row,
|
| 271 |
+
frame=frame,
|
| 272 |
+
timestamp_sec=timestamp_sec,
|
| 273 |
+
image_path=image_path,
|
| 274 |
+
view=selected_view,
|
| 275 |
+
is_terminal_point=(frame == terminal_frame),
|
| 276 |
+
selected_count=len(eval_selected.frames),
|
| 277 |
+
eval_points=args.eval_points,
|
| 278 |
+
sample_hz=float(args.sample_hz),
|
| 279 |
+
)
|
| 280 |
+
f.write(json.dumps(record, ensure_ascii=False) + "\n")
|
| 281 |
+
emitted_for_traj += 1
|
| 282 |
+
stats["records"] += 1
|
| 283 |
+
stats["point_records"] += 1
|
| 284 |
+
if emitted_for_traj:
|
| 285 |
+
emitted_trajectories += 1
|
| 286 |
+
stats["trajectories"] += 1
|
| 287 |
+
|
| 288 |
+
summary = {
|
| 289 |
+
"out": str(args.out),
|
| 290 |
+
"benchmark_root": str(args.benchmark_root),
|
| 291 |
+
"frames_root": str(args.frames_root),
|
| 292 |
+
"buckets": list(args.buckets),
|
| 293 |
+
"eval_points": args.eval_points,
|
| 294 |
+
"sample_hz": float(args.sample_hz) if args.eval_points == "time_hz" else None,
|
| 295 |
+
"input_sample_hz": float(args.input_sample_hz),
|
| 296 |
+
"record_format": args.record_format,
|
| 297 |
+
"stats": dict(stats),
|
| 298 |
+
}
|
| 299 |
+
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
if __name__ == "__main__":
|
| 303 |
+
main()
|
scripts/evaluate_v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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import json
|
| 6 |
+
import math
|
| 7 |
+
import re
|
| 8 |
+
import sys
|
| 9 |
+
import tempfile
|
| 10 |
+
from collections import Counter
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
SCRIPT_DIR = Path(__file__).resolve().parent
|
| 15 |
+
if str(SCRIPT_DIR) not in sys.path:
|
| 16 |
+
sys.path.insert(0, str(SCRIPT_DIR))
|
| 17 |
+
|
| 18 |
+
from vpb_public_eval_utils import (
|
| 19 |
+
EXPERT_BUCKETS,
|
| 20 |
+
TEST_BUCKETS,
|
| 21 |
+
Trajectory,
|
| 22 |
+
build_trajectories,
|
| 23 |
+
dump_json,
|
| 24 |
+
finite_float,
|
| 25 |
+
format_metric,
|
| 26 |
+
format_percent,
|
| 27 |
+
markdown_table,
|
| 28 |
+
mean_or_none,
|
| 29 |
+
spearman_corr,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
PredMap = dict[str, dict[int, float]]
|
| 34 |
+
SIGNED_NUM = r"([+-]?[0-9]+(?:\.[0-9]+)?)"
|
| 35 |
+
POINT_TIME_RE = re.compile(r"(?:Time|时间)[::]?\s*([0-9]+(?:\.[0-9]+)?)\s*s?", re.IGNORECASE)
|
| 36 |
+
POINT_PROGRESS_LINE_RE = re.compile(rf"(?im)^\s*(?:Progress|进度)[::]?\s*{SIGNED_NUM}\s*%")
|
| 37 |
+
INLINE_POINT_RE = re.compile(
|
| 38 |
+
rf"(?:Time|时间)[::]?\s*([0-9]+(?:\.[0-9]+)?)\s*s?\s*[,,]?\s*(?:Progress|进度)[::]?\s*{SIGNED_NUM}\s*%",
|
| 39 |
+
re.IGNORECASE,
|
| 40 |
+
)
|
| 41 |
+
SEEN_BUCKETS = ("test_expert_seen", "test_nonexpert_seen")
|
| 42 |
+
UNSEEN_BUCKETS = ("test_expert_unseen", "test_nonexpert_unseen")
|
| 43 |
+
LOCAL_DIRECTION_TAU_PERCENT = 0.0
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def parse_args() -> argparse.Namespace:
|
| 47 |
+
release_root = SCRIPT_DIR.parent
|
| 48 |
+
parser = argparse.ArgumentParser(
|
| 49 |
+
description="Evaluate public Video-Progress Benchmark predictions."
|
| 50 |
+
)
|
| 51 |
+
parser.add_argument(
|
| 52 |
+
"--benchmark-root",
|
| 53 |
+
type=Path,
|
| 54 |
+
default=release_root / "benchmark_splits",
|
| 55 |
+
help="Directory containing the benchmark split folders.",
|
| 56 |
+
)
|
| 57 |
+
parser.add_argument("--predictions", type=Path, help="Prediction JSONL or JSON file.")
|
| 58 |
+
parser.add_argument("--out-json", type=Path, help="Output JSON report.")
|
| 59 |
+
parser.add_argument("--out-md", type=Path, help="Output Markdown report.")
|
| 60 |
+
parser.add_argument(
|
| 61 |
+
"--buckets",
|
| 62 |
+
nargs="+",
|
| 63 |
+
default=list(TEST_BUCKETS),
|
| 64 |
+
choices=list(TEST_BUCKETS),
|
| 65 |
+
help="Benchmark buckets to evaluate.",
|
| 66 |
+
)
|
| 67 |
+
parser.add_argument(
|
| 68 |
+
"--eval-points",
|
| 69 |
+
choices=["time_hz", "dense", "semantic_anchors"],
|
| 70 |
+
default="time_hz",
|
| 71 |
+
help="Evaluation frame points. Default time_hz with --sample-hz 1.0 reconstructs the public 1Hz protocol.",
|
| 72 |
+
)
|
| 73 |
+
parser.add_argument(
|
| 74 |
+
"--sample-hz",
|
| 75 |
+
type=float,
|
| 76 |
+
default=1.0,
|
| 77 |
+
help="Sampling rate used when --eval-points=time_hz.",
|
| 78 |
+
)
|
| 79 |
+
parser.add_argument(
|
| 80 |
+
"--success-threshold",
|
| 81 |
+
type=float,
|
| 82 |
+
default=90.0,
|
| 83 |
+
help="Terminal success threshold in progress percent.",
|
| 84 |
+
)
|
| 85 |
+
parser.add_argument(
|
| 86 |
+
"--clip-pred",
|
| 87 |
+
nargs=2,
|
| 88 |
+
type=float,
|
| 89 |
+
metavar=("MIN", "MAX"),
|
| 90 |
+
default=None,
|
| 91 |
+
help="Optionally clip predictions before evaluation.",
|
| 92 |
+
)
|
| 93 |
+
parser.add_argument(
|
| 94 |
+
"--interpolate-missing",
|
| 95 |
+
action="store_true",
|
| 96 |
+
help="Linearly interpolate missing prediction frames within each trajectory. This is not the strict default.",
|
| 97 |
+
)
|
| 98 |
+
parser.add_argument(
|
| 99 |
+
"--self-test",
|
| 100 |
+
action="store_true",
|
| 101 |
+
help="Run a small synthetic self-test and exit.",
|
| 102 |
+
)
|
| 103 |
+
return parser.parse_args()
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def load_prediction_rows(path: Path) -> list[dict[str, Any]]:
|
| 107 |
+
text = path.read_text(encoding="utf-8").strip()
|
| 108 |
+
if not text:
|
| 109 |
+
return []
|
| 110 |
+
try:
|
| 111 |
+
payload = json.loads(text)
|
| 112 |
+
except json.JSONDecodeError:
|
| 113 |
+
rows = []
|
| 114 |
+
for line_no, line in enumerate(text.splitlines(), start=1):
|
| 115 |
+
raw = line.strip()
|
| 116 |
+
if not raw:
|
| 117 |
+
continue
|
| 118 |
+
item = json.loads(raw)
|
| 119 |
+
if not isinstance(item, dict):
|
| 120 |
+
raise ValueError(f"Prediction line {line_no} is not an object")
|
| 121 |
+
rows.append(item)
|
| 122 |
+
return rows
|
| 123 |
+
|
| 124 |
+
if isinstance(payload, list):
|
| 125 |
+
if not all(isinstance(item, dict) for item in payload):
|
| 126 |
+
raise ValueError("Prediction JSON list must contain objects")
|
| 127 |
+
return list(payload)
|
| 128 |
+
if isinstance(payload, dict):
|
| 129 |
+
for key in ("predictions", "results", "rows"):
|
| 130 |
+
value = payload.get(key)
|
| 131 |
+
if isinstance(value, list):
|
| 132 |
+
if not all(isinstance(item, dict) for item in value):
|
| 133 |
+
raise ValueError(f"Prediction JSON field {key!r} must contain objects")
|
| 134 |
+
return list(value)
|
| 135 |
+
return [payload]
|
| 136 |
+
raise ValueError("Prediction file must be JSONL, a JSON object, or a JSON list")
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def strip_code_fence(text: str) -> str:
|
| 140 |
+
cleaned = str(text or "").strip()
|
| 141 |
+
if cleaned.startswith("```") and cleaned.endswith("```"):
|
| 142 |
+
lines = cleaned.splitlines()
|
| 143 |
+
if len(lines) >= 3:
|
| 144 |
+
return "\n".join(lines[1:-1]).strip()
|
| 145 |
+
return cleaned
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def dedupe_sorted_points(times: list[float], values: list[float]) -> tuple[list[float], list[float]]:
|
| 149 |
+
if not times:
|
| 150 |
+
return [], []
|
| 151 |
+
pairs = sorted(zip(times, values), key=lambda item: (item[0], item[1]))
|
| 152 |
+
out_times: list[float] = []
|
| 153 |
+
out_values: list[float] = []
|
| 154 |
+
cur_time = pairs[0][0]
|
| 155 |
+
bucket: list[float] = []
|
| 156 |
+
for time_val, progress_val in pairs:
|
| 157 |
+
if time_val != cur_time:
|
| 158 |
+
out_times.append(float(cur_time))
|
| 159 |
+
out_values.append(float(sum(bucket) / len(bucket)))
|
| 160 |
+
cur_time = time_val
|
| 161 |
+
bucket = [float(progress_val)]
|
| 162 |
+
else:
|
| 163 |
+
bucket.append(float(progress_val))
|
| 164 |
+
out_times.append(float(cur_time))
|
| 165 |
+
out_values.append(float(sum(bucket) / len(bucket)))
|
| 166 |
+
return out_times, out_values
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def parse_point_blocks(text: str) -> tuple[list[float], list[float]]:
|
| 170 |
+
cleaned = strip_code_fence(text)
|
| 171 |
+
if not cleaned:
|
| 172 |
+
return [], []
|
| 173 |
+
inline_matches = INLINE_POINT_RE.findall(cleaned)
|
| 174 |
+
if inline_matches:
|
| 175 |
+
return dedupe_sorted_points(
|
| 176 |
+
[float(time_val) for time_val, _ in inline_matches],
|
| 177 |
+
[float(progress_val) for _, progress_val in inline_matches],
|
| 178 |
+
)
|
| 179 |
+
blocks = re.split(r"(?=时间[::]?\s*[0-9])", cleaned)
|
| 180 |
+
times: list[float] = []
|
| 181 |
+
values: list[float] = []
|
| 182 |
+
for block in blocks:
|
| 183 |
+
block = block.strip()
|
| 184 |
+
if not block:
|
| 185 |
+
continue
|
| 186 |
+
time_match = POINT_TIME_RE.search(block)
|
| 187 |
+
progress_match = POINT_PROGRESS_LINE_RE.search(block)
|
| 188 |
+
if time_match and progress_match:
|
| 189 |
+
times.append(float(time_match.group(1)))
|
| 190 |
+
values.append(float(progress_match.group(1)))
|
| 191 |
+
return dedupe_sorted_points(times, values)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def align_curve_to_length(raw_times: list[float], raw_values: list[float], target_len: int) -> list[float]:
|
| 195 |
+
"""Match the formal VLAC evaluator's index-normalized curve alignment."""
|
| 196 |
+
if target_len <= 0 or not raw_values:
|
| 197 |
+
return []
|
| 198 |
+
if len(raw_values) == 1:
|
| 199 |
+
return [float(raw_values[0])] * target_len
|
| 200 |
+
times, values = dedupe_sorted_points(raw_times, raw_values)
|
| 201 |
+
if len(values) == 1:
|
| 202 |
+
return [float(values[0])] * target_len
|
| 203 |
+
start = float(times[0])
|
| 204 |
+
end = float(times[-1])
|
| 205 |
+
if math.isclose(start, end):
|
| 206 |
+
if len(values) == 1:
|
| 207 |
+
positions = [0.0]
|
| 208 |
+
else:
|
| 209 |
+
positions = [idx * float(target_len - 1) / float(len(values) - 1) for idx in range(len(values))]
|
| 210 |
+
else:
|
| 211 |
+
positions = [(time_val - start) / (end - start) * float(target_len - 1) for time_val in times]
|
| 212 |
+
|
| 213 |
+
aligned: list[float] = []
|
| 214 |
+
for target in range(target_len):
|
| 215 |
+
target_f = float(target)
|
| 216 |
+
if target_f <= positions[0]:
|
| 217 |
+
aligned.append(float(values[0]))
|
| 218 |
+
continue
|
| 219 |
+
if target_f >= positions[-1]:
|
| 220 |
+
aligned.append(float(values[-1]))
|
| 221 |
+
continue
|
| 222 |
+
for idx in range(len(positions) - 1):
|
| 223 |
+
if positions[idx] <= target_f <= positions[idx + 1]:
|
| 224 |
+
if math.isclose(positions[idx], positions[idx + 1]):
|
| 225 |
+
value = float(values[idx])
|
| 226 |
+
else:
|
| 227 |
+
alpha = (target_f - positions[idx]) / (positions[idx + 1] - positions[idx])
|
| 228 |
+
value = float(values[idx]) + alpha * (float(values[idx + 1]) - float(values[idx]))
|
| 229 |
+
aligned.append(float(value))
|
| 230 |
+
break
|
| 231 |
+
return aligned
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def maybe_clip(value: float, clip_range: tuple[float, float] | None, stats: Counter[str]) -> float:
|
| 235 |
+
if clip_range is None:
|
| 236 |
+
if value < 0.0 or value > 100.0:
|
| 237 |
+
stats["outside_nominal_0_100_predictions"] += 1
|
| 238 |
+
return value
|
| 239 |
+
lo, hi = clip_range
|
| 240 |
+
clipped = min(max(value, lo), hi)
|
| 241 |
+
if clipped != value:
|
| 242 |
+
stats["clipped_predictions"] += 1
|
| 243 |
+
return clipped
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def add_prediction(
|
| 247 |
+
pred_map: PredMap,
|
| 248 |
+
*,
|
| 249 |
+
gid: str,
|
| 250 |
+
frame: int,
|
| 251 |
+
value: Any,
|
| 252 |
+
clip_range: tuple[float, float] | None,
|
| 253 |
+
stats: Counter[str],
|
| 254 |
+
) -> None:
|
| 255 |
+
pred_value = finite_float(value)
|
| 256 |
+
if pred_value is None:
|
| 257 |
+
stats["invalid_prediction_values"] += 1
|
| 258 |
+
return
|
| 259 |
+
pred_value = maybe_clip(float(pred_value), clip_range, stats)
|
| 260 |
+
frame_map = pred_map.setdefault(gid, {})
|
| 261 |
+
if int(frame) in frame_map:
|
| 262 |
+
stats["duplicate_frame_predictions"] += 1
|
| 263 |
+
frame_map[int(frame)] = pred_value
|
| 264 |
+
stats["valid_prediction_values"] += 1
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def add_sequence_predictions(
|
| 268 |
+
pred_map: PredMap,
|
| 269 |
+
*,
|
| 270 |
+
gid: str,
|
| 271 |
+
sequence: Any,
|
| 272 |
+
traj: Trajectory,
|
| 273 |
+
frame_sequence: Any,
|
| 274 |
+
clip_range: tuple[float, float] | None,
|
| 275 |
+
stats: Counter[str],
|
| 276 |
+
) -> None:
|
| 277 |
+
if not isinstance(sequence, list):
|
| 278 |
+
stats["invalid_sequence_predictions"] += 1
|
| 279 |
+
return
|
| 280 |
+
if isinstance(frame_sequence, list) and len(frame_sequence) == len(sequence):
|
| 281 |
+
valid_frames: list[int] = []
|
| 282 |
+
for raw_frame in frame_sequence:
|
| 283 |
+
frame = finite_float(raw_frame)
|
| 284 |
+
if frame is None:
|
| 285 |
+
stats["invalid_sequence_frames"] += 1
|
| 286 |
+
return
|
| 287 |
+
valid_frames.append(int(frame))
|
| 288 |
+
for frame, value in zip(valid_frames, sequence):
|
| 289 |
+
add_prediction(
|
| 290 |
+
pred_map,
|
| 291 |
+
gid=gid,
|
| 292 |
+
frame=frame,
|
| 293 |
+
value=value,
|
| 294 |
+
clip_range=clip_range,
|
| 295 |
+
stats=stats,
|
| 296 |
+
)
|
| 297 |
+
stats["sequence_rows_aligned_by_row_frames"] += 1
|
| 298 |
+
return
|
| 299 |
+
if len(sequence) == len(traj.frames):
|
| 300 |
+
for frame, value in zip(traj.frames, sequence):
|
| 301 |
+
add_prediction(
|
| 302 |
+
pred_map,
|
| 303 |
+
gid=gid,
|
| 304 |
+
frame=frame,
|
| 305 |
+
value=value,
|
| 306 |
+
clip_range=clip_range,
|
| 307 |
+
stats=stats,
|
| 308 |
+
)
|
| 309 |
+
stats["sequence_rows_aligned_by_position"] += 1
|
| 310 |
+
return
|
| 311 |
+
if traj.frames and max(traj.frames) < len(sequence):
|
| 312 |
+
for frame in traj.frames:
|
| 313 |
+
add_prediction(
|
| 314 |
+
pred_map,
|
| 315 |
+
gid=gid,
|
| 316 |
+
frame=frame,
|
| 317 |
+
value=sequence[frame],
|
| 318 |
+
clip_range=clip_range,
|
| 319 |
+
stats=stats,
|
| 320 |
+
)
|
| 321 |
+
stats["sequence_rows_aligned_by_frame_id"] += 1
|
| 322 |
+
return
|
| 323 |
+
stats["sequence_length_mismatch"] += 1
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
def add_vlac_keypoint_predictions(
|
| 327 |
+
pred_map: PredMap,
|
| 328 |
+
*,
|
| 329 |
+
gid: str,
|
| 330 |
+
row: dict[str, Any],
|
| 331 |
+
traj: Trajectory,
|
| 332 |
+
clip_range: tuple[float, float] | None,
|
| 333 |
+
stats: Counter[str],
|
| 334 |
+
) -> bool:
|
| 335 |
+
frame_sequence = row.get("frames") or row.get("input_frames")
|
| 336 |
+
if not isinstance(frame_sequence, list) or not frame_sequence:
|
| 337 |
+
return False
|
| 338 |
+
|
| 339 |
+
raw_times: list[float] = []
|
| 340 |
+
raw_values: list[float] = []
|
| 341 |
+
if isinstance(row.get("pred_curve_point_times_sec"), list) and isinstance(row.get("pred_curve_point_progress"), list):
|
| 342 |
+
for time_val, progress_val in zip(row["pred_curve_point_times_sec"], row["pred_curve_point_progress"]):
|
| 343 |
+
time_num = finite_float(time_val)
|
| 344 |
+
progress_num = finite_float(progress_val)
|
| 345 |
+
if time_num is None or progress_num is None:
|
| 346 |
+
continue
|
| 347 |
+
raw_times.append(float(time_num))
|
| 348 |
+
raw_values.append(float(progress_num))
|
| 349 |
+
elif isinstance(row.get("response"), str):
|
| 350 |
+
raw_times, raw_values = parse_point_blocks(str(row.get("response") or ""))
|
| 351 |
+
else:
|
| 352 |
+
return False
|
| 353 |
+
|
| 354 |
+
if not raw_values:
|
| 355 |
+
stats["vlac_keypoint_parse_failed"] += 1
|
| 356 |
+
return True
|
| 357 |
+
|
| 358 |
+
aligned = align_curve_to_length(raw_times, raw_values, len(frame_sequence))
|
| 359 |
+
if not aligned:
|
| 360 |
+
stats["vlac_keypoint_align_failed"] += 1
|
| 361 |
+
return True
|
| 362 |
+
|
| 363 |
+
add_sequence_predictions(
|
| 364 |
+
pred_map,
|
| 365 |
+
gid=gid,
|
| 366 |
+
sequence=aligned,
|
| 367 |
+
traj=traj,
|
| 368 |
+
frame_sequence=frame_sequence,
|
| 369 |
+
clip_range=clip_range,
|
| 370 |
+
stats=stats,
|
| 371 |
+
)
|
| 372 |
+
stats["vlac_keypoint_rows_aligned_by_index"] += 1
|
| 373 |
+
return True
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def load_predictions(
|
| 377 |
+
path: Path,
|
| 378 |
+
*,
|
| 379 |
+
trajectories: list[Trajectory],
|
| 380 |
+
clip_range: tuple[float, float] | None,
|
| 381 |
+
) -> tuple[PredMap, dict[str, Any]]:
|
| 382 |
+
traj_by_gid = {traj.global_episode_id: traj for traj in trajectories}
|
| 383 |
+
pred_map: PredMap = {}
|
| 384 |
+
stats: Counter[str] = Counter()
|
| 385 |
+
unknown_examples: list[str] = []
|
| 386 |
+
|
| 387 |
+
rows = load_prediction_rows(path)
|
| 388 |
+
stats["rows"] = len(rows)
|
| 389 |
+
for row in rows:
|
| 390 |
+
gid = str(row.get("global_episode_id") or "").strip()
|
| 391 |
+
if not gid:
|
| 392 |
+
stats["rows_missing_global_episode_id"] += 1
|
| 393 |
+
continue
|
| 394 |
+
traj = traj_by_gid.get(gid)
|
| 395 |
+
if traj is None:
|
| 396 |
+
stats["unknown_global_episode_id"] += 1
|
| 397 |
+
if len(unknown_examples) < 10:
|
| 398 |
+
unknown_examples.append(gid)
|
| 399 |
+
continue
|
| 400 |
+
|
| 401 |
+
by_frame = None
|
| 402 |
+
for key in ("pred_progress_by_frame", "progress_by_frame", "predictions_by_frame"):
|
| 403 |
+
value = row.get(key)
|
| 404 |
+
if isinstance(value, dict):
|
| 405 |
+
by_frame = value
|
| 406 |
+
break
|
| 407 |
+
if by_frame is not None:
|
| 408 |
+
stats["episode_rows"] += 1
|
| 409 |
+
for raw_frame, value in by_frame.items():
|
| 410 |
+
frame = finite_float(raw_frame)
|
| 411 |
+
if frame is None:
|
| 412 |
+
stats["invalid_prediction_frames"] += 1
|
| 413 |
+
continue
|
| 414 |
+
add_prediction(
|
| 415 |
+
pred_map,
|
| 416 |
+
gid=gid,
|
| 417 |
+
frame=int(frame),
|
| 418 |
+
value=value,
|
| 419 |
+
clip_range=clip_range,
|
| 420 |
+
stats=stats,
|
| 421 |
+
)
|
| 422 |
+
continue
|
| 423 |
+
|
| 424 |
+
if add_vlac_keypoint_predictions(
|
| 425 |
+
pred_map,
|
| 426 |
+
gid=gid,
|
| 427 |
+
row=row,
|
| 428 |
+
traj=traj,
|
| 429 |
+
clip_range=clip_range,
|
| 430 |
+
stats=stats,
|
| 431 |
+
):
|
| 432 |
+
continue
|
| 433 |
+
|
| 434 |
+
sequence = None
|
| 435 |
+
for key in ("pred_progress_sequence", "pred_dense_progress_aligned_to_gt"):
|
| 436 |
+
value = row.get(key)
|
| 437 |
+
if isinstance(value, list):
|
| 438 |
+
sequence = value
|
| 439 |
+
break
|
| 440 |
+
if sequence is not None:
|
| 441 |
+
stats["sequence_rows"] += 1
|
| 442 |
+
add_sequence_predictions(
|
| 443 |
+
pred_map,
|
| 444 |
+
gid=gid,
|
| 445 |
+
sequence=sequence,
|
| 446 |
+
traj=traj,
|
| 447 |
+
frame_sequence=row.get("frames") or row.get("input_frames"),
|
| 448 |
+
clip_range=clip_range,
|
| 449 |
+
stats=stats,
|
| 450 |
+
)
|
| 451 |
+
continue
|
| 452 |
+
|
| 453 |
+
frame = finite_float(row.get("frame"))
|
| 454 |
+
value = None
|
| 455 |
+
for key in ("pred_progress", "pred_progress_percent", "progress", "prediction"):
|
| 456 |
+
if key in row:
|
| 457 |
+
value = row.get(key)
|
| 458 |
+
break
|
| 459 |
+
if frame is None or value is None:
|
| 460 |
+
stats["unrecognized_prediction_rows"] += 1
|
| 461 |
+
continue
|
| 462 |
+
stats["point_rows"] += 1
|
| 463 |
+
add_prediction(
|
| 464 |
+
pred_map,
|
| 465 |
+
gid=gid,
|
| 466 |
+
frame=int(frame),
|
| 467 |
+
value=value,
|
| 468 |
+
clip_range=clip_range,
|
| 469 |
+
stats=stats,
|
| 470 |
+
)
|
| 471 |
+
|
| 472 |
+
known_frames = {traj.global_episode_id: set(traj.frames) for traj in trajectories}
|
| 473 |
+
extra_frame_count = 0
|
| 474 |
+
for gid, frame_map in pred_map.items():
|
| 475 |
+
eval_frames = known_frames.get(gid, set())
|
| 476 |
+
for frame in frame_map:
|
| 477 |
+
if frame not in eval_frames:
|
| 478 |
+
extra_frame_count += 1
|
| 479 |
+
stats["prediction_frames_outside_eval_points"] = extra_frame_count
|
| 480 |
+
|
| 481 |
+
return pred_map, {"stats": dict(stats), "unknown_global_episode_id_examples": unknown_examples}
|
| 482 |
+
|
| 483 |
+
|
| 484 |
+
def interpolated_value(frame_map: dict[int, float], frame: int) -> float | None:
|
| 485 |
+
if frame in frame_map:
|
| 486 |
+
return frame_map[frame]
|
| 487 |
+
if not frame_map:
|
| 488 |
+
return None
|
| 489 |
+
points = sorted(frame_map.items())
|
| 490 |
+
if frame <= points[0][0]:
|
| 491 |
+
return points[0][1]
|
| 492 |
+
if frame >= points[-1][0]:
|
| 493 |
+
return points[-1][1]
|
| 494 |
+
for (left_frame, left_value), (right_frame, right_value) in zip(points, points[1:]):
|
| 495 |
+
if left_frame <= frame <= right_frame:
|
| 496 |
+
if right_frame == left_frame:
|
| 497 |
+
return left_value
|
| 498 |
+
alpha = (frame - left_frame) / float(right_frame - left_frame)
|
| 499 |
+
return left_value + alpha * (right_value - left_value)
|
| 500 |
+
return None
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
def interpolated_prediction_for_frame(pred_map: PredMap, gid: str, frame: int) -> float | None:
|
| 504 |
+
frame_map = pred_map.get(gid)
|
| 505 |
+
if not frame_map:
|
| 506 |
+
return None
|
| 507 |
+
return interpolated_value(frame_map, int(frame))
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
def prediction_at(
|
| 511 |
+
pred_map: PredMap,
|
| 512 |
+
gid: str,
|
| 513 |
+
frame: int,
|
| 514 |
+
*,
|
| 515 |
+
interpolate_missing: bool,
|
| 516 |
+
) -> float | None:
|
| 517 |
+
frame_map = pred_map.get(gid)
|
| 518 |
+
if not frame_map:
|
| 519 |
+
return None
|
| 520 |
+
if frame in frame_map:
|
| 521 |
+
return frame_map[frame]
|
| 522 |
+
if interpolate_missing:
|
| 523 |
+
return interpolated_value(frame_map, frame)
|
| 524 |
+
return None
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
def summarize_curve(
|
| 528 |
+
trajectories: list[Trajectory],
|
| 529 |
+
pred_map: PredMap,
|
| 530 |
+
*,
|
| 531 |
+
interpolate_missing: bool,
|
| 532 |
+
include_voc: bool,
|
| 533 |
+
) -> dict[str, Any]:
|
| 534 |
+
base_points = sum(len(traj.frames) for traj in trajectories)
|
| 535 |
+
matched_trajs = 0
|
| 536 |
+
matched_points = 0
|
| 537 |
+
valid_points = 0
|
| 538 |
+
traj_with_valid_pred = 0
|
| 539 |
+
mae_values: list[float] = []
|
| 540 |
+
prc_values: list[float] = []
|
| 541 |
+
voc_values: list[float] = []
|
| 542 |
+
|
| 543 |
+
for traj in trajectories:
|
| 544 |
+
has_predictions = traj.global_episode_id in pred_map
|
| 545 |
+
if has_predictions:
|
| 546 |
+
matched_trajs += 1
|
| 547 |
+
matched_points += len(traj.frames)
|
| 548 |
+
|
| 549 |
+
gt_curve: list[float] = []
|
| 550 |
+
pred_curve: list[float] = []
|
| 551 |
+
for frame, gt in zip(traj.frames, traj.gt_progress):
|
| 552 |
+
pred = prediction_at(
|
| 553 |
+
pred_map,
|
| 554 |
+
traj.global_episode_id,
|
| 555 |
+
frame,
|
| 556 |
+
interpolate_missing=interpolate_missing,
|
| 557 |
+
)
|
| 558 |
+
if pred is None or not math.isfinite(float(pred)):
|
| 559 |
+
continue
|
| 560 |
+
valid_points += 1
|
| 561 |
+
gt_curve.append(float(gt))
|
| 562 |
+
pred_curve.append(float(pred))
|
| 563 |
+
|
| 564 |
+
if gt_curve:
|
| 565 |
+
traj_with_valid_pred += 1
|
| 566 |
+
mae_values.append(
|
| 567 |
+
sum(abs(gt - pred) for gt, pred in zip(gt_curve, pred_curve))
|
| 568 |
+
/ len(gt_curve)
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
prc = spearman_corr(gt_curve, pred_curve)
|
| 572 |
+
if prc is not None:
|
| 573 |
+
prc_values.append(prc)
|
| 574 |
+
if include_voc:
|
| 575 |
+
voc = spearman_corr(pred_curve, [float(i) for i in range(1, len(pred_curve) + 1)])
|
| 576 |
+
if voc is not None:
|
| 577 |
+
voc_values.append(voc)
|
| 578 |
+
|
| 579 |
+
return {
|
| 580 |
+
"traj_base_total": len(trajectories),
|
| 581 |
+
"traj_matched": matched_trajs,
|
| 582 |
+
"traj_with_valid_pred": traj_with_valid_pred,
|
| 583 |
+
"point_base_total": base_points,
|
| 584 |
+
"point_total_on_matched": matched_points,
|
| 585 |
+
"point_valid": valid_points,
|
| 586 |
+
"point_coverage_to_base": (valid_points / base_points) if base_points else None,
|
| 587 |
+
"point_coverage_on_matched": (valid_points / matched_points) if matched_points else None,
|
| 588 |
+
"mae": mean_or_none(mae_values),
|
| 589 |
+
"mae_valid_traj": len(mae_values),
|
| 590 |
+
"prc": mean_or_none(prc_values),
|
| 591 |
+
"prc_valid_traj": len(prc_values),
|
| 592 |
+
"voc": mean_or_none(voc_values) if include_voc else None,
|
| 593 |
+
"voc_valid_traj": len(voc_values) if include_voc else 0,
|
| 594 |
+
}
|
| 595 |
+
|
| 596 |
+
|
| 597 |
+
def average_precision_ranked(items: list[tuple[int, float]]) -> float | None:
|
| 598 |
+
positive_total = int(sum(label for label, _ in items))
|
| 599 |
+
if not items or positive_total == 0:
|
| 600 |
+
return None
|
| 601 |
+
ranked = sorted(enumerate(items), key=lambda item: (-float(item[1][1]), item[0]))
|
| 602 |
+
hits = 0
|
| 603 |
+
precision_sum = 0.0
|
| 604 |
+
for rank, (_, (label, _score)) in enumerate(ranked, start=1):
|
| 605 |
+
if int(label) == 1:
|
| 606 |
+
hits += 1
|
| 607 |
+
precision_sum += hits / rank
|
| 608 |
+
return precision_sum / positive_total
|
| 609 |
+
|
| 610 |
+
|
| 611 |
+
def classify_delta(delta: float, tau_percent: float) -> str:
|
| 612 |
+
if delta > tau_percent:
|
| 613 |
+
return "positive"
|
| 614 |
+
if delta < -tau_percent:
|
| 615 |
+
return "negative"
|
| 616 |
+
return "neutral"
|
| 617 |
+
|
| 618 |
+
|
| 619 |
+
def summarize_local_direction_ap(
|
| 620 |
+
trajectories: list[Trajectory],
|
| 621 |
+
pred_map: PredMap,
|
| 622 |
+
*,
|
| 623 |
+
tau_percent: float,
|
| 624 |
+
) -> dict[str, Any]:
|
| 625 |
+
transition_total = 0
|
| 626 |
+
valid = 0
|
| 627 |
+
missing = 0
|
| 628 |
+
gt_counts: Counter[str] = Counter()
|
| 629 |
+
valid_gt_counts: Counter[str] = Counter()
|
| 630 |
+
positive_items: list[tuple[int, float]] = []
|
| 631 |
+
negative_items: list[tuple[int, float]] = []
|
| 632 |
+
|
| 633 |
+
for traj in trajectories:
|
| 634 |
+
frames = traj.semantic_anchor_frames
|
| 635 |
+
progress = traj.semantic_anchor_progress
|
| 636 |
+
for idx in range(max(0, len(frames) - 1)):
|
| 637 |
+
transition_total += 1
|
| 638 |
+
gt_delta = float(progress[idx + 1]) - float(progress[idx])
|
| 639 |
+
gt_class = classify_delta(gt_delta, tau_percent)
|
| 640 |
+
gt_counts[gt_class] += 1
|
| 641 |
+
|
| 642 |
+
left = interpolated_prediction_for_frame(pred_map, traj.global_episode_id, frames[idx])
|
| 643 |
+
right = interpolated_prediction_for_frame(pred_map, traj.global_episode_id, frames[idx + 1])
|
| 644 |
+
if left is None or right is None or not math.isfinite(float(left)) or not math.isfinite(float(right)):
|
| 645 |
+
missing += 1
|
| 646 |
+
continue
|
| 647 |
+
|
| 648 |
+
valid += 1
|
| 649 |
+
valid_gt_counts[gt_class] += 1
|
| 650 |
+
pred_delta = float(right) - float(left)
|
| 651 |
+
positive_items.append((1 if gt_delta > tau_percent else 0, pred_delta))
|
| 652 |
+
negative_items.append((1 if gt_delta < -tau_percent else 0, -pred_delta))
|
| 653 |
+
|
| 654 |
+
ap_positive = average_precision_ranked(positive_items)
|
| 655 |
+
ap_negative = average_precision_ranked(negative_items)
|
| 656 |
+
macro_ap = (
|
| 657 |
+
0.5 * (ap_positive + ap_negative)
|
| 658 |
+
if ap_positive is not None and ap_negative is not None
|
| 659 |
+
else None
|
| 660 |
+
)
|
| 661 |
+
return {
|
| 662 |
+
"tau_percent": float(tau_percent),
|
| 663 |
+
"transition_total": int(transition_total),
|
| 664 |
+
"valid": int(valid),
|
| 665 |
+
"missing": int(missing),
|
| 666 |
+
"gt_counts": {key: int(gt_counts.get(key, 0)) for key in ("positive", "neutral", "negative")},
|
| 667 |
+
"valid_gt_counts": {key: int(valid_gt_counts.get(key, 0)) for key in ("positive", "neutral", "negative")},
|
| 668 |
+
"ap_positive_support": int(sum(label for label, _ in positive_items)),
|
| 669 |
+
"ap_negative_support": int(sum(label for label, _ in negative_items)),
|
| 670 |
+
"ap_positive": ap_positive,
|
| 671 |
+
"ap_negative": ap_negative,
|
| 672 |
+
"macro_ap_d": macro_ap,
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
|
| 676 |
+
def summarize_local_keypoint_progress(
|
| 677 |
+
trajectories: list[Trajectory],
|
| 678 |
+
pred_map: PredMap,
|
| 679 |
+
*,
|
| 680 |
+
include_voc: bool,
|
| 681 |
+
) -> dict[str, Any]:
|
| 682 |
+
point_total = 0
|
| 683 |
+
point_valid = 0
|
| 684 |
+
traj_total = 0
|
| 685 |
+
traj_with_valid_pred = 0
|
| 686 |
+
mae_values: list[float] = []
|
| 687 |
+
prc_values: list[float] = []
|
| 688 |
+
voc_values: list[float] = []
|
| 689 |
+
|
| 690 |
+
for traj in trajectories:
|
| 691 |
+
frames = traj.semantic_anchor_frames
|
| 692 |
+
progress = traj.semantic_anchor_progress
|
| 693 |
+
if not frames:
|
| 694 |
+
continue
|
| 695 |
+
traj_total += 1
|
| 696 |
+
point_total += len(frames)
|
| 697 |
+
gt_curve: list[float] = []
|
| 698 |
+
pred_curve: list[float] = []
|
| 699 |
+
for frame, gt in zip(frames, progress):
|
| 700 |
+
pred = interpolated_prediction_for_frame(pred_map, traj.global_episode_id, frame)
|
| 701 |
+
if pred is None or not math.isfinite(float(pred)):
|
| 702 |
+
continue
|
| 703 |
+
point_valid += 1
|
| 704 |
+
gt_curve.append(float(gt))
|
| 705 |
+
pred_curve.append(float(pred))
|
| 706 |
+
|
| 707 |
+
if gt_curve:
|
| 708 |
+
traj_with_valid_pred += 1
|
| 709 |
+
mae_values.append(
|
| 710 |
+
sum(abs(gt - pred) for gt, pred in zip(gt_curve, pred_curve))
|
| 711 |
+
/ len(gt_curve)
|
| 712 |
+
)
|
| 713 |
+
prc = spearman_corr(gt_curve, pred_curve)
|
| 714 |
+
if prc is not None:
|
| 715 |
+
prc_values.append(prc)
|
| 716 |
+
if include_voc:
|
| 717 |
+
voc = spearman_corr(pred_curve, [float(i) for i in range(1, len(pred_curve) + 1)])
|
| 718 |
+
if voc is not None:
|
| 719 |
+
voc_values.append(voc)
|
| 720 |
+
|
| 721 |
+
return {
|
| 722 |
+
"event_source": "semantic_anchors",
|
| 723 |
+
"traj_base_total": int(traj_total),
|
| 724 |
+
"traj_with_valid_pred": int(traj_with_valid_pred),
|
| 725 |
+
"point_base_total": int(point_total),
|
| 726 |
+
"point_valid": int(point_valid),
|
| 727 |
+
"point_coverage_to_base": (point_valid / point_total) if point_total else None,
|
| 728 |
+
"mae": mean_or_none(mae_values),
|
| 729 |
+
"mae_valid_traj": int(len(mae_values)),
|
| 730 |
+
"prc": mean_or_none(prc_values),
|
| 731 |
+
"prc_valid_traj": int(len(prc_values)),
|
| 732 |
+
"voc": mean_or_none(voc_values) if include_voc else None,
|
| 733 |
+
"voc_valid_traj": int(len(voc_values)) if include_voc else 0,
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
|
| 737 |
+
def finalize_terminal_counter(counter: Counter[str]) -> dict[str, Any]:
|
| 738 |
+
support = int(counter.get("support", 0))
|
| 739 |
+
valid_final = int(counter.get("valid_final", 0))
|
| 740 |
+
tp = int(counter.get("tp", 0))
|
| 741 |
+
fn = int(counter.get("fn", 0))
|
| 742 |
+
fp = int(counter.get("fp", 0))
|
| 743 |
+
tn = int(counter.get("tn", 0))
|
| 744 |
+
gt_success = int(counter.get("gt_success", 0))
|
| 745 |
+
gt_failure = int(counter.get("gt_failure", 0))
|
| 746 |
+
pred_success = int(counter.get("pred_success", 0))
|
| 747 |
+
pred_failure = int(counter.get("pred_failure", 0))
|
| 748 |
+
missing_final = int(counter.get("missing_final", 0))
|
| 749 |
+
valid_binary = tp + fn + fp + tn
|
| 750 |
+
|
| 751 |
+
f1_success = (2 * tp / (2 * tp + fp + fn)) if (2 * tp + fp + fn) else None
|
| 752 |
+
f1_failure = (2 * tn / (2 * tn + fp + fn)) if (2 * tn + fp + fn) else None
|
| 753 |
+
macro_f1_terminal = (
|
| 754 |
+
(f1_success + f1_failure) / 2.0
|
| 755 |
+
if f1_success is not None and f1_failure is not None
|
| 756 |
+
else None
|
| 757 |
+
)
|
| 758 |
+
return {
|
| 759 |
+
"support": support,
|
| 760 |
+
"gt_success": gt_success,
|
| 761 |
+
"gt_failure": gt_failure,
|
| 762 |
+
"valid_final": valid_final,
|
| 763 |
+
"missing_final": missing_final,
|
| 764 |
+
"pred_success": pred_success,
|
| 765 |
+
"pred_failure": pred_failure,
|
| 766 |
+
"tp": tp,
|
| 767 |
+
"fn": fn,
|
| 768 |
+
"fp": fp,
|
| 769 |
+
"tn": tn,
|
| 770 |
+
"tsa": ((tp + tn) / valid_binary) if valid_binary else None,
|
| 771 |
+
"f1_success": f1_success,
|
| 772 |
+
"f1_failure": f1_failure,
|
| 773 |
+
"macro_f1_terminal": macro_f1_terminal,
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
+
|
| 777 |
+
def summarize_terminal(
|
| 778 |
+
trajectories: list[Trajectory],
|
| 779 |
+
pred_map: PredMap,
|
| 780 |
+
*,
|
| 781 |
+
success_threshold: float,
|
| 782 |
+
interpolate_missing: bool,
|
| 783 |
+
) -> dict[str, Any]:
|
| 784 |
+
counter: Counter[str] = Counter()
|
| 785 |
+
for traj in trajectories:
|
| 786 |
+
counter["support"] += 1
|
| 787 |
+
gt_final = float(traj.gt_progress[-1])
|
| 788 |
+
gt_success = gt_final >= success_threshold
|
| 789 |
+
if gt_success:
|
| 790 |
+
counter["gt_success"] += 1
|
| 791 |
+
else:
|
| 792 |
+
counter["gt_failure"] += 1
|
| 793 |
+
|
| 794 |
+
pred_final = prediction_at(
|
| 795 |
+
pred_map,
|
| 796 |
+
traj.global_episode_id,
|
| 797 |
+
traj.frames[-1],
|
| 798 |
+
interpolate_missing=interpolate_missing,
|
| 799 |
+
)
|
| 800 |
+
if pred_final is None or not math.isfinite(float(pred_final)):
|
| 801 |
+
counter["missing_final"] += 1
|
| 802 |
+
continue
|
| 803 |
+
counter["valid_final"] += 1
|
| 804 |
+
pred_success = float(pred_final) >= success_threshold
|
| 805 |
+
if pred_success:
|
| 806 |
+
counter["pred_success"] += 1
|
| 807 |
+
else:
|
| 808 |
+
counter["pred_failure"] += 1
|
| 809 |
+
|
| 810 |
+
if gt_success and pred_success:
|
| 811 |
+
counter["tp"] += 1
|
| 812 |
+
elif gt_success and not pred_success:
|
| 813 |
+
counter["fn"] += 1
|
| 814 |
+
elif (not gt_success) and pred_success:
|
| 815 |
+
counter["fp"] += 1
|
| 816 |
+
else:
|
| 817 |
+
counter["tn"] += 1
|
| 818 |
+
return finalize_terminal_counter(counter)
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
def build_report(
|
| 822 |
+
*,
|
| 823 |
+
trajectories: list[Trajectory],
|
| 824 |
+
pred_map: PredMap,
|
| 825 |
+
prediction_info: dict[str, Any],
|
| 826 |
+
config: dict[str, Any],
|
| 827 |
+
) -> dict[str, Any]:
|
| 828 |
+
selected_buckets = list(config["buckets"])
|
| 829 |
+
by_bucket = {bucket: [traj for traj in trajectories if traj.bucket == bucket] for bucket in selected_buckets}
|
| 830 |
+
interpolate_missing = bool(config["interpolate_missing"])
|
| 831 |
+
success_threshold = float(config["success_threshold_percent"])
|
| 832 |
+
seen_trajs = [
|
| 833 |
+
traj for bucket in SEEN_BUCKETS for traj in by_bucket.get(bucket, [])
|
| 834 |
+
]
|
| 835 |
+
unseen_trajs = [
|
| 836 |
+
traj for bucket in UNSEEN_BUCKETS for traj in by_bucket.get(bucket, [])
|
| 837 |
+
]
|
| 838 |
+
|
| 839 |
+
curve_per_bucket = {
|
| 840 |
+
bucket: summarize_curve(
|
| 841 |
+
bucket_trajs,
|
| 842 |
+
pred_map,
|
| 843 |
+
interpolate_missing=interpolate_missing,
|
| 844 |
+
include_voc=(bucket in EXPERT_BUCKETS),
|
| 845 |
+
)
|
| 846 |
+
for bucket, bucket_trajs in by_bucket.items()
|
| 847 |
+
}
|
| 848 |
+
terminal_per_bucket = {
|
| 849 |
+
bucket: summarize_terminal(
|
| 850 |
+
bucket_trajs,
|
| 851 |
+
pred_map,
|
| 852 |
+
success_threshold=success_threshold,
|
| 853 |
+
interpolate_missing=interpolate_missing,
|
| 854 |
+
)
|
| 855 |
+
for bucket, bucket_trajs in by_bucket.items()
|
| 856 |
+
}
|
| 857 |
+
local_keypoint_per_bucket = {
|
| 858 |
+
bucket: summarize_local_keypoint_progress(
|
| 859 |
+
bucket_trajs,
|
| 860 |
+
pred_map,
|
| 861 |
+
include_voc=(bucket in EXPERT_BUCKETS),
|
| 862 |
+
)
|
| 863 |
+
for bucket, bucket_trajs in by_bucket.items()
|
| 864 |
+
}
|
| 865 |
+
local_direction_per_bucket = {
|
| 866 |
+
bucket: summarize_local_direction_ap(
|
| 867 |
+
bucket_trajs,
|
| 868 |
+
pred_map,
|
| 869 |
+
tau_percent=LOCAL_DIRECTION_TAU_PERCENT,
|
| 870 |
+
)
|
| 871 |
+
for bucket, bucket_trajs in by_bucket.items()
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
return {
|
| 875 |
+
"config": config,
|
| 876 |
+
"benchmark": {
|
| 877 |
+
"traj_total": len(trajectories),
|
| 878 |
+
"point_total": sum(len(traj.frames) for traj in trajectories),
|
| 879 |
+
"buckets": {
|
| 880 |
+
bucket: {
|
| 881 |
+
"traj_total": len(bucket_trajs),
|
| 882 |
+
"point_total": sum(len(traj.frames) for traj in bucket_trajs),
|
| 883 |
+
}
|
| 884 |
+
for bucket, bucket_trajs in by_bucket.items()
|
| 885 |
+
},
|
| 886 |
+
},
|
| 887 |
+
"prediction_input": prediction_info,
|
| 888 |
+
"curve": {
|
| 889 |
+
"overall_4bucket": summarize_curve(
|
| 890 |
+
trajectories,
|
| 891 |
+
pred_map,
|
| 892 |
+
interpolate_missing=interpolate_missing,
|
| 893 |
+
include_voc=False,
|
| 894 |
+
),
|
| 895 |
+
"per_bucket": curve_per_bucket,
|
| 896 |
+
},
|
| 897 |
+
"terminal": {
|
| 898 |
+
"overall_4bucket": summarize_terminal(
|
| 899 |
+
trajectories,
|
| 900 |
+
pred_map,
|
| 901 |
+
success_threshold=success_threshold,
|
| 902 |
+
interpolate_missing=interpolate_missing,
|
| 903 |
+
),
|
| 904 |
+
"seen_merged": summarize_terminal(
|
| 905 |
+
seen_trajs,
|
| 906 |
+
pred_map,
|
| 907 |
+
success_threshold=success_threshold,
|
| 908 |
+
interpolate_missing=interpolate_missing,
|
| 909 |
+
),
|
| 910 |
+
"unseen_merged": summarize_terminal(
|
| 911 |
+
unseen_trajs,
|
| 912 |
+
pred_map,
|
| 913 |
+
success_threshold=success_threshold,
|
| 914 |
+
interpolate_missing=interpolate_missing,
|
| 915 |
+
),
|
| 916 |
+
"per_bucket": terminal_per_bucket,
|
| 917 |
+
},
|
| 918 |
+
"local_direction_ap": {
|
| 919 |
+
"tau_percent": LOCAL_DIRECTION_TAU_PERCENT,
|
| 920 |
+
"overall_4bucket": summarize_local_direction_ap(
|
| 921 |
+
trajectories,
|
| 922 |
+
pred_map,
|
| 923 |
+
tau_percent=LOCAL_DIRECTION_TAU_PERCENT,
|
| 924 |
+
),
|
| 925 |
+
"seen_merged": summarize_local_direction_ap(
|
| 926 |
+
seen_trajs,
|
| 927 |
+
pred_map,
|
| 928 |
+
tau_percent=LOCAL_DIRECTION_TAU_PERCENT,
|
| 929 |
+
),
|
| 930 |
+
"unseen_merged": summarize_local_direction_ap(
|
| 931 |
+
unseen_trajs,
|
| 932 |
+
pred_map,
|
| 933 |
+
tau_percent=LOCAL_DIRECTION_TAU_PERCENT,
|
| 934 |
+
),
|
| 935 |
+
"per_bucket": local_direction_per_bucket,
|
| 936 |
+
},
|
| 937 |
+
"local_keypoint_progress": {
|
| 938 |
+
"overall_4bucket": summarize_local_keypoint_progress(
|
| 939 |
+
trajectories,
|
| 940 |
+
pred_map,
|
| 941 |
+
include_voc=False,
|
| 942 |
+
),
|
| 943 |
+
"per_bucket": local_keypoint_per_bucket,
|
| 944 |
+
},
|
| 945 |
+
}
|
| 946 |
+
|
| 947 |
+
|
| 948 |
+
def point_ratio(item: dict[str, Any]) -> str:
|
| 949 |
+
return f"{int(item.get('point_valid', 0))}/{int(item.get('point_base_total', 0))}"
|
| 950 |
+
|
| 951 |
+
|
| 952 |
+
def traj_ratio(item: dict[str, Any]) -> str:
|
| 953 |
+
return f"{int(item.get('traj_with_valid_pred', 0))}/{int(item.get('traj_base_total', 0))}"
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
def terminal_ratio(item: dict[str, Any]) -> str:
|
| 957 |
+
return f"{int(item.get('valid_final', 0))}/{int(item.get('support', 0))}"
|
| 958 |
+
|
| 959 |
+
|
| 960 |
+
def build_markdown(report: dict[str, Any]) -> str:
|
| 961 |
+
config = report["config"]
|
| 962 |
+
selected_buckets = list(config["buckets"])
|
| 963 |
+
lines: list[str] = []
|
| 964 |
+
lines.append("# Video-Progress Benchmark Evaluation")
|
| 965 |
+
lines.append("")
|
| 966 |
+
lines.append("## Protocol")
|
| 967 |
+
lines.append("")
|
| 968 |
+
lines.append(f"- eval_points: `{config['eval_points']}`")
|
| 969 |
+
lines.append(f"- sample_hz: `{config['sample_hz']}`")
|
| 970 |
+
lines.append(f"- success_threshold: `{config['success_threshold_percent']}`")
|
| 971 |
+
lines.append(f"- interpolate_missing: `{config['interpolate_missing']}`")
|
| 972 |
+
lines.append("- Curve metrics are trajectory-equal means.")
|
| 973 |
+
lines.append("- VOC is reported only for expert bucket rows.")
|
| 974 |
+
lines.append("- Local Direction AP and Local Keypoint Progress use released `semantic_anchors`; predictions are linearly interpolated at anchor frames.")
|
| 975 |
+
lines.append("")
|
| 976 |
+
|
| 977 |
+
curve_rows: list[list[Any]] = []
|
| 978 |
+
curve_sources = [("overall_4bucket", report["curve"]["overall_4bucket"])]
|
| 979 |
+
for bucket in selected_buckets:
|
| 980 |
+
curve_sources.append((bucket, report["curve"]["per_bucket"][bucket]))
|
| 981 |
+
for scope, item in curve_sources:
|
| 982 |
+
include_voc = scope in EXPERT_BUCKETS
|
| 983 |
+
row = [
|
| 984 |
+
scope,
|
| 985 |
+
format_percent(item.get("point_coverage_to_base")),
|
| 986 |
+
point_ratio(item),
|
| 987 |
+
traj_ratio(item),
|
| 988 |
+
format_metric(item.get("mae")),
|
| 989 |
+
format_metric(item.get("prc")),
|
| 990 |
+
]
|
| 991 |
+
if include_voc:
|
| 992 |
+
row.append(format_metric(item.get("voc")))
|
| 993 |
+
else:
|
| 994 |
+
row.append("n/a")
|
| 995 |
+
curve_rows.append(
|
| 996 |
+
row
|
| 997 |
+
)
|
| 998 |
+
lines.append("## Curve Metrics")
|
| 999 |
+
lines.append("")
|
| 1000 |
+
lines.append(
|
| 1001 |
+
markdown_table(
|
| 1002 |
+
["scope", "coverage", "point_valid/base", "traj_valid/base", "MAE", "PRC", "VOC"],
|
| 1003 |
+
curve_rows,
|
| 1004 |
+
)
|
| 1005 |
+
)
|
| 1006 |
+
lines.append("")
|
| 1007 |
+
|
| 1008 |
+
terminal_rows: list[list[Any]] = []
|
| 1009 |
+
terminal_sources = [
|
| 1010 |
+
("overall_4bucket", report["terminal"]["overall_4bucket"]),
|
| 1011 |
+
("seen_merged", report["terminal"]["seen_merged"]),
|
| 1012 |
+
("unseen_merged", report["terminal"]["unseen_merged"]),
|
| 1013 |
+
]
|
| 1014 |
+
for scope, item in terminal_sources:
|
| 1015 |
+
terminal_rows.append(
|
| 1016 |
+
[
|
| 1017 |
+
scope,
|
| 1018 |
+
terminal_ratio(item),
|
| 1019 |
+
format_metric(item.get("tsa")),
|
| 1020 |
+
format_metric(item.get("f1_success")),
|
| 1021 |
+
format_metric(item.get("f1_failure")),
|
| 1022 |
+
format_metric(item.get("macro_f1_terminal")),
|
| 1023 |
+
int(item.get("tp", 0)),
|
| 1024 |
+
int(item.get("fn", 0)),
|
| 1025 |
+
int(item.get("fp", 0)),
|
| 1026 |
+
int(item.get("tn", 0)),
|
| 1027 |
+
int(item.get("missing_final", 0)),
|
| 1028 |
+
]
|
| 1029 |
+
)
|
| 1030 |
+
lines.append("## Terminal Metrics")
|
| 1031 |
+
lines.append("")
|
| 1032 |
+
lines.append(
|
| 1033 |
+
markdown_table(
|
| 1034 |
+
[
|
| 1035 |
+
"scope",
|
| 1036 |
+
"valid_final/support",
|
| 1037 |
+
"TSA",
|
| 1038 |
+
"F1_S",
|
| 1039 |
+
"F1_F",
|
| 1040 |
+
"MacroF1_T",
|
| 1041 |
+
"TP",
|
| 1042 |
+
"FN",
|
| 1043 |
+
"FP",
|
| 1044 |
+
"TN",
|
| 1045 |
+
"missing_final",
|
| 1046 |
+
],
|
| 1047 |
+
terminal_rows,
|
| 1048 |
+
)
|
| 1049 |
+
)
|
| 1050 |
+
lines.append("")
|
| 1051 |
+
|
| 1052 |
+
local_direction_rows: list[list[Any]] = []
|
| 1053 |
+
local_direction_sources = [
|
| 1054 |
+
("overall_4bucket", report["local_direction_ap"]["overall_4bucket"]),
|
| 1055 |
+
("seen_merged", report["local_direction_ap"]["seen_merged"]),
|
| 1056 |
+
("unseen_merged", report["local_direction_ap"]["unseen_merged"]),
|
| 1057 |
+
]
|
| 1058 |
+
for scope, item in local_direction_sources:
|
| 1059 |
+
gt_counts = item.get("gt_counts") or {}
|
| 1060 |
+
local_direction_rows.append(
|
| 1061 |
+
[
|
| 1062 |
+
scope,
|
| 1063 |
+
f"{int(item.get('valid', 0))}/{int(item.get('transition_total', 0))}",
|
| 1064 |
+
f"{int(gt_counts.get('positive', 0))}/{int(gt_counts.get('neutral', 0))}/{int(gt_counts.get('negative', 0))}",
|
| 1065 |
+
f"{int(item.get('ap_positive_support', 0))}/{int(item.get('ap_negative_support', 0))}",
|
| 1066 |
+
format_percent(item.get("ap_positive")),
|
| 1067 |
+
format_percent(item.get("ap_negative")),
|
| 1068 |
+
format_percent(item.get("macro_ap_d")),
|
| 1069 |
+
]
|
| 1070 |
+
)
|
| 1071 |
+
lines.append("## Local Direction AP")
|
| 1072 |
+
lines.append("")
|
| 1073 |
+
tau_text = f"{float(report['local_direction_ap']['tau_percent']):g}%"
|
| 1074 |
+
lines.append(
|
| 1075 |
+
f"`tau={tau_text}`. "
|
| 1076 |
+
"`AP+ = AP(y=Delta_gt>tau, score=Delta_pred)`, "
|
| 1077 |
+
"`AP- = AP(y=Delta_gt<-tau, score=-Delta_pred)`, "
|
| 1078 |
+
"`MacroAP_D = (AP+ + AP-) / 2`."
|
| 1079 |
+
)
|
| 1080 |
+
lines.append("")
|
| 1081 |
+
lines.append(
|
| 1082 |
+
markdown_table(
|
| 1083 |
+
["scope", "valid/trans", "GT +/0/-", "support +/-", "AP+", "AP-", "MacroAP_D"],
|
| 1084 |
+
local_direction_rows,
|
| 1085 |
+
)
|
| 1086 |
+
)
|
| 1087 |
+
lines.append("")
|
| 1088 |
+
|
| 1089 |
+
keypoint_rows: list[list[Any]] = []
|
| 1090 |
+
keypoint_sources = [("overall_4bucket", report["local_keypoint_progress"]["overall_4bucket"])]
|
| 1091 |
+
for bucket in selected_buckets:
|
| 1092 |
+
keypoint_sources.append((bucket, report["local_keypoint_progress"]["per_bucket"][bucket]))
|
| 1093 |
+
for scope, item in keypoint_sources:
|
| 1094 |
+
keypoint_rows.append(
|
| 1095 |
+
[
|
| 1096 |
+
scope,
|
| 1097 |
+
format_percent(item.get("point_coverage_to_base")),
|
| 1098 |
+
point_ratio(item),
|
| 1099 |
+
traj_ratio(item),
|
| 1100 |
+
format_metric(item.get("mae")),
|
| 1101 |
+
format_metric(item.get("prc")),
|
| 1102 |
+
format_metric(item.get("voc")) if scope in EXPERT_BUCKETS else "n/a",
|
| 1103 |
+
]
|
| 1104 |
+
)
|
| 1105 |
+
lines.append("## Local Keypoint Progress")
|
| 1106 |
+
lines.append("")
|
| 1107 |
+
lines.append(
|
| 1108 |
+
markdown_table(
|
| 1109 |
+
["scope", "coverage", "point_valid/keypoints", "traj_valid/base", "MAE", "PRC", "VOC"],
|
| 1110 |
+
keypoint_rows,
|
| 1111 |
+
)
|
| 1112 |
+
)
|
| 1113 |
+
lines.append("")
|
| 1114 |
+
|
| 1115 |
+
lines.append("## Prediction Diagnostics")
|
| 1116 |
+
lines.append("")
|
| 1117 |
+
stats = report["prediction_input"]["stats"]
|
| 1118 |
+
diagnostic_rows = [[key, value] for key, value in sorted(stats.items())]
|
| 1119 |
+
lines.append(markdown_table(["key", "value"], diagnostic_rows))
|
| 1120 |
+
lines.append("")
|
| 1121 |
+
return "\n".join(lines)
|
| 1122 |
+
|
| 1123 |
+
|
| 1124 |
+
def run_self_test() -> None:
|
| 1125 |
+
def row(gid: str, gt_values: list[float], *, success: bool = True) -> dict[str, Any]:
|
| 1126 |
+
frames = [0, 30, 60]
|
| 1127 |
+
if not success:
|
| 1128 |
+
gt_values = [0.0, 20.0, 50.0]
|
| 1129 |
+
return {
|
| 1130 |
+
"global_episode_id": gid,
|
| 1131 |
+
"metadata": {
|
| 1132 |
+
"fps": 30.0,
|
| 1133 |
+
"start_idx": 0,
|
| 1134 |
+
"main_path": f"ARX-data/mock/videos/chunk-000/observation.images.front/{gid}",
|
| 1135 |
+
"available_views": ["front"],
|
| 1136 |
+
"task_instruction": "mock task",
|
| 1137 |
+
"task_description": "mock task",
|
| 1138 |
+
},
|
| 1139 |
+
"frame_index": {
|
| 1140 |
+
str(frame): {"front": f"__VLAC2_FRAMES_ROOT__/mock/{gid}/{frame}-90.jpg"}
|
| 1141 |
+
for frame in frames
|
| 1142 |
+
},
|
| 1143 |
+
"dense_kinematic_progress": {
|
| 1144 |
+
str(frame): value for frame, value in zip(frames, gt_values)
|
| 1145 |
+
},
|
| 1146 |
+
"semantic_anchors": [
|
| 1147 |
+
{"frame": frame, "human_annotated_progress": value}
|
| 1148 |
+
for frame, value in zip(frames, gt_values)
|
| 1149 |
+
],
|
| 1150 |
+
}
|
| 1151 |
+
|
| 1152 |
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
| 1153 |
+
root = Path(tmp_dir) / "benchmark_splits"
|
| 1154 |
+
rows_by_bucket = {
|
| 1155 |
+
"test_expert_seen": [row("traj_success_a", [0.0, 50.0, 100.0])],
|
| 1156 |
+
"test_expert_unseen": [row("traj_success_b", [0.0, 40.0, 100.0])],
|
| 1157 |
+
"test_nonexpert_seen": [row("traj_failure_a", [0.0, 20.0, 50.0], success=False)],
|
| 1158 |
+
"test_nonexpert_unseen": [row("traj_failure_b", [0.0, 10.0, 40.0], success=False)],
|
| 1159 |
+
}
|
| 1160 |
+
for bucket, rows in rows_by_bucket.items():
|
| 1161 |
+
split_dir = root / bucket
|
| 1162 |
+
split_dir.mkdir(parents=True)
|
| 1163 |
+
(split_dir / "video_progress_benchmark_file.json").write_text(
|
| 1164 |
+
json.dumps(rows),
|
| 1165 |
+
encoding="utf-8",
|
| 1166 |
+
)
|
| 1167 |
+
pred_path = Path(tmp_dir) / "predictions.jsonl"
|
| 1168 |
+
with pred_path.open("w", encoding="utf-8") as f:
|
| 1169 |
+
for rows in rows_by_bucket.values():
|
| 1170 |
+
for item in rows:
|
| 1171 |
+
f.write(
|
| 1172 |
+
json.dumps(
|
| 1173 |
+
{
|
| 1174 |
+
"global_episode_id": item["global_episode_id"],
|
| 1175 |
+
"pred_progress_by_frame": item["dense_kinematic_progress"],
|
| 1176 |
+
}
|
| 1177 |
+
)
|
| 1178 |
+
+ "\n"
|
| 1179 |
+
)
|
| 1180 |
+
trajectories = build_trajectories(root, eval_points="time_hz", sample_hz=1.0)
|
| 1181 |
+
pred_map, prediction_info = load_predictions(
|
| 1182 |
+
pred_path,
|
| 1183 |
+
trajectories=trajectories,
|
| 1184 |
+
clip_range=None,
|
| 1185 |
+
)
|
| 1186 |
+
report = build_report(
|
| 1187 |
+
trajectories=trajectories,
|
| 1188 |
+
pred_map=pred_map,
|
| 1189 |
+
prediction_info=prediction_info,
|
| 1190 |
+
config={
|
| 1191 |
+
"benchmark_root": str(root),
|
| 1192 |
+
"predictions": str(pred_path),
|
| 1193 |
+
"buckets": list(TEST_BUCKETS),
|
| 1194 |
+
"eval_points": "time_hz",
|
| 1195 |
+
"sample_hz": 1.0,
|
| 1196 |
+
"success_threshold_percent": 90.0,
|
| 1197 |
+
"interpolate_missing": False,
|
| 1198 |
+
"clip_pred": None,
|
| 1199 |
+
},
|
| 1200 |
+
)
|
| 1201 |
+
assert report["benchmark"]["traj_total"] == 4
|
| 1202 |
+
assert report["curve"]["overall_4bucket"]["mae"] == 0.0
|
| 1203 |
+
assert report["terminal"]["overall_4bucket"]["tsa"] == 1.0
|
| 1204 |
+
assert report["local_keypoint_progress"]["overall_4bucket"]["mae"] == 0.0
|
| 1205 |
+
assert report["local_direction_ap"]["overall_4bucket"]["ap_positive"] == 1.0
|
| 1206 |
+
print("[self-test] ok")
|
| 1207 |
+
|
| 1208 |
+
|
| 1209 |
+
def main() -> None:
|
| 1210 |
+
args = parse_args()
|
| 1211 |
+
if args.self_test:
|
| 1212 |
+
run_self_test()
|
| 1213 |
+
return
|
| 1214 |
+
if args.predictions is None:
|
| 1215 |
+
raise SystemExit("--predictions is required unless --self-test is set")
|
| 1216 |
+
if args.out_json is None and args.out_md is None:
|
| 1217 |
+
raise SystemExit("At least one of --out-json or --out-md is required")
|
| 1218 |
+
if args.sample_hz <= 0:
|
| 1219 |
+
raise SystemExit("--sample-hz must be positive")
|
| 1220 |
+
|
| 1221 |
+
clip_range = None
|
| 1222 |
+
if args.clip_pred is not None:
|
| 1223 |
+
lo, hi = args.clip_pred
|
| 1224 |
+
if lo > hi:
|
| 1225 |
+
raise SystemExit("--clip-pred MIN must be <= MAX")
|
| 1226 |
+
clip_range = (float(lo), float(hi))
|
| 1227 |
+
|
| 1228 |
+
trajectories = build_trajectories(
|
| 1229 |
+
args.benchmark_root,
|
| 1230 |
+
buckets=args.buckets,
|
| 1231 |
+
eval_points=args.eval_points,
|
| 1232 |
+
sample_hz=float(args.sample_hz),
|
| 1233 |
+
)
|
| 1234 |
+
pred_map, prediction_info = load_predictions(
|
| 1235 |
+
args.predictions,
|
| 1236 |
+
trajectories=trajectories,
|
| 1237 |
+
clip_range=clip_range,
|
| 1238 |
+
)
|
| 1239 |
+
config = {
|
| 1240 |
+
"benchmark_root": str(args.benchmark_root),
|
| 1241 |
+
"predictions": str(args.predictions),
|
| 1242 |
+
"buckets": list(args.buckets),
|
| 1243 |
+
"eval_points": args.eval_points,
|
| 1244 |
+
"sample_hz": float(args.sample_hz) if args.eval_points == "time_hz" else None,
|
| 1245 |
+
"success_threshold_percent": float(args.success_threshold),
|
| 1246 |
+
"interpolate_missing": bool(args.interpolate_missing),
|
| 1247 |
+
"clip_pred": list(clip_range) if clip_range is not None else None,
|
| 1248 |
+
}
|
| 1249 |
+
report = build_report(
|
| 1250 |
+
trajectories=trajectories,
|
| 1251 |
+
pred_map=pred_map,
|
| 1252 |
+
prediction_info=prediction_info,
|
| 1253 |
+
config=config,
|
| 1254 |
+
)
|
| 1255 |
+
if args.out_json is not None:
|
| 1256 |
+
dump_json(args.out_json, report)
|
| 1257 |
+
if args.out_md is not None:
|
| 1258 |
+
args.out_md.parent.mkdir(parents=True, exist_ok=True)
|
| 1259 |
+
args.out_md.write_text(build_markdown(report), encoding="utf-8")
|
| 1260 |
+
|
| 1261 |
+
print(
|
| 1262 |
+
json.dumps(
|
| 1263 |
+
{
|
| 1264 |
+
"traj_total": report["benchmark"]["traj_total"],
|
| 1265 |
+
"point_total": report["benchmark"]["point_total"],
|
| 1266 |
+
"curve_overall": report["curve"]["overall_4bucket"],
|
| 1267 |
+
"terminal_overall": report["terminal"]["overall_4bucket"],
|
| 1268 |
+
},
|
| 1269 |
+
ensure_ascii=False,
|
| 1270 |
+
indent=2,
|
| 1271 |
+
)
|
| 1272 |
+
)
|
| 1273 |
+
|
| 1274 |
+
|
| 1275 |
+
if __name__ == "__main__":
|
| 1276 |
+
main()
|
scripts/upload_vlac2_release_archives_to_hf.sbatch
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ntasks=1
|
| 7 |
+
#SBATCH --cpus-per-task=4
|
| 8 |
+
#SBATCH --mem=16G
|
| 9 |
+
#SBATCH --time=1-00:00:00
|
| 10 |
+
#SBATCH --output=slurm/%x_%j.out
|
| 11 |
+
#SBATCH --error=slurm/%x_%j.err
|
| 12 |
+
|
| 13 |
+
set -euo pipefail
|
| 14 |
+
|
| 15 |
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
| 16 |
+
RELEASE_ROOT="${RELEASE_ROOT:-$(cd "${SCRIPT_DIR}/.." && pwd)}"
|
| 17 |
+
HF_REPO_ID="${HF_REPO_ID:-InternRobotics/VLAC-Cut-Benchmark}"
|
| 18 |
+
HF_REPO_TYPE="${HF_REPO_TYPE:-dataset}"
|
| 19 |
+
ARCHIVE_NAMES=(
|
| 20 |
+
vlac2_release_data_part01_arx_group_a.tar.zst
|
| 21 |
+
vlac2_release_data_part02_arx_group_b.tar.zst
|
| 22 |
+
vlac2_release_data_part03_arx_group_c.tar.zst
|
| 23 |
+
vlac2_release_data_part04_droid_group_a.tar.zst
|
| 24 |
+
vlac2_release_data_part05_droid_group_b.tar.zst
|
| 25 |
+
vlac2_release_data_part06_droid_group_c.tar.zst
|
| 26 |
+
vlac2_release_data_part07_other_sources.tar.zst
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
if [[ -z "${HF_TOKEN:-}" ]]; then
|
| 30 |
+
echo "HF_TOKEN is required" >&2
|
| 31 |
+
exit 1
|
| 32 |
+
fi
|
| 33 |
+
|
| 34 |
+
HF_STAGE_ROOT="${RELEASE_ROOT}/vlac2_release_data/.hf_upload_stage"
|
| 35 |
+
mkdir -p "${HF_STAGE_ROOT}"
|
| 36 |
+
|
| 37 |
+
python3 - "${RELEASE_ROOT}" "${HF_REPO_ID}" "${HF_REPO_TYPE}" "${HF_TOKEN}" "${ARCHIVE_NAMES[@]}" <<'PY'
|
| 38 |
+
import fnmatch
|
| 39 |
+
import sys
|
| 40 |
+
from pathlib import Path
|
| 41 |
+
|
| 42 |
+
from huggingface_hub import HfApi
|
| 43 |
+
|
| 44 |
+
release_root = Path(sys.argv[1]).resolve()
|
| 45 |
+
repo_id = sys.argv[2]
|
| 46 |
+
repo_type = sys.argv[3]
|
| 47 |
+
token = sys.argv[4]
|
| 48 |
+
archive_names = sys.argv[5:]
|
| 49 |
+
api = HfApi(token=token)
|
| 50 |
+
|
| 51 |
+
required = [
|
| 52 |
+
release_root / "README.md",
|
| 53 |
+
release_root / "docs" / "vpb_public_evaluation.md",
|
| 54 |
+
release_root / "scripts" / "build_vpb_inference_manifest.py",
|
| 55 |
+
release_root / "scripts" / "evaluate_vpb_predictions.py",
|
| 56 |
+
release_root / "scripts" / "unpack_data.sh",
|
| 57 |
+
release_root / "scripts" / "upload_vlac2_release_archives_to_hf.sbatch",
|
| 58 |
+
release_root / "scripts" / "extract_vlac2_release_frames.py",
|
| 59 |
+
release_root / "scripts" / "vlac2_release_common.py",
|
| 60 |
+
release_root / "scripts" / "vpb_public_eval_utils.py",
|
| 61 |
+
]
|
| 62 |
+
required.extend(sorted((release_root / "benchmark_splits").glob("**/video_progress_benchmark_file.json")))
|
| 63 |
+
required.extend(release_root / "vlac2_release_data" / name for name in archive_names)
|
| 64 |
+
missing = [str(p) for p in required if not p.exists()]
|
| 65 |
+
if missing:
|
| 66 |
+
raise SystemExit(f"missing required local files: {missing}")
|
| 67 |
+
|
| 68 |
+
delete_candidates = [
|
| 69 |
+
"_extracted_frames/_GENERATED",
|
| 70 |
+
"docs/vlac2_public_release.md",
|
| 71 |
+
"release_bundle_manifest.json",
|
| 72 |
+
"rebuild_validation_summary.json",
|
| 73 |
+
"benchmark_json/split_summary.json",
|
| 74 |
+
"benchmark_splits/split_summary.json",
|
| 75 |
+
"vlac2_release_data/vlac2_release_data_archives_manifest.json",
|
| 76 |
+
"vlac2_release_data/ARX-data/.gitkeep",
|
| 77 |
+
"vlac2_release_data/VLABench_5/.gitkeep",
|
| 78 |
+
"vlac2_release_data/dex_fold_v2_mix/.gitkeep",
|
| 79 |
+
"vlac2_release_data/droid_lerobot/.gitkeep",
|
| 80 |
+
"vlac2_release_data/libero/.gitkeep",
|
| 81 |
+
"vlac2_release_data/libero_zty50/.gitkeep",
|
| 82 |
+
"vlac2_release_data/README.md",
|
| 83 |
+
]
|
| 84 |
+
delete_patterns = [
|
| 85 |
+
"benchmark_json/*/benchmark_stats.json",
|
| 86 |
+
"benchmark_json/*/video_progress_benchmark_file.json",
|
| 87 |
+
"benchmark_splits/*/benchmark_stats.json",
|
| 88 |
+
]
|
| 89 |
+
remote_files = set(api.list_repo_files(repo_id=repo_id, repo_type=repo_type))
|
| 90 |
+
for path_in_repo in delete_candidates:
|
| 91 |
+
if path_in_repo in remote_files:
|
| 92 |
+
api.delete_file(
|
| 93 |
+
path_in_repo=path_in_repo,
|
| 94 |
+
repo_id=repo_id,
|
| 95 |
+
repo_type=repo_type,
|
| 96 |
+
commit_message=f"Delete {path_in_repo}",
|
| 97 |
+
)
|
| 98 |
+
for remote_path in sorted(remote_files):
|
| 99 |
+
if any(fnmatch.fnmatch(remote_path, pattern) for pattern in delete_patterns):
|
| 100 |
+
api.delete_file(
|
| 101 |
+
path_in_repo=remote_path,
|
| 102 |
+
repo_id=repo_id,
|
| 103 |
+
repo_type=repo_type,
|
| 104 |
+
commit_message=f"Delete {remote_path}",
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
for local_path in required[:len(required) - len(archive_names)]:
|
| 108 |
+
rel = local_path.relative_to(release_root).as_posix()
|
| 109 |
+
api.upload_file(
|
| 110 |
+
path_or_fileobj=str(local_path),
|
| 111 |
+
path_in_repo=rel,
|
| 112 |
+
repo_id=repo_id,
|
| 113 |
+
repo_type=repo_type,
|
| 114 |
+
commit_message=f"Update {rel}",
|
| 115 |
+
)
|
| 116 |
+
print(f"uploaded={rel}", flush=True)
|
| 117 |
+
PY
|
| 118 |
+
|
| 119 |
+
hf_remote_file_exists() {
|
| 120 |
+
local rel_path="$1"
|
| 121 |
+
python3 - "${rel_path}" "${HF_REPO_ID}" "${HF_REPO_TYPE}" "${HF_TOKEN}" <<'PY'
|
| 122 |
+
import sys
|
| 123 |
+
|
| 124 |
+
from huggingface_hub import HfApi
|
| 125 |
+
|
| 126 |
+
rel_path = sys.argv[1]
|
| 127 |
+
repo_id = sys.argv[2]
|
| 128 |
+
repo_type = sys.argv[3]
|
| 129 |
+
token = sys.argv[4]
|
| 130 |
+
api = HfApi(token=token)
|
| 131 |
+
remote_files = set(api.list_repo_files(repo_id=repo_id, repo_type=repo_type))
|
| 132 |
+
print("1" if rel_path in remote_files else "0")
|
| 133 |
+
PY
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
for archive_name in "${ARCHIVE_NAMES[@]}"; do
|
| 137 |
+
archive_path="${RELEASE_ROOT}/vlac2_release_data/${archive_name}"
|
| 138 |
+
remote_rel="vlac2_release_data/${archive_name}"
|
| 139 |
+
if [[ "$(hf_remote_file_exists "${remote_rel}")" == "1" ]]; then
|
| 140 |
+
echo "remote_exists=${archive_name}"
|
| 141 |
+
continue
|
| 142 |
+
fi
|
| 143 |
+
|
| 144 |
+
stage_path="${HF_STAGE_ROOT}/${remote_rel}"
|
| 145 |
+
mkdir -p "$(dirname "${stage_path}")"
|
| 146 |
+
if [[ ! -f "${stage_path}" ]] || [[ "$(stat -c '%d:%i' "${stage_path}" 2>/dev/null || true)" != "$(stat -c '%d:%i' "${archive_path}")" ]]; then
|
| 147 |
+
rm -f "${stage_path}"
|
| 148 |
+
ln "${archive_path}" "${stage_path}"
|
| 149 |
+
fi
|
| 150 |
+
|
| 151 |
+
hf upload-large-folder "${HF_REPO_ID}" "${HF_STAGE_ROOT}" \
|
| 152 |
+
--repo-type "${HF_REPO_TYPE}" \
|
| 153 |
+
--token "${HF_TOKEN}" \
|
| 154 |
+
--include "${remote_rel}" \
|
| 155 |
+
--num-workers 4
|
| 156 |
+
|
| 157 |
+
echo "uploaded=${remote_rel}"
|
| 158 |
+
rm -f "${stage_path}"
|
| 159 |
+
done
|
scripts/vlac2_release_common.py
CHANGED
|
@@ -241,13 +241,12 @@ def discover_benchmark_jsons(benchmark_root: Path) -> list[Path]:
|
|
| 241 |
benchmark_root = benchmark_root.resolve()
|
| 242 |
candidates: list[Path] = []
|
| 243 |
seen: set[Path] = set()
|
| 244 |
-
for
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
candidates.append(resolved)
|
| 251 |
return candidates
|
| 252 |
|
| 253 |
|
|
|
|
| 241 |
benchmark_root = benchmark_root.resolve()
|
| 242 |
candidates: list[Path] = []
|
| 243 |
seen: set[Path] = set()
|
| 244 |
+
for path in sorted(benchmark_root.glob(f"**/{PUBLIC_BENCHMARK_JSON_NAME}")):
|
| 245 |
+
resolved = path.resolve()
|
| 246 |
+
if resolved in seen:
|
| 247 |
+
continue
|
| 248 |
+
seen.add(resolved)
|
| 249 |
+
candidates.append(resolved)
|
|
|
|
| 250 |
return candidates
|
| 251 |
|
| 252 |
|
scripts/vpb_public_eval_utils.py
ADDED
|
@@ -0,0 +1,366 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import json
|
| 5 |
+
import math
|
| 6 |
+
from dataclasses import dataclass
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any, Iterable
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
TEST_BUCKETS = (
|
| 12 |
+
"test_expert_seen",
|
| 13 |
+
"test_expert_unseen",
|
| 14 |
+
"test_nonexpert_seen",
|
| 15 |
+
"test_nonexpert_unseen",
|
| 16 |
+
)
|
| 17 |
+
EXPERT_BUCKETS = {"test_expert_seen", "test_expert_unseen"}
|
| 18 |
+
BENCHMARK_JSON_NAME = "video_progress_benchmark_file.json"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@dataclass(frozen=True)
|
| 22 |
+
class SelectedFrames:
|
| 23 |
+
frames: list[int]
|
| 24 |
+
timestamps_sec: list[float | None]
|
| 25 |
+
mode: str
|
| 26 |
+
sample_hz: float | None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@dataclass(frozen=True)
|
| 30 |
+
class Trajectory:
|
| 31 |
+
bucket: str
|
| 32 |
+
global_episode_id: str
|
| 33 |
+
frames: list[int]
|
| 34 |
+
gt_progress: list[float]
|
| 35 |
+
timestamps_sec: list[float | None]
|
| 36 |
+
task_instruction: str
|
| 37 |
+
task_description: str
|
| 38 |
+
main_view: str | None
|
| 39 |
+
fps: float | None
|
| 40 |
+
start_idx: int
|
| 41 |
+
semantic_anchor_frames: list[int]
|
| 42 |
+
semantic_anchor_progress: list[float]
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def load_json(path: Path) -> Any:
|
| 46 |
+
return json.loads(path.read_text(encoding="utf-8"))
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def dump_json(path: Path, payload: Any) -> None:
|
| 50 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 51 |
+
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def iter_benchmark_rows(
|
| 55 |
+
benchmark_root: Path,
|
| 56 |
+
buckets: Iterable[str] = TEST_BUCKETS,
|
| 57 |
+
) -> Iterable[tuple[str, int, dict[str, Any]]]:
|
| 58 |
+
for bucket in buckets:
|
| 59 |
+
path = benchmark_root / bucket / BENCHMARK_JSON_NAME
|
| 60 |
+
if not path.exists():
|
| 61 |
+
raise FileNotFoundError(f"Missing benchmark split: {path}")
|
| 62 |
+
rows = load_json(path)
|
| 63 |
+
if not isinstance(rows, list):
|
| 64 |
+
raise ValueError(f"Expected list in benchmark split: {path}")
|
| 65 |
+
for idx, row in enumerate(rows):
|
| 66 |
+
if not isinstance(row, dict):
|
| 67 |
+
raise ValueError(f"Expected object row in {path} at index {idx}")
|
| 68 |
+
yield bucket, idx, row
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def finite_float(value: Any) -> float | None:
|
| 72 |
+
try:
|
| 73 |
+
number = float(value)
|
| 74 |
+
except (TypeError, ValueError):
|
| 75 |
+
return None
|
| 76 |
+
return number if math.isfinite(number) else None
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def mean_or_none(values: Iterable[float | None]) -> float | None:
|
| 80 |
+
clean = [float(v) for v in values if v is not None and math.isfinite(float(v))]
|
| 81 |
+
if not clean:
|
| 82 |
+
return None
|
| 83 |
+
return float(sum(clean) / len(clean))
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def pearson_corr(xs: list[float], ys: list[float]) -> float | None:
|
| 87 |
+
if len(xs) != len(ys) or len(xs) < 2:
|
| 88 |
+
return None
|
| 89 |
+
mean_x = sum(xs) / len(xs)
|
| 90 |
+
mean_y = sum(ys) / len(ys)
|
| 91 |
+
num = sum((x - mean_x) * (y - mean_y) for x, y in zip(xs, ys))
|
| 92 |
+
den_x = sum((x - mean_x) ** 2 for x in xs)
|
| 93 |
+
den_y = sum((y - mean_y) ** 2 for y in ys)
|
| 94 |
+
if math.isclose(den_x, 0.0, rel_tol=0.0, abs_tol=1e-12):
|
| 95 |
+
return None
|
| 96 |
+
if math.isclose(den_y, 0.0, rel_tol=0.0, abs_tol=1e-12):
|
| 97 |
+
return None
|
| 98 |
+
value = num / math.sqrt(den_x * den_y)
|
| 99 |
+
return value if math.isfinite(value) else None
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def average_ranks(values: list[float]) -> list[float]:
|
| 103 |
+
order = sorted(range(len(values)), key=lambda idx: values[idx])
|
| 104 |
+
ranks = [0.0] * len(values)
|
| 105 |
+
i = 0
|
| 106 |
+
while i < len(order):
|
| 107 |
+
j = i + 1
|
| 108 |
+
while (
|
| 109 |
+
j < len(order)
|
| 110 |
+
and math.isclose(values[order[j]], values[order[i]], rel_tol=0.0, abs_tol=1e-9)
|
| 111 |
+
):
|
| 112 |
+
j += 1
|
| 113 |
+
rank = (i + j - 1) / 2.0 + 1.0
|
| 114 |
+
for pos in order[i:j]:
|
| 115 |
+
ranks[pos] = rank
|
| 116 |
+
i = j
|
| 117 |
+
return ranks
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def spearman_corr(xs: list[float], ys: list[float]) -> float | None:
|
| 121 |
+
return pearson_corr(average_ranks(xs), average_ranks(ys))
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def extract_view_from_main_path(main_path: str | None) -> str | None:
|
| 125 |
+
raw = str(main_path or "").strip()
|
| 126 |
+
if not raw:
|
| 127 |
+
return None
|
| 128 |
+
for part in Path(raw).parts:
|
| 129 |
+
if part.startswith("observation.images."):
|
| 130 |
+
view = part.split("observation.images.", 1)[1].strip()
|
| 131 |
+
return view or None
|
| 132 |
+
return None
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def main_view_for_row(row: dict[str, Any]) -> str | None:
|
| 136 |
+
meta = dict(row.get("metadata") or {})
|
| 137 |
+
target_view = extract_view_from_main_path(meta.get("main_path"))
|
| 138 |
+
available = [str(v) for v in meta.get("available_views", []) if str(v).strip()]
|
| 139 |
+
if target_view:
|
| 140 |
+
return target_view
|
| 141 |
+
if available:
|
| 142 |
+
return available[0]
|
| 143 |
+
frame_index = row.get("frame_index")
|
| 144 |
+
if isinstance(frame_index, dict):
|
| 145 |
+
for image_map in frame_index.values():
|
| 146 |
+
if isinstance(image_map, dict) and image_map:
|
| 147 |
+
return sorted(str(k) for k in image_map.keys())[0]
|
| 148 |
+
return None
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def _nearest_frame(eligible: list[int], target_frame: float) -> int:
|
| 152 |
+
best_idx = eligible[0]
|
| 153 |
+
best_distance = abs(float(best_idx) - target_frame)
|
| 154 |
+
for idx in eligible[1:]:
|
| 155 |
+
distance = abs(float(idx) - target_frame)
|
| 156 |
+
if distance < best_distance:
|
| 157 |
+
best_idx = idx
|
| 158 |
+
best_distance = distance
|
| 159 |
+
return int(best_idx)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def sample_frame_indices_by_hz(
|
| 163 |
+
frame_ids: list[int],
|
| 164 |
+
*,
|
| 165 |
+
start_idx: int,
|
| 166 |
+
fps: float,
|
| 167 |
+
sample_hz: float,
|
| 168 |
+
) -> tuple[list[int], list[float]]:
|
| 169 |
+
if not frame_ids or fps <= 0 or sample_hz <= 0:
|
| 170 |
+
return [], []
|
| 171 |
+
eligible = [idx for idx in frame_ids if idx >= start_idx]
|
| 172 |
+
if not eligible:
|
| 173 |
+
eligible = list(frame_ids)
|
| 174 |
+
if not eligible:
|
| 175 |
+
return [], []
|
| 176 |
+
|
| 177 |
+
start_frame = eligible[0]
|
| 178 |
+
end_frame = eligible[-1]
|
| 179 |
+
duration_sec = max(0.0, (end_frame - start_frame) / fps)
|
| 180 |
+
step_sec = 1.0 / sample_hz
|
| 181 |
+
|
| 182 |
+
target_times: list[float] = []
|
| 183 |
+
current = 0.0
|
| 184 |
+
eps = 1e-9
|
| 185 |
+
while current <= duration_sec + eps:
|
| 186 |
+
target_times.append(round(current, 6))
|
| 187 |
+
current += step_sec
|
| 188 |
+
if not target_times:
|
| 189 |
+
target_times = [0.0]
|
| 190 |
+
|
| 191 |
+
selected_indices: list[int] = []
|
| 192 |
+
selected_times: list[float] = []
|
| 193 |
+
seen: set[int] = set()
|
| 194 |
+
for target_time in target_times:
|
| 195 |
+
target_frame = start_frame + target_time * fps
|
| 196 |
+
idx = _nearest_frame(eligible, target_frame)
|
| 197 |
+
if idx in seen:
|
| 198 |
+
continue
|
| 199 |
+
seen.add(idx)
|
| 200 |
+
selected_indices.append(idx)
|
| 201 |
+
selected_times.append(round((idx - start_frame) / fps, 6))
|
| 202 |
+
|
| 203 |
+
if not selected_indices:
|
| 204 |
+
selected_indices = [start_frame]
|
| 205 |
+
selected_times = [0.0]
|
| 206 |
+
return selected_indices, selected_times
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def selected_frames_for_row(
|
| 210 |
+
row: dict[str, Any],
|
| 211 |
+
*,
|
| 212 |
+
eval_points: str,
|
| 213 |
+
sample_hz: float,
|
| 214 |
+
) -> SelectedFrames:
|
| 215 |
+
frame_index = dict(row.get("frame_index") or {})
|
| 216 |
+
dense_progress = dict(row.get("dense_kinematic_progress") or {})
|
| 217 |
+
frame_ids = sorted(
|
| 218 |
+
int(k)
|
| 219 |
+
for k in frame_index.keys()
|
| 220 |
+
if str(k) in dense_progress and finite_float(dense_progress.get(str(k))) is not None
|
| 221 |
+
)
|
| 222 |
+
if not frame_ids:
|
| 223 |
+
return SelectedFrames([], [], eval_points, sample_hz if eval_points == "time_hz" else None)
|
| 224 |
+
|
| 225 |
+
if eval_points == "dense":
|
| 226 |
+
return SelectedFrames(frame_ids, [None] * len(frame_ids), "dense", None)
|
| 227 |
+
|
| 228 |
+
if eval_points == "semantic_anchors":
|
| 229 |
+
anchor_frames: list[int] = []
|
| 230 |
+
seen: set[int] = set()
|
| 231 |
+
for anchor in row.get("semantic_anchors") or []:
|
| 232 |
+
if not isinstance(anchor, dict):
|
| 233 |
+
continue
|
| 234 |
+
frame = finite_float(anchor.get("frame"))
|
| 235 |
+
if frame is None:
|
| 236 |
+
continue
|
| 237 |
+
idx = int(frame)
|
| 238 |
+
if idx in seen or idx not in frame_ids:
|
| 239 |
+
continue
|
| 240 |
+
seen.add(idx)
|
| 241 |
+
anchor_frames.append(idx)
|
| 242 |
+
anchor_frames.sort()
|
| 243 |
+
return SelectedFrames(anchor_frames, [None] * len(anchor_frames), "semantic_anchors", None)
|
| 244 |
+
|
| 245 |
+
if eval_points != "time_hz":
|
| 246 |
+
raise ValueError(f"Unsupported eval_points: {eval_points}")
|
| 247 |
+
|
| 248 |
+
meta = dict(row.get("metadata") or {})
|
| 249 |
+
fps = finite_float(meta.get("fps")) or 0.0
|
| 250 |
+
start_idx = int(finite_float(meta.get("start_idx")) or frame_ids[0])
|
| 251 |
+
frames, timestamps = sample_frame_indices_by_hz(
|
| 252 |
+
frame_ids,
|
| 253 |
+
start_idx=start_idx,
|
| 254 |
+
fps=fps,
|
| 255 |
+
sample_hz=sample_hz,
|
| 256 |
+
)
|
| 257 |
+
valid = [
|
| 258 |
+
(frame, ts)
|
| 259 |
+
for frame, ts in zip(frames, timestamps)
|
| 260 |
+
if str(frame) in dense_progress and finite_float(dense_progress.get(str(frame))) is not None
|
| 261 |
+
]
|
| 262 |
+
return SelectedFrames(
|
| 263 |
+
[frame for frame, _ in valid],
|
| 264 |
+
[ts for _, ts in valid],
|
| 265 |
+
"time_hz",
|
| 266 |
+
float(sample_hz),
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def semantic_anchor_points_for_row(row: dict[str, Any]) -> tuple[list[int], list[float]]:
|
| 271 |
+
points_by_frame: dict[int, float] = {}
|
| 272 |
+
for anchor in row.get("semantic_anchors") or []:
|
| 273 |
+
if not isinstance(anchor, dict):
|
| 274 |
+
continue
|
| 275 |
+
frame = finite_float(anchor.get("frame"))
|
| 276 |
+
progress = finite_float(anchor.get("human_annotated_progress"))
|
| 277 |
+
if frame is None or progress is None:
|
| 278 |
+
continue
|
| 279 |
+
points_by_frame[int(frame)] = float(progress)
|
| 280 |
+
frames = sorted(points_by_frame)
|
| 281 |
+
return frames, [points_by_frame[frame] for frame in frames]
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def build_trajectories(
|
| 285 |
+
benchmark_root: Path,
|
| 286 |
+
*,
|
| 287 |
+
buckets: Iterable[str] = TEST_BUCKETS,
|
| 288 |
+
eval_points: str = "time_hz",
|
| 289 |
+
sample_hz: float = 1.0,
|
| 290 |
+
) -> list[Trajectory]:
|
| 291 |
+
trajectories: list[Trajectory] = []
|
| 292 |
+
seen_gids: set[str] = set()
|
| 293 |
+
for bucket, row_idx, row in iter_benchmark_rows(benchmark_root, buckets):
|
| 294 |
+
global_episode_id = str(row.get("global_episode_id") or "").strip()
|
| 295 |
+
if not global_episode_id:
|
| 296 |
+
raise ValueError(f"Missing global_episode_id in {bucket} row {row_idx}")
|
| 297 |
+
if global_episode_id in seen_gids:
|
| 298 |
+
raise ValueError(f"Duplicate global_episode_id across benchmark splits: {global_episode_id}")
|
| 299 |
+
seen_gids.add(global_episode_id)
|
| 300 |
+
|
| 301 |
+
selected = selected_frames_for_row(row, eval_points=eval_points, sample_hz=sample_hz)
|
| 302 |
+
dense_progress = dict(row.get("dense_kinematic_progress") or {})
|
| 303 |
+
gt_progress: list[float] = []
|
| 304 |
+
frames: list[int] = []
|
| 305 |
+
timestamps: list[float | None] = []
|
| 306 |
+
for frame, timestamp in zip(selected.frames, selected.timestamps_sec):
|
| 307 |
+
value = finite_float(dense_progress.get(str(frame)))
|
| 308 |
+
if value is None:
|
| 309 |
+
continue
|
| 310 |
+
frames.append(int(frame))
|
| 311 |
+
timestamps.append(timestamp)
|
| 312 |
+
gt_progress.append(float(value))
|
| 313 |
+
if not frames:
|
| 314 |
+
continue
|
| 315 |
+
|
| 316 |
+
meta = dict(row.get("metadata") or {})
|
| 317 |
+
anchor_frames, anchor_progress = semantic_anchor_points_for_row(row)
|
| 318 |
+
trajectories.append(
|
| 319 |
+
Trajectory(
|
| 320 |
+
bucket=bucket,
|
| 321 |
+
global_episode_id=global_episode_id,
|
| 322 |
+
frames=frames,
|
| 323 |
+
gt_progress=gt_progress,
|
| 324 |
+
timestamps_sec=timestamps,
|
| 325 |
+
task_instruction=str(meta.get("task_instruction") or ""),
|
| 326 |
+
task_description=str(meta.get("task_description") or ""),
|
| 327 |
+
main_view=main_view_for_row(row),
|
| 328 |
+
fps=finite_float(meta.get("fps")),
|
| 329 |
+
start_idx=int(finite_float(meta.get("start_idx")) or frames[0]),
|
| 330 |
+
semantic_anchor_frames=anchor_frames,
|
| 331 |
+
semantic_anchor_progress=anchor_progress,
|
| 332 |
+
)
|
| 333 |
+
)
|
| 334 |
+
return trajectories
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
def format_metric(value: Any, digits: int = 4) -> str:
|
| 338 |
+
if value is None:
|
| 339 |
+
return "n/a"
|
| 340 |
+
if isinstance(value, float):
|
| 341 |
+
if not math.isfinite(value):
|
| 342 |
+
return "n/a"
|
| 343 |
+
return f"{value:.{digits}f}"
|
| 344 |
+
return str(value)
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
def format_percent(value: Any, digits: int = 2) -> str:
|
| 348 |
+
if value is None:
|
| 349 |
+
return "n/a"
|
| 350 |
+
try:
|
| 351 |
+
number = float(value)
|
| 352 |
+
except (TypeError, ValueError):
|
| 353 |
+
return "n/a"
|
| 354 |
+
if not math.isfinite(number):
|
| 355 |
+
return "n/a"
|
| 356 |
+
return f"{number * 100.0:.{digits}f}%"
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
def markdown_table(headers: list[str], rows: list[list[Any]]) -> str:
|
| 360 |
+
lines = [
|
| 361 |
+
"| " + " | ".join(headers) + " |",
|
| 362 |
+
"| " + " | ".join(["---"] * len(headers)) + " |",
|
| 363 |
+
]
|
| 364 |
+
for row in rows:
|
| 365 |
+
lines.append("| " + " | ".join(str(cell) for cell in row) + " |")
|
| 366 |
+
return "\n".join(lines)
|