Upload 5 files
Browse files- README.md +165 -0
- scripts/evaluation_perception.py +168 -0
- scripts/evaluation_planning.py +230 -0
- scripts/evaluation_prediction.py +165 -0
- scripts/evaluation_understanding.py +302 -0
README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: EventDrive
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
# EventDrive
|
| 8 |
+
|
| 9 |
+
## EventDrive: Event Cameras for Vision-Language Driving Intelligence
|
| 10 |
+
|
| 11 |
+
Dongyue Lu, Rong Li, Ao Liang, Lingdong Kong, Wei Yin, Lai Xing Ng, Benoit R. Cottereau, Camille Simon Chane, and Wei Tsang Ooi
|
| 12 |
+
|
| 13 |
+
**CVPR 2026**
|
| 14 |
+
|
| 15 |
+
[Project Page](https://dylanorange.github.io/projects/eventdrive/) | [Paper](https://dylanorange.github.io/projects/eventdrive/static/files/EventDrive.pdf) | [Dataset](https://huggingface.co/datasets/dylanorange/EventDrive)
|
| 16 |
+
|
| 17 |
+
EventDrive is a unified event-frame driving benchmark for vision-language driving intelligence. It combines synchronized RGB frames, event-camera data, and instruction-style annotations to study how event sensing supports multimodal perception, reasoning, prediction, and planning under diverse driving conditions.
|
| 18 |
+
|
| 19 |
+
The benchmark covers four dimensions:
|
| 20 |
+
|
| 21 |
+
- **Perception**: scene-level driving perception questions.
|
| 22 |
+
- **Understanding**: object awareness, grounding, appearance, status, and spatial-relation questions.
|
| 23 |
+
- **Prediction**: short-term behavior prediction for a highlighted dynamic agent.
|
| 24 |
+
- **Planning**: high-level driving intent and ego-trajectory prediction.
|
| 25 |
+
|
| 26 |
+
## Repository Layout
|
| 27 |
+
|
| 28 |
+
```text
|
| 29 |
+
.
|
| 30 |
+
├── eventdrive_perception.tar.gz
|
| 31 |
+
├── eventdrive_understanding.tar.gz
|
| 32 |
+
├── eventdrive_prediction.tar.gz
|
| 33 |
+
├── eventdrive_planning.tar.gz
|
| 34 |
+
├── json/
|
| 35 |
+
│ ├── perception/
|
| 36 |
+
│ │ ├── dsec/
|
| 37 |
+
│ │ ├── m3ed/
|
| 38 |
+
│ │ └── pku/
|
| 39 |
+
│ ├── understanding/
|
| 40 |
+
│ ├── prediction/
|
| 41 |
+
│ └── planning/
|
| 42 |
+
└── scripts/
|
| 43 |
+
├── evaluation_perception.py
|
| 44 |
+
├── evaluation_understanding.py
|
| 45 |
+
├── evaluation_prediction.py
|
| 46 |
+
└── evaluation_planning.py
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
Create a `data/` directory and extract all archives from the repository root:
|
| 50 |
+
|
| 51 |
+
```bash
|
| 52 |
+
mkdir -p data
|
| 53 |
+
tar -xzf eventdrive_perception.tar.gz -C data
|
| 54 |
+
tar -xzf eventdrive_understanding.tar.gz -C data
|
| 55 |
+
tar -xzf eventdrive_prediction.tar.gz -C data
|
| 56 |
+
tar -xzf eventdrive_planning.tar.gz -C data
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
The extracted data follows this structure:
|
| 60 |
+
|
| 61 |
+
```text
|
| 62 |
+
data/
|
| 63 |
+
├── perception/
|
| 64 |
+
│ ├── dsec/
|
| 65 |
+
│ │ ├── train/<sequence>/{image,event}/
|
| 66 |
+
│ │ └── test/<sequence>/{image,event}/
|
| 67 |
+
│ ├── m3ed/<sequence>/{image,event}/
|
| 68 |
+
│ └── pku/aps_frames_sampled/val/<condition>/<sequence>/
|
| 69 |
+
├── understanding/
|
| 70 |
+
│ ├── train/<sequence>/{image,event}/
|
| 71 |
+
│ └── test/<sequence>/{image,event}/
|
| 72 |
+
├── prediction/<sequence>/{image,event}/
|
| 73 |
+
└── planning/<sequence>/{image,event}/
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
Each `image/` directory contains RGB frames. Each `event/` directory contains the paired event-camera representation in `.npz` format.
|
| 77 |
+
|
| 78 |
+
For PKU perception data, paired `.png` and `.npz` files are stored side by side in each sequence directory instead of separate `image/` and `event/` directories.
|
| 79 |
+
|
| 80 |
+
## Annotation Files
|
| 81 |
+
|
| 82 |
+
All annotation paths are relative to the repository root and start with `data/`. Run the scripts from the repository root after extracting the archives.
|
| 83 |
+
|
| 84 |
+
Each dimension provides train and test annotations. Files ending in `_hard.json` contain the hard test subsets.
|
| 85 |
+
|
| 86 |
+
The released annotations under `json/` use separate prompts for answer components such as option letter and label text, or speed and path intent. Samples originating from the same question share an `original_id`. The evaluation scripts use this field to pair component predictions before computing joint accuracy. Planning trajectory samples are evaluated independently and do not require an `original_id`.
|
| 87 |
+
|
| 88 |
+
A typical annotation includes paired image and event paths plus an instruction-answer conversation:
|
| 89 |
+
|
| 90 |
+
```json
|
| 91 |
+
{
|
| 92 |
+
"image": "data/perception/dsec/test/interlaken_00_a/image/000005.png",
|
| 93 |
+
"event": "data/perception/dsec/test/interlaken_00_a/event/000005.npz",
|
| 94 |
+
"category": "Scene type",
|
| 95 |
+
"original_id": "perception/dsec/dsec_test_perception.json:000000",
|
| 96 |
+
"subtask": "option_letter",
|
| 97 |
+
"conversations": [
|
| 98 |
+
{
|
| 99 |
+
"from": "human",
|
| 100 |
+
"value": "<instruction>"
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"from": "gpt",
|
| 104 |
+
"value": "<ground-truth answer>"
|
| 105 |
+
}
|
| 106 |
+
]
|
| 107 |
+
}
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
Add a `model_output` field to each sample after inference:
|
| 111 |
+
|
| 112 |
+
```json
|
| 113 |
+
{
|
| 114 |
+
"model_output": "<model prediction>"
|
| 115 |
+
}
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
For understanding grounding samples, boxes use `[x, y, w, h]`, where `(x, y)` is the top-left corner and `(w, h)` is the width and height.
|
| 119 |
+
|
| 120 |
+
## Evaluation
|
| 121 |
+
|
| 122 |
+
Install the evaluation dependencies:
|
| 123 |
+
|
| 124 |
+
```bash
|
| 125 |
+
pip install numpy tqdm
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
Run the matching evaluator on an inference result JSON file generated from the annotations under `json/`:
|
| 129 |
+
|
| 130 |
+
```bash
|
| 131 |
+
python scripts/evaluation_perception.py \
|
| 132 |
+
--pred-json results/dsec_test_perception.json
|
| 133 |
+
|
| 134 |
+
python scripts/evaluation_understanding.py \
|
| 135 |
+
--pred-json results/dsec_test_understanding.json \
|
| 136 |
+
--iou-thresh 0.6
|
| 137 |
+
|
| 138 |
+
python scripts/evaluation_prediction.py \
|
| 139 |
+
--pred-json results/m3ed_test_prediction.json
|
| 140 |
+
|
| 141 |
+
python scripts/evaluation_planning.py \
|
| 142 |
+
--pred-json results/m3ed_test_planning.json
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
The evaluators write summary JSON files next to the prediction file. They also save mismatch examples for debugging when applicable.
|
| 146 |
+
|
| 147 |
+
Metrics:
|
| 148 |
+
|
| 149 |
+
- **Perception**: joint accuracy after pairing the split option-letter and label-text answers. Both answers must be correct.
|
| 150 |
+
- **Understanding**: joint QA accuracy after pairing the split option-letter and label-text answers, category-wise accuracy, grounding accuracy at the selected IoU threshold, and mean IoU. Both QA answers must be correct. The default IoU threshold is `0.6`.
|
| 151 |
+
- **Prediction**: speed accuracy, path accuracy, class-wise accuracy, and joint speed-path accuracy after pairing split answers.
|
| 152 |
+
- **Planning**: high-level speed accuracy, path accuracy, class-wise accuracy, joint speed-path accuracy after pairing split answers, and trajectory L2 error at `1s`, `3s`, and `5s`.
|
| 153 |
+
|
| 154 |
+
Planning trajectory predictions must contain exactly 10 `[x, y]` waypoints at 0.5-second intervals. Evaluation terminates with an error if a trajectory prediction does not follow this format.
|
| 155 |
+
|
| 156 |
+
## Citation
|
| 157 |
+
|
| 158 |
+
```bibtex
|
| 159 |
+
@InProceedings{Lu_2026_CVPR,
|
| 160 |
+
author = {Lu, Dongyue and Li, Rong and Liang, Ao and Kong, Lingdong and Yin, Wei and Ng, Lai Xing and Cottereau, Benoit R. and Chane, Camille Simon and Ooi, Wei Tsang},
|
| 161 |
+
title = {EventDrive: Event Cameras for Vision-Language Driving Intelligence},
|
| 162 |
+
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
|
| 163 |
+
year = {2026},
|
| 164 |
+
}
|
| 165 |
+
```
|
scripts/evaluation_perception.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import re
|
| 4 |
+
from collections import defaultdict
|
| 5 |
+
|
| 6 |
+
from tqdm import tqdm
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
CHOICE_SUBTASKS = ("option_letter", "label_text")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def clean_text(s: str):
|
| 13 |
+
"""Normalize whitespace and common answer prefixes."""
|
| 14 |
+
if not isinstance(s, str):
|
| 15 |
+
return ""
|
| 16 |
+
s = s.strip()
|
| 17 |
+
s = s.replace("Answer:", "").replace("answer:", "")
|
| 18 |
+
s = re.sub(r"[.\n\r]+", "", s)
|
| 19 |
+
s = re.sub(r"\s+", " ", s)
|
| 20 |
+
return s.strip()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def parse_option_letter(text):
|
| 24 |
+
"""Parse a split option-letter answer such as 'B'."""
|
| 25 |
+
text = clean_text(text)
|
| 26 |
+
return text.upper() if re.fullmatch(r"[A-Da-d]", text) else None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def normalize_label_text(text):
|
| 30 |
+
"""Normalize a split label-text answer such as 'Low light'."""
|
| 31 |
+
return clean_text(text).lower()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def group_split_choices(data):
|
| 35 |
+
groups = {}
|
| 36 |
+
for item in data:
|
| 37 |
+
original_id = item.get("original_id")
|
| 38 |
+
subtask = item.get("subtask")
|
| 39 |
+
if not original_id:
|
| 40 |
+
raise ValueError("Perception sample is missing original_id")
|
| 41 |
+
if subtask not in CHOICE_SUBTASKS:
|
| 42 |
+
raise ValueError(f"Missing or invalid perception subtask: {subtask!r}")
|
| 43 |
+
|
| 44 |
+
group = groups.setdefault(original_id, {})
|
| 45 |
+
if subtask in group:
|
| 46 |
+
raise ValueError(f"Duplicate perception subtask {subtask!r} for {original_id}")
|
| 47 |
+
group[subtask] = item
|
| 48 |
+
|
| 49 |
+
required = set(CHOICE_SUBTASKS)
|
| 50 |
+
for original_id, group in groups.items():
|
| 51 |
+
if set(group) != required:
|
| 52 |
+
raise ValueError(f"Incomplete perception subtask pair for {original_id}: {sorted(group)}")
|
| 53 |
+
return groups
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def evaluate(pred_json):
|
| 57 |
+
with open(pred_json, "r", encoding="utf-8") as f:
|
| 58 |
+
data = json.load(f)
|
| 59 |
+
|
| 60 |
+
if not data:
|
| 61 |
+
raise ValueError(f"No samples found in {pred_json}")
|
| 62 |
+
|
| 63 |
+
groups = group_split_choices(data)
|
| 64 |
+
total, correct = 0, 0
|
| 65 |
+
option_letter_correct, label_text_correct = 0, 0
|
| 66 |
+
mismatch_examples = []
|
| 67 |
+
category_stats = defaultdict(lambda: {"total": 0, "correct": 0})
|
| 68 |
+
|
| 69 |
+
for original_id, pair in tqdm(groups.items(), desc="Evaluating perception pairs"):
|
| 70 |
+
letter_item = pair["option_letter"]
|
| 71 |
+
label_item = pair["label_text"]
|
| 72 |
+
category = letter_item.get("category", "Unknown")
|
| 73 |
+
if label_item.get("category", "Unknown") != category:
|
| 74 |
+
raise ValueError(f"Mismatched perception categories for {original_id}")
|
| 75 |
+
|
| 76 |
+
gt_letter = parse_option_letter(letter_item["conversations"][1]["value"])
|
| 77 |
+
pred_letter = parse_option_letter(letter_item.get("model_output", ""))
|
| 78 |
+
gt_label = normalize_label_text(label_item["conversations"][1]["value"])
|
| 79 |
+
pred_label = normalize_label_text(label_item.get("model_output", ""))
|
| 80 |
+
if gt_letter is None or not gt_label:
|
| 81 |
+
raise ValueError(f"Invalid perception ground truth for {original_id}")
|
| 82 |
+
|
| 83 |
+
is_letter_correct = gt_letter == pred_letter
|
| 84 |
+
is_label_correct = gt_label == pred_label
|
| 85 |
+
is_joint_correct = is_letter_correct and is_label_correct
|
| 86 |
+
|
| 87 |
+
total += 1
|
| 88 |
+
category_stats[category]["total"] += 1
|
| 89 |
+
option_letter_correct += is_letter_correct
|
| 90 |
+
label_text_correct += is_label_correct
|
| 91 |
+
if is_joint_correct:
|
| 92 |
+
correct += 1
|
| 93 |
+
category_stats[category]["correct"] += 1
|
| 94 |
+
else:
|
| 95 |
+
mismatch_examples.append({
|
| 96 |
+
"original_id": original_id,
|
| 97 |
+
"image": letter_item["image"],
|
| 98 |
+
"category": category,
|
| 99 |
+
"gt": {
|
| 100 |
+
"option_letter": gt_letter,
|
| 101 |
+
"label_text": gt_label,
|
| 102 |
+
},
|
| 103 |
+
"pred": {
|
| 104 |
+
"option_letter": pred_letter,
|
| 105 |
+
"label_text": pred_label,
|
| 106 |
+
},
|
| 107 |
+
"model_output": {
|
| 108 |
+
"option_letter": letter_item.get("model_output", ""),
|
| 109 |
+
"label_text": label_item.get("model_output", ""),
|
| 110 |
+
},
|
| 111 |
+
})
|
| 112 |
+
|
| 113 |
+
overall_acc = correct / total * 100
|
| 114 |
+
option_letter_acc = option_letter_correct / total * 100
|
| 115 |
+
label_text_acc = label_text_correct / total * 100
|
| 116 |
+
|
| 117 |
+
print(f"\nInference samples: {len(data)}")
|
| 118 |
+
print(f"Original questions: {total}")
|
| 119 |
+
print(f"Overall accuracy (option_letter + label_text): {overall_acc:.2f}%")
|
| 120 |
+
print(f"Option-letter accuracy: {option_letter_acc:.2f}%")
|
| 121 |
+
print(f"Label-text accuracy: {label_text_acc:.2f}%")
|
| 122 |
+
print(f"Wrong original questions: {len(mismatch_examples)}")
|
| 123 |
+
|
| 124 |
+
print("\nCategory-wise Joint Accuracy:")
|
| 125 |
+
category_acc = {}
|
| 126 |
+
for category, stats in category_stats.items():
|
| 127 |
+
acc = stats["correct"] / stats["total"] * 100 if stats["total"] else 0.0
|
| 128 |
+
category_acc[category] = {
|
| 129 |
+
"total": stats["total"],
|
| 130 |
+
"correct": stats["correct"],
|
| 131 |
+
"accuracy (%)": round(acc, 2),
|
| 132 |
+
}
|
| 133 |
+
print(f" {category:20s}: {acc:5.2f}% ({stats['correct']}/{stats['total']})")
|
| 134 |
+
|
| 135 |
+
result_summary = {
|
| 136 |
+
"overall": {
|
| 137 |
+
"inference_samples": len(data),
|
| 138 |
+
"total": total,
|
| 139 |
+
"correct": correct,
|
| 140 |
+
"accuracy (%)": round(overall_acc, 2),
|
| 141 |
+
"option_letter_accuracy (%)": round(option_letter_acc, 2),
|
| 142 |
+
"label_text_accuracy (%)": round(label_text_acc, 2),
|
| 143 |
+
},
|
| 144 |
+
"categories": category_acc,
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
error_path = pred_json.replace(".json", "_errors.json")
|
| 148 |
+
with open(error_path, "w", encoding="utf-8") as f:
|
| 149 |
+
json.dump(mismatch_examples, f, indent=2, ensure_ascii=False)
|
| 150 |
+
|
| 151 |
+
result_path = pred_json.replace(".json", "_accuracy.json")
|
| 152 |
+
with open(result_path, "w", encoding="utf-8") as f:
|
| 153 |
+
json.dump(result_summary, f, indent=2, ensure_ascii=False)
|
| 154 |
+
|
| 155 |
+
print(f"\nError samples saved to {error_path}")
|
| 156 |
+
print(f"Accuracy summary saved to {result_path}")
|
| 157 |
+
return result_summary
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def parse_args():
|
| 161 |
+
parser = argparse.ArgumentParser(description="Evaluate split EventDrive perception predictions.")
|
| 162 |
+
parser.add_argument("--pred-json", required=True, help="Path to split perception JSON with model_output fields.")
|
| 163 |
+
return parser.parse_args()
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
if __name__ == "__main__":
|
| 167 |
+
args = parse_args()
|
| 168 |
+
evaluate(args.pred_json)
|
scripts/evaluation_planning.py
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import re
|
| 4 |
+
from tqdm import tqdm
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
HIGHLEVEL_CATEGORIES = {
|
| 8 |
+
"speed": ["KEEP", "ACCELERATE", "DECELERATE", "STOP"],
|
| 9 |
+
"path": ["STRAIGHT", "LEFT_TURN", "RIGHT_TURN", "LEFT_CHANGE", "RIGHT_CHANGE", "UNKNOWN"],
|
| 10 |
+
}
|
| 11 |
+
REQUIRED_HIGHLEVEL_SUBTASKS = set(HIGHLEVEL_CATEGORIES)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def get_numpy():
|
| 15 |
+
import numpy as np
|
| 16 |
+
return np
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def clean_text(s: str):
|
| 20 |
+
if not isinstance(s, str):
|
| 21 |
+
return ""
|
| 22 |
+
s = s.strip()
|
| 23 |
+
s = re.sub(r"[.\n\r]+", " ", s)
|
| 24 |
+
s = re.sub(r"\s+", " ", s)
|
| 25 |
+
return s.strip()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def parse_highlevel_prediction(text, subtask):
|
| 29 |
+
if subtask not in HIGHLEVEL_CATEGORIES:
|
| 30 |
+
raise ValueError(f"Unexpected planning high-level subtask: {subtask!r}")
|
| 31 |
+
|
| 32 |
+
text = clean_text(text).upper()
|
| 33 |
+
categories = HIGHLEVEL_CATEGORIES[subtask]
|
| 34 |
+
matches = [
|
| 35 |
+
word for word in categories
|
| 36 |
+
if re.search(rf"(?<![A-Z_]){re.escape(word)}(?![A-Z_])", text)
|
| 37 |
+
]
|
| 38 |
+
return matches[0] if len(matches) == 1 else None
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def parse_traj(text):
|
| 42 |
+
"""
|
| 43 |
+
Parse trajectory text like "[0.001, -0.002], [0.003, -0.004]".
|
| 44 |
+
Returns an array with shape [N, 2].
|
| 45 |
+
"""
|
| 46 |
+
np = get_numpy()
|
| 47 |
+
if not isinstance(text, str):
|
| 48 |
+
return np.zeros((0, 2))
|
| 49 |
+
|
| 50 |
+
# Match integers, floats, and scientific notation.
|
| 51 |
+
nums = re.findall(r"[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?", text)
|
| 52 |
+
if len(nums) < 2:
|
| 53 |
+
return np.zeros((0, 2))
|
| 54 |
+
if len(nums) % 2 != 0:
|
| 55 |
+
return np.zeros((0, 2))
|
| 56 |
+
|
| 57 |
+
arr = np.array(nums, dtype=float)
|
| 58 |
+
arr = arr.reshape(-1, 2)
|
| 59 |
+
return arr
|
| 60 |
+
|
| 61 |
+
def compute_l2_error(gt, pred, dt=0.5):
|
| 62 |
+
"""
|
| 63 |
+
gt, pred: np.array of shape [10, 2]
|
| 64 |
+
Returns: {1s, 3s, 5s, mean}
|
| 65 |
+
"""
|
| 66 |
+
if gt.shape != pred.shape or gt.shape[0] == 0:
|
| 67 |
+
return {"1s": None, "3s": None, "5s": None, "mean": None}
|
| 68 |
+
|
| 69 |
+
np = get_numpy()
|
| 70 |
+
errors = np.linalg.norm(gt - pred, axis=1)
|
| 71 |
+
time_horizons = [1.0, 3.0, 5.0]
|
| 72 |
+
results = {}
|
| 73 |
+
for t in time_horizons:
|
| 74 |
+
idx = int(t / dt) - 1
|
| 75 |
+
idx = min(idx, len(errors) - 1)
|
| 76 |
+
results[f"{t:.0f}s"] = float(errors[idx])
|
| 77 |
+
results["mean"] = float(np.mean(errors))
|
| 78 |
+
return results
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def evaluate(pred_json):
|
| 82 |
+
with open(pred_json, "r", encoding="utf-8") as f:
|
| 83 |
+
data = json.load(f)
|
| 84 |
+
|
| 85 |
+
if not data:
|
| 86 |
+
raise ValueError(f"No samples found in {pred_json}")
|
| 87 |
+
|
| 88 |
+
highlevel_totals = {subtask: 0 for subtask in HIGHLEVEL_CATEGORIES}
|
| 89 |
+
highlevel_correct = {subtask: 0 for subtask in HIGHLEVEL_CATEGORIES}
|
| 90 |
+
highlevel_classwise = {
|
| 91 |
+
subtask: {category: {"total": 0, "correct": 0} for category in categories}
|
| 92 |
+
for subtask, categories in HIGHLEVEL_CATEGORIES.items()
|
| 93 |
+
}
|
| 94 |
+
highlevel_groups = {}
|
| 95 |
+
trajectory_items = []
|
| 96 |
+
traj_errors = []
|
| 97 |
+
|
| 98 |
+
mismatch_high = []
|
| 99 |
+
|
| 100 |
+
for item in data:
|
| 101 |
+
category = item["category"]
|
| 102 |
+
|
| 103 |
+
if category == "Planning-HighLevel":
|
| 104 |
+
original_id = item.get("original_id")
|
| 105 |
+
subtask = item.get("subtask")
|
| 106 |
+
if not original_id:
|
| 107 |
+
raise ValueError("Planning high-level sample is missing original_id")
|
| 108 |
+
if subtask not in HIGHLEVEL_CATEGORIES:
|
| 109 |
+
raise ValueError(f"Missing or invalid planning high-level subtask: {subtask!r}")
|
| 110 |
+
|
| 111 |
+
group = highlevel_groups.setdefault(original_id, {})
|
| 112 |
+
if subtask in group:
|
| 113 |
+
raise ValueError(f"Duplicate planning high-level subtask {subtask!r} for {original_id}")
|
| 114 |
+
group[subtask] = item
|
| 115 |
+
elif category == "Planning-Trajectory":
|
| 116 |
+
trajectory_items.append(item)
|
| 117 |
+
else:
|
| 118 |
+
raise ValueError(f"Unexpected planning category: {category!r}")
|
| 119 |
+
|
| 120 |
+
for original_id, group in highlevel_groups.items():
|
| 121 |
+
if set(group) != REQUIRED_HIGHLEVEL_SUBTASKS:
|
| 122 |
+
raise ValueError(f"Incomplete planning high-level subtask pair for {original_id}: {sorted(group)}")
|
| 123 |
+
|
| 124 |
+
joint_correct = 0
|
| 125 |
+
for original_id, group in tqdm(highlevel_groups.items(), desc="Evaluating planning intent pairs"):
|
| 126 |
+
is_joint_correct = True
|
| 127 |
+
for subtask, item in group.items():
|
| 128 |
+
gt_raw = item["conversations"][1]["value"]
|
| 129 |
+
pred_raw = item.get("model_output", "")
|
| 130 |
+
gt = parse_highlevel_prediction(gt_raw, subtask)
|
| 131 |
+
pred = parse_highlevel_prediction(pred_raw, subtask)
|
| 132 |
+
if gt is None:
|
| 133 |
+
raise ValueError(f"Invalid planning {subtask} ground-truth answer: {gt_raw!r}")
|
| 134 |
+
|
| 135 |
+
highlevel_totals[subtask] += 1
|
| 136 |
+
highlevel_classwise[subtask][gt]["total"] += 1
|
| 137 |
+
is_correct = gt == pred
|
| 138 |
+
is_joint_correct = is_joint_correct and is_correct
|
| 139 |
+
if is_correct:
|
| 140 |
+
highlevel_correct[subtask] += 1
|
| 141 |
+
highlevel_classwise[subtask][gt]["correct"] += 1
|
| 142 |
+
else:
|
| 143 |
+
mismatch_high.append({
|
| 144 |
+
"original_id": original_id,
|
| 145 |
+
"image": item["image"],
|
| 146 |
+
"subtask": subtask,
|
| 147 |
+
"gt": gt,
|
| 148 |
+
"pred": pred,
|
| 149 |
+
"model_output": pred_raw,
|
| 150 |
+
})
|
| 151 |
+
joint_correct += is_joint_correct
|
| 152 |
+
|
| 153 |
+
for item in tqdm(trajectory_items, desc="Evaluating planning trajectories"):
|
| 154 |
+
gt_raw = item["conversations"][1]["value"]
|
| 155 |
+
pred_raw = item.get("model_output", "")
|
| 156 |
+
gt_traj = parse_traj(gt_raw)
|
| 157 |
+
pred_traj = parse_traj(pred_raw)
|
| 158 |
+
if gt_traj.shape[0] != 10:
|
| 159 |
+
raise ValueError(f"Invalid planning trajectory ground truth for {item['image']}: {gt_raw!r}")
|
| 160 |
+
if pred_traj.shape[0] != 10:
|
| 161 |
+
raise ValueError(
|
| 162 |
+
f"Invalid planning trajectory prediction for {item['image']}: "
|
| 163 |
+
f"expected exactly 10 waypoints, got {pred_traj.shape[0]}"
|
| 164 |
+
)
|
| 165 |
+
traj_errors.append(compute_l2_error(gt_traj, pred_traj))
|
| 166 |
+
|
| 167 |
+
results = {}
|
| 168 |
+
total_high = sum(highlevel_totals.values())
|
| 169 |
+
original_questions = len(highlevel_groups)
|
| 170 |
+
|
| 171 |
+
if total_high > 0:
|
| 172 |
+
results["HighLevel"] = {
|
| 173 |
+
"total": total_high,
|
| 174 |
+
"original_questions": original_questions,
|
| 175 |
+
"overall_accuracy (%)": round(sum(highlevel_correct.values()) / total_high * 100, 2),
|
| 176 |
+
"joint_correct": joint_correct,
|
| 177 |
+
"joint_accuracy (%)": round(joint_correct / original_questions * 100, 2),
|
| 178 |
+
"subtasks": {
|
| 179 |
+
subtask: {
|
| 180 |
+
"total": highlevel_totals[subtask],
|
| 181 |
+
"accuracy (%)": round(highlevel_correct[subtask] / highlevel_totals[subtask] * 100, 2)
|
| 182 |
+
if highlevel_totals[subtask]
|
| 183 |
+
else None,
|
| 184 |
+
"classwise": {
|
| 185 |
+
category: round(stats["correct"] / stats["total"] * 100, 2) if stats["total"] else None
|
| 186 |
+
for category, stats in highlevel_classwise[subtask].items()
|
| 187 |
+
},
|
| 188 |
+
}
|
| 189 |
+
for subtask in HIGHLEVEL_CATEGORIES
|
| 190 |
+
},
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
total_traj = len(trajectory_items)
|
| 194 |
+
if total_traj > 0:
|
| 195 |
+
results["Trajectory"] = {
|
| 196 |
+
"total": total_traj,
|
| 197 |
+
"valid_predictions": total_traj,
|
| 198 |
+
"invalid_predictions": 0,
|
| 199 |
+
}
|
| 200 |
+
if traj_errors:
|
| 201 |
+
np = get_numpy()
|
| 202 |
+
traj_errs_np = {
|
| 203 |
+
k: np.mean([error[k] for error in traj_errors if error[k] is not None])
|
| 204 |
+
for k in ["1s", "3s", "5s", "mean"]
|
| 205 |
+
}
|
| 206 |
+
results["Trajectory"]["avg_L2_error_m"] = {k: round(v, 4) for k, v in traj_errs_np.items()}
|
| 207 |
+
|
| 208 |
+
print("\n=== Evaluation Summary ===")
|
| 209 |
+
print(json.dumps(results, indent=2))
|
| 210 |
+
|
| 211 |
+
result_path = pred_json.replace(".json", "_eval_results.json")
|
| 212 |
+
with open(result_path, "w", encoding="utf-8") as f:
|
| 213 |
+
json.dump(results, f, indent=2, ensure_ascii=False)
|
| 214 |
+
|
| 215 |
+
with open(pred_json.replace(".json", "_highlevel_mismatch.json"), "w", encoding="utf-8") as f:
|
| 216 |
+
json.dump(mismatch_high, f, indent=2, ensure_ascii=False)
|
| 217 |
+
print(f"Evaluation summary saved to {result_path}")
|
| 218 |
+
|
| 219 |
+
return results
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
def parse_args():
|
| 223 |
+
parser = argparse.ArgumentParser(description="Evaluate EventDrive planning task results.")
|
| 224 |
+
parser.add_argument("--pred-json", required=True, help="Path to prediction JSON with model_output fields.")
|
| 225 |
+
return parser.parse_args()
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
if __name__ == "__main__":
|
| 229 |
+
args = parse_args()
|
| 230 |
+
evaluate(args.pred_json)
|
scripts/evaluation_prediction.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import re
|
| 4 |
+
from tqdm import tqdm
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
SUBTASK_CATEGORIES = {
|
| 8 |
+
"speed": ["KEEP", "ACCELERATE", "DECELERATE", "STOP"],
|
| 9 |
+
"path": ["LEFT", "RIGHT", "STRAIGHT", "UNKNOWN"],
|
| 10 |
+
}
|
| 11 |
+
REQUIRED_SUBTASKS = set(SUBTASK_CATEGORIES)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def clean_text(s: str):
|
| 15 |
+
"""Normalize whitespace and punctuation."""
|
| 16 |
+
if not isinstance(s, str):
|
| 17 |
+
return ""
|
| 18 |
+
s = s.strip()
|
| 19 |
+
s = re.sub(r"[.\n\r]+", " ", s)
|
| 20 |
+
s = re.sub(r"\s+", " ", s)
|
| 21 |
+
return s.strip()
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def parse_prediction(text, subtask):
|
| 25 |
+
"""
|
| 26 |
+
Parse one split-task prediction:
|
| 27 |
+
"B ACCELERATE" -> "ACCELERATE"
|
| 28 |
+
"C STRAIGHT" -> "STRAIGHT"
|
| 29 |
+
"""
|
| 30 |
+
if subtask not in SUBTASK_CATEGORIES:
|
| 31 |
+
raise ValueError(f"Unexpected prediction subtask: {subtask!r}")
|
| 32 |
+
|
| 33 |
+
text = clean_text(text).upper()
|
| 34 |
+
categories = SUBTASK_CATEGORIES[subtask]
|
| 35 |
+
matches = [
|
| 36 |
+
word for word in categories
|
| 37 |
+
if re.search(rf"(?<![A-Z_]){re.escape(word)}(?![A-Z_])", text)
|
| 38 |
+
]
|
| 39 |
+
return matches[0] if len(matches) == 1 else None
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def group_split_samples(data):
|
| 43 |
+
groups = {}
|
| 44 |
+
for item in data:
|
| 45 |
+
original_id = item.get("original_id")
|
| 46 |
+
subtask = item.get("subtask")
|
| 47 |
+
if not original_id:
|
| 48 |
+
raise ValueError("Prediction sample is missing original_id")
|
| 49 |
+
if subtask not in SUBTASK_CATEGORIES:
|
| 50 |
+
raise ValueError(f"Missing or invalid prediction subtask: {subtask!r}")
|
| 51 |
+
|
| 52 |
+
group = groups.setdefault(original_id, {})
|
| 53 |
+
if subtask in group:
|
| 54 |
+
raise ValueError(f"Duplicate prediction subtask {subtask!r} for {original_id}")
|
| 55 |
+
group[subtask] = item
|
| 56 |
+
|
| 57 |
+
for original_id, group in groups.items():
|
| 58 |
+
if set(group) != REQUIRED_SUBTASKS:
|
| 59 |
+
raise ValueError(f"Incomplete prediction subtask pair for {original_id}: {sorted(group)}")
|
| 60 |
+
return groups
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def evaluate(pred_json):
|
| 64 |
+
with open(pred_json, "r", encoding="utf-8") as f:
|
| 65 |
+
data = json.load(f)
|
| 66 |
+
|
| 67 |
+
if not data:
|
| 68 |
+
raise ValueError(f"No samples found in {pred_json}")
|
| 69 |
+
|
| 70 |
+
groups = group_split_samples(data)
|
| 71 |
+
totals = {subtask: 0 for subtask in SUBTASK_CATEGORIES}
|
| 72 |
+
correct = {subtask: 0 for subtask in SUBTASK_CATEGORIES}
|
| 73 |
+
classwise = {
|
| 74 |
+
subtask: {category: {"total": 0, "correct": 0} for category in categories}
|
| 75 |
+
for subtask, categories in SUBTASK_CATEGORIES.items()
|
| 76 |
+
}
|
| 77 |
+
mismatch_examples = []
|
| 78 |
+
joint_correct = 0
|
| 79 |
+
|
| 80 |
+
for original_id, group in tqdm(groups.items(), desc="Evaluating prediction pairs"):
|
| 81 |
+
is_joint_correct = True
|
| 82 |
+
for subtask, item in group.items():
|
| 83 |
+
gt_raw = item["conversations"][1]["value"]
|
| 84 |
+
pred_raw = item.get("model_output", "")
|
| 85 |
+
|
| 86 |
+
gt = parse_prediction(gt_raw, subtask)
|
| 87 |
+
pred = parse_prediction(pred_raw, subtask)
|
| 88 |
+
if gt is None:
|
| 89 |
+
raise ValueError(f"Invalid {subtask} ground-truth answer: {gt_raw!r}")
|
| 90 |
+
|
| 91 |
+
totals[subtask] += 1
|
| 92 |
+
classwise[subtask][gt]["total"] += 1
|
| 93 |
+
is_correct = gt == pred
|
| 94 |
+
is_joint_correct = is_joint_correct and is_correct
|
| 95 |
+
if is_correct:
|
| 96 |
+
correct[subtask] += 1
|
| 97 |
+
classwise[subtask][gt]["correct"] += 1
|
| 98 |
+
else:
|
| 99 |
+
mismatch_examples.append({
|
| 100 |
+
"original_id": original_id,
|
| 101 |
+
"image": item["image"],
|
| 102 |
+
"bbox_2d": item.get("bbox_2d", {}),
|
| 103 |
+
"subtask": subtask,
|
| 104 |
+
"gt": gt,
|
| 105 |
+
"pred": pred,
|
| 106 |
+
"model_output": pred_raw,
|
| 107 |
+
})
|
| 108 |
+
joint_correct += is_joint_correct
|
| 109 |
+
|
| 110 |
+
total = sum(totals.values())
|
| 111 |
+
original_questions = len(groups)
|
| 112 |
+
overall_acc = sum(correct.values()) / total * 100
|
| 113 |
+
joint_acc = joint_correct / original_questions * 100
|
| 114 |
+
|
| 115 |
+
print(f"\nTotal samples: {total}")
|
| 116 |
+
print(f"Original questions: {original_questions}")
|
| 117 |
+
for subtask in SUBTASK_CATEGORIES:
|
| 118 |
+
accuracy = correct[subtask] / totals[subtask] * 100 if totals[subtask] else 0.0
|
| 119 |
+
print(f"{subtask.upper()} accuracy: {accuracy:.2f}% ({correct[subtask]}/{totals[subtask]})")
|
| 120 |
+
print(f"Overall accuracy: {overall_acc:.2f}%")
|
| 121 |
+
print(f"Joint accuracy: {joint_acc:.2f}% ({joint_correct}/{original_questions})")
|
| 122 |
+
print(f"Wrong examples: {len(mismatch_examples)}")
|
| 123 |
+
|
| 124 |
+
result_summary = {
|
| 125 |
+
"total": total,
|
| 126 |
+
"original_questions": original_questions,
|
| 127 |
+
"overall_accuracy (%)": round(overall_acc, 2),
|
| 128 |
+
"joint_correct": joint_correct,
|
| 129 |
+
"joint_accuracy (%)": round(joint_acc, 2),
|
| 130 |
+
"subtasks": {
|
| 131 |
+
subtask: {
|
| 132 |
+
"total": totals[subtask],
|
| 133 |
+
"accuracy (%)": round(correct[subtask] / totals[subtask] * 100, 2) if totals[subtask] else None,
|
| 134 |
+
"classwise": {
|
| 135 |
+
category: round(stats["correct"] / stats["total"] * 100, 2) if stats["total"] else None
|
| 136 |
+
for category, stats in classwise[subtask].items()
|
| 137 |
+
},
|
| 138 |
+
}
|
| 139 |
+
for subtask in SUBTASK_CATEGORIES
|
| 140 |
+
},
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
error_path = pred_json.replace(".json", "_errors.json")
|
| 144 |
+
with open(error_path, "w", encoding="utf-8") as f:
|
| 145 |
+
json.dump(mismatch_examples, f, indent=2, ensure_ascii=False)
|
| 146 |
+
|
| 147 |
+
result_path = pred_json.replace(".json", "_accuracy.json")
|
| 148 |
+
with open(result_path, "w", encoding="utf-8") as f:
|
| 149 |
+
json.dump(result_summary, f, indent=2, ensure_ascii=False)
|
| 150 |
+
|
| 151 |
+
print(f"\nError samples saved to {error_path}")
|
| 152 |
+
print(f"Accuracy summary saved to {result_path}")
|
| 153 |
+
|
| 154 |
+
return result_summary
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
def parse_args():
|
| 158 |
+
parser = argparse.ArgumentParser(description="Evaluate EventDrive prediction task results.")
|
| 159 |
+
parser.add_argument("--pred-json", required=True, help="Path to prediction JSON with model_output fields.")
|
| 160 |
+
return parser.parse_args()
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
if __name__ == "__main__":
|
| 164 |
+
args = parse_args()
|
| 165 |
+
evaluate(args.pred_json)
|
scripts/evaluation_understanding.py
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
import json
|
| 3 |
+
import re
|
| 4 |
+
from collections import defaultdict
|
| 5 |
+
|
| 6 |
+
from tqdm import tqdm
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
DEFAULT_IOU_THRESH = 0.6
|
| 10 |
+
CHOICE_SUBTASKS = ("option_letter", "label_text")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def clean_text(s: str):
|
| 14 |
+
"""Normalize whitespace and common answer prefixes."""
|
| 15 |
+
if not isinstance(s, str):
|
| 16 |
+
return ""
|
| 17 |
+
s = s.strip()
|
| 18 |
+
s = s.replace("Answer:", "").replace("answer:", "")
|
| 19 |
+
s = re.sub(r"[.\n\r]+", "", s)
|
| 20 |
+
s = re.sub(r"\s+", " ", s)
|
| 21 |
+
return s.strip()
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def parse_option_letter(text):
|
| 25 |
+
"""Parse a split option-letter answer such as 'B'."""
|
| 26 |
+
text = clean_text(text)
|
| 27 |
+
return text.upper() if re.fullmatch(r"[A-Da-d]", text) else None
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def normalize_label_text(text):
|
| 31 |
+
"""Normalize a split label-text answer."""
|
| 32 |
+
return clean_text(text).lower()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def parse_bbox(bbox_str):
|
| 36 |
+
"""Parse prediction text in 'x,y,w,h' format."""
|
| 37 |
+
try:
|
| 38 |
+
nums = re.findall(r"[-+]?\d*\.?\d+", bbox_str)
|
| 39 |
+
if len(nums) < 4:
|
| 40 |
+
return None
|
| 41 |
+
nums = nums[:4]
|
| 42 |
+
x, y, w, h = map(float, nums)
|
| 43 |
+
if w <= 0 or h <= 0:
|
| 44 |
+
return None
|
| 45 |
+
return [x, y, w, h]
|
| 46 |
+
except Exception:
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def bbox_iou(box1, box2):
|
| 51 |
+
"""Compute IoU for boxes in [x, y, w, h] format."""
|
| 52 |
+
x1_min, y1_min = box1[0], box1[1]
|
| 53 |
+
x1_max, y1_max = box1[0] + box1[2], box1[1] + box1[3]
|
| 54 |
+
x2_min, y2_min = box2[0], box2[1]
|
| 55 |
+
x2_max, y2_max = box2[0] + box2[2], box2[1] + box2[3]
|
| 56 |
+
|
| 57 |
+
inter_x1 = max(x1_min, x2_min)
|
| 58 |
+
inter_y1 = max(y1_min, y2_min)
|
| 59 |
+
inter_x2 = min(x1_max, x2_max)
|
| 60 |
+
inter_y2 = min(y1_max, y2_max)
|
| 61 |
+
inter_w = max(0, inter_x2 - inter_x1)
|
| 62 |
+
inter_h = max(0, inter_y2 - inter_y1)
|
| 63 |
+
inter_area = inter_w * inter_h
|
| 64 |
+
area1 = box1[2] * box1[3]
|
| 65 |
+
area2 = box2[2] * box2[3]
|
| 66 |
+
union = area1 + area2 - inter_area
|
| 67 |
+
return inter_area / union if union > 0 else 0.0
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def is_text_match(gt_text, pred_text):
|
| 71 |
+
"""Apply the lenient text matching rule to a split label-text answer."""
|
| 72 |
+
if not gt_text or not pred_text:
|
| 73 |
+
return False
|
| 74 |
+
|
| 75 |
+
gt = gt_text.strip().lower()
|
| 76 |
+
pred = pred_text.strip().lower()
|
| 77 |
+
|
| 78 |
+
gt = re.sub(r"\b(a|an|the)\b", "", gt)
|
| 79 |
+
pred = re.sub(r"\b(a|an|the)\b", "", pred)
|
| 80 |
+
|
| 81 |
+
gt = re.sub(r"[^a-z0-9\s]", " ", gt)
|
| 82 |
+
pred = re.sub(r"[^a-z0-9\s]", " ", pred)
|
| 83 |
+
gt = re.sub(r"\s+", " ", gt).strip()
|
| 84 |
+
pred = re.sub(r"\s+", " ", pred).strip()
|
| 85 |
+
|
| 86 |
+
gt_tokens = set(gt.split())
|
| 87 |
+
pred_tokens = set(pred.split())
|
| 88 |
+
overlap = len(gt_tokens & pred_tokens)
|
| 89 |
+
union = len(gt_tokens | pred_tokens)
|
| 90 |
+
return overlap / union > 0.8 if union else False
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def group_split_samples(data):
|
| 94 |
+
choice_groups = {}
|
| 95 |
+
grounding_items = []
|
| 96 |
+
grounding_ids = set()
|
| 97 |
+
|
| 98 |
+
for item in data:
|
| 99 |
+
original_id = item.get("original_id")
|
| 100 |
+
subtask = item.get("subtask")
|
| 101 |
+
category = item.get("category", "Unknown")
|
| 102 |
+
if not original_id:
|
| 103 |
+
raise ValueError("Understanding sample is missing original_id")
|
| 104 |
+
|
| 105 |
+
if category.lower() == "grounding":
|
| 106 |
+
if subtask != "grounding":
|
| 107 |
+
raise ValueError(f"Missing or invalid grounding subtask for {original_id}: {subtask!r}")
|
| 108 |
+
if original_id in grounding_ids:
|
| 109 |
+
raise ValueError(f"Duplicate grounding sample for {original_id}")
|
| 110 |
+
grounding_ids.add(original_id)
|
| 111 |
+
grounding_items.append(item)
|
| 112 |
+
continue
|
| 113 |
+
|
| 114 |
+
if subtask not in CHOICE_SUBTASKS:
|
| 115 |
+
raise ValueError(f"Missing or invalid understanding QA subtask: {subtask!r}")
|
| 116 |
+
group = choice_groups.setdefault(original_id, {})
|
| 117 |
+
if subtask in group:
|
| 118 |
+
raise ValueError(f"Duplicate understanding subtask {subtask!r} for {original_id}")
|
| 119 |
+
group[subtask] = item
|
| 120 |
+
|
| 121 |
+
required = set(CHOICE_SUBTASKS)
|
| 122 |
+
for original_id, group in choice_groups.items():
|
| 123 |
+
if set(group) != required:
|
| 124 |
+
raise ValueError(f"Incomplete understanding subtask pair for {original_id}: {sorted(group)}")
|
| 125 |
+
return choice_groups, grounding_items
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def evaluate(pred_json, iou_thresh=DEFAULT_IOU_THRESH):
|
| 129 |
+
with open(pred_json, "r", encoding="utf-8") as f:
|
| 130 |
+
data = json.load(f)
|
| 131 |
+
|
| 132 |
+
if not data:
|
| 133 |
+
raise ValueError(f"No samples found in {pred_json}")
|
| 134 |
+
|
| 135 |
+
choice_groups, grounding_items = group_split_samples(data)
|
| 136 |
+
category_stats = defaultdict(lambda: {"total": 0, "correct": 0})
|
| 137 |
+
mismatch_examples = []
|
| 138 |
+
|
| 139 |
+
qa_correct = 0
|
| 140 |
+
option_letter_correct = 0
|
| 141 |
+
label_text_correct = 0
|
| 142 |
+
label_text_exact_correct = 0
|
| 143 |
+
|
| 144 |
+
for original_id, pair in tqdm(choice_groups.items(), desc="Evaluating understanding QA pairs"):
|
| 145 |
+
letter_item = pair["option_letter"]
|
| 146 |
+
label_item = pair["label_text"]
|
| 147 |
+
category = letter_item.get("category", "Unknown")
|
| 148 |
+
if label_item.get("category", "Unknown") != category:
|
| 149 |
+
raise ValueError(f"Mismatched understanding categories for {original_id}")
|
| 150 |
+
|
| 151 |
+
gt_letter = parse_option_letter(letter_item["conversations"][1]["value"])
|
| 152 |
+
pred_letter = parse_option_letter(letter_item.get("model_output", ""))
|
| 153 |
+
gt_label = label_item["conversations"][1]["value"]
|
| 154 |
+
pred_label = label_item.get("model_output", "")
|
| 155 |
+
if gt_letter is None or not normalize_label_text(gt_label):
|
| 156 |
+
raise ValueError(f"Invalid understanding ground truth for {original_id}")
|
| 157 |
+
|
| 158 |
+
is_letter_correct = gt_letter == pred_letter
|
| 159 |
+
is_label_correct = is_text_match(gt_label, pred_label)
|
| 160 |
+
is_label_exact = normalize_label_text(gt_label) == normalize_label_text(pred_label)
|
| 161 |
+
is_joint_correct = is_letter_correct and is_label_correct
|
| 162 |
+
|
| 163 |
+
category_stats[category]["total"] += 1
|
| 164 |
+
option_letter_correct += is_letter_correct
|
| 165 |
+
label_text_correct += is_label_correct
|
| 166 |
+
label_text_exact_correct += is_label_exact
|
| 167 |
+
if is_joint_correct:
|
| 168 |
+
qa_correct += 1
|
| 169 |
+
category_stats[category]["correct"] += 1
|
| 170 |
+
else:
|
| 171 |
+
mismatch_examples.append({
|
| 172 |
+
"original_id": original_id,
|
| 173 |
+
"image": letter_item["image"],
|
| 174 |
+
"category": category,
|
| 175 |
+
"gt": {
|
| 176 |
+
"option_letter": gt_letter,
|
| 177 |
+
"label_text": gt_label,
|
| 178 |
+
},
|
| 179 |
+
"pred": {
|
| 180 |
+
"option_letter": pred_letter,
|
| 181 |
+
"label_text": pred_label,
|
| 182 |
+
},
|
| 183 |
+
"model_output": {
|
| 184 |
+
"option_letter": letter_item.get("model_output", ""),
|
| 185 |
+
"label_text": pred_label,
|
| 186 |
+
},
|
| 187 |
+
})
|
| 188 |
+
|
| 189 |
+
correct_gd = 0
|
| 190 |
+
iou_sum = 0.0
|
| 191 |
+
for item in tqdm(grounding_items, desc="Evaluating understanding grounding"):
|
| 192 |
+
category = item.get("category", "Grounding")
|
| 193 |
+
gt_bbox = item.get("gt_bbox", {})
|
| 194 |
+
try:
|
| 195 |
+
gt_box = [gt_bbox["x"], gt_bbox["y"], gt_bbox["w"], gt_bbox["h"]]
|
| 196 |
+
except (KeyError, TypeError) as exc:
|
| 197 |
+
raise ValueError(f"Invalid grounding ground truth for {item['original_id']}") from exc
|
| 198 |
+
pred_raw = item.get("model_output", "")
|
| 199 |
+
pred_box = parse_bbox(pred_raw)
|
| 200 |
+
|
| 201 |
+
category_stats[category]["total"] += 1
|
| 202 |
+
if pred_box is not None:
|
| 203 |
+
iou = bbox_iou(pred_box, gt_box)
|
| 204 |
+
iou_sum += iou
|
| 205 |
+
if iou >= iou_thresh:
|
| 206 |
+
correct_gd += 1
|
| 207 |
+
category_stats[category]["correct"] += 1
|
| 208 |
+
else:
|
| 209 |
+
mismatch_examples.append({
|
| 210 |
+
"original_id": item["original_id"],
|
| 211 |
+
"image": item["image"],
|
| 212 |
+
"category": category,
|
| 213 |
+
"gt_bbox": gt_box,
|
| 214 |
+
"pred_bbox": pred_box,
|
| 215 |
+
"iou": round(iou, 3),
|
| 216 |
+
})
|
| 217 |
+
else:
|
| 218 |
+
mismatch_examples.append({
|
| 219 |
+
"original_id": item["original_id"],
|
| 220 |
+
"image": item["image"],
|
| 221 |
+
"category": category,
|
| 222 |
+
"gt_bbox": gt_box,
|
| 223 |
+
"pred_bbox": "Invalid",
|
| 224 |
+
"iou": 0.0,
|
| 225 |
+
})
|
| 226 |
+
|
| 227 |
+
qa_total = len(choice_groups)
|
| 228 |
+
gd_total = len(grounding_items)
|
| 229 |
+
qa_acc = qa_correct / qa_total * 100 if qa_total else 0.0
|
| 230 |
+
option_letter_acc = option_letter_correct / qa_total * 100 if qa_total else 0.0
|
| 231 |
+
label_text_acc = label_text_correct / qa_total * 100 if qa_total else 0.0
|
| 232 |
+
label_text_exact_acc = label_text_exact_correct / qa_total * 100 if qa_total else 0.0
|
| 233 |
+
gd_acc = correct_gd / gd_total * 100 if gd_total else 0.0
|
| 234 |
+
avg_iou = iou_sum / gd_total if gd_total else 0.0
|
| 235 |
+
|
| 236 |
+
print("\n========== QA Part ==========")
|
| 237 |
+
print(f"Inference samples: {qa_total * 2}")
|
| 238 |
+
print(f"Original questions: {qa_total}")
|
| 239 |
+
print(f"Overall accuracy (option_letter + label_text): {qa_acc:.2f}%")
|
| 240 |
+
print(f"Option-letter accuracy: {option_letter_acc:.2f}%")
|
| 241 |
+
print(f"Label-text soft-match accuracy: {label_text_acc:.2f}%")
|
| 242 |
+
print(f"Label-text exact accuracy: {label_text_exact_acc:.2f}%")
|
| 243 |
+
|
| 244 |
+
print("\n========== Grounding Part ==========")
|
| 245 |
+
print(f"Samples: {gd_total}")
|
| 246 |
+
print(f"Accuracy (IoU >= {iou_thresh}): {gd_acc:.2f}%")
|
| 247 |
+
print(f"Average IoU: {avg_iou:.3f}")
|
| 248 |
+
|
| 249 |
+
print("\nCategory-wise Accuracy:")
|
| 250 |
+
category_acc = {}
|
| 251 |
+
for category, stats in category_stats.items():
|
| 252 |
+
acc = stats["correct"] / stats["total"] * 100 if stats["total"] else 0.0
|
| 253 |
+
category_acc[category] = {
|
| 254 |
+
"total": stats["total"],
|
| 255 |
+
"correct": stats["correct"],
|
| 256 |
+
"accuracy (%)": round(acc, 2),
|
| 257 |
+
}
|
| 258 |
+
print(f" {category:20s}: {acc:5.2f}% ({stats['correct']}/{stats['total']})")
|
| 259 |
+
|
| 260 |
+
result_summary = {
|
| 261 |
+
"qa": {
|
| 262 |
+
"inference_samples": qa_total * 2,
|
| 263 |
+
"total": qa_total,
|
| 264 |
+
"correct": qa_correct,
|
| 265 |
+
"accuracy (%)": round(qa_acc, 2),
|
| 266 |
+
"option_letter_accuracy (%)": round(option_letter_acc, 2),
|
| 267 |
+
"label_text_accuracy (%)": round(label_text_acc, 2),
|
| 268 |
+
"label_text_exact_accuracy (%)": round(label_text_exact_acc, 2),
|
| 269 |
+
},
|
| 270 |
+
"grounding": {
|
| 271 |
+
"total": gd_total,
|
| 272 |
+
"correct": correct_gd,
|
| 273 |
+
"accuracy (%)": round(gd_acc, 2),
|
| 274 |
+
"average_iou": round(avg_iou, 3),
|
| 275 |
+
"iou_threshold": iou_thresh,
|
| 276 |
+
},
|
| 277 |
+
"categories": category_acc,
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
error_path = pred_json.replace(".json", "_errors.json")
|
| 281 |
+
with open(error_path, "w", encoding="utf-8") as f:
|
| 282 |
+
json.dump(mismatch_examples, f, indent=2, ensure_ascii=False)
|
| 283 |
+
|
| 284 |
+
result_path = pred_json.replace(".json", "_accuracy.json")
|
| 285 |
+
with open(result_path, "w", encoding="utf-8") as f:
|
| 286 |
+
json.dump(result_summary, f, indent=2, ensure_ascii=False)
|
| 287 |
+
|
| 288 |
+
print(f"\nError samples saved to {error_path}")
|
| 289 |
+
print(f"Accuracy summary saved to {result_path}")
|
| 290 |
+
return result_summary
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def parse_args():
|
| 294 |
+
parser = argparse.ArgumentParser(description="Evaluate split EventDrive understanding predictions.")
|
| 295 |
+
parser.add_argument("--pred-json", required=True, help="Path to split understanding JSON with model_output fields.")
|
| 296 |
+
parser.add_argument("--iou-thresh", type=float, default=DEFAULT_IOU_THRESH, help="IoU threshold for grounding.")
|
| 297 |
+
return parser.parse_args()
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
if __name__ == "__main__":
|
| 301 |
+
args = parse_args()
|
| 302 |
+
evaluate(args.pred_json, iou_thresh=args.iou_thresh)
|