Datasets:
File size: 13,642 Bytes
dd7ed38 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
---
license: cc-by-4.0
task_categories:
- video-text-to-text
tags:
- video-question-answering
- video-understanding
- spatial-reasoning
- benchmark
- 3d
---
# DSI-Bench: A Benchmark for Dynamic Spatial Intelligence
[Paper](https://huggingface.co/papers/2510.18873) | [Project Page](https://dsibench.github.io/) | [Code](https://github.com/SpatialVision/dsibench)
## Abstract
Reasoning about dynamic spatial relationships is essential, as both observers and objects often move simultaneously. Although vision-language models (VLMs) and visual expertise models excel in 2D tasks and static scenarios, their ability to fully understand dynamic 3D scenarios remains limited. We introduce Dynamic Spatial Intelligence and propose DSI-Bench, a benchmark with nearly 1,000 dynamic videos and over 1,700 manually annotated questions covering nine decoupled motion patterns of observers and objects. Spatially and temporally symmetric designs reduce biases and enable systematic evaluation of models' reasoning about self-motion and object motion. Our evaluation of 14 VLMs and expert models reveals key limitations: models often conflate observer and object motion, exhibit semantic biases, and fail to accurately infer relative relationships in dynamic scenarios. Our DSI-Bench provides valuable findings and insights about the future development of general and expertise models with dynamic spatial intelligence.
## Sample Usage
This section provides a quick guide to set up the environment, download the dataset, perform inference, and evaluate model performance.
### 1. Install dependency
```shell
pip install -r requirements.txt
```
### 2. Download full dataset
```shell
huggingface-cli download --repo-type dataset Viglong/DSI-Bench --local-dir DSI-Bench
```
### 3. Inference with Qwen API
Here we provide a sample for testing on DSI-bench using the Qwen API.
```python
import os
import re
import pandas as pd
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor, as_completed
import dashscope
# Configuration
DASHSCOPE_API_KEY = "YOUR_DASHSCOPE_API_KEY_HERE" # Replace or load from env
VLM_MODEL = "qwen2.5-vl-32b-instruct" # e.g., "qwen2.5-vl-72b-instruct"
VIDEO_AUG = "std" # Video variant: 'std', 'hflip', etc.
NUM_WORKERS = 2
MAX_RETRIES = 10
FPS = 5 # Frames per second for video input
# Relative paths (relative to this script)
METADATA_BASE_DIR = "/path/to/metadatas"# Contains {VIDEO_AUG}.csv
VIDEO_BASE_DIR = "/path/to/videos" # Structure: videos/{VIDEO_AUG}/xxx.mp4
OUTPUT_BASE_DIR = "/path/to/outputs" # Output: outputs/{VIDEO_AUG}/{model}.csv
# Prompt
rawqa_prompt = """You are a vision-language expert.
You are given a clip of video and your task is to answer a question about the video.
You only need to provide *ONE* correct answer selecting from the options listed below.
For example, if you think the correct answer is 'A' from 'A. Above B. Under C. Front D. Behind',
your response should **only** be '<answer>A</answer>'.
Please answer the question in this format strictly:
<answer>[A, B, C, or D]</answer>
"""
def extract_single_choice_with_word_boundary(text):
"""
Extract the answer letter (A/B/C/D) from <answer>X</answer> in the response.
Returns None if not found.
"""
match = re.search(r"<answer>\s*([A-D])\s*</answer>", text, re.IGNORECASE)
return match.group(1).upper() if match else None
# Call VLM with video and question
def query_vlm(mp4_path, question, options):
"""
Send video and question to Qwen-VL via DashScope API.
Returns raw model response text.
"""
question_and_options = f"
Question:
{question} {options}"
messages = [
{
"role": "user",
"content": [
{"video": f"file://{mp4_path}", "fps": FPS},
{"text": rawqa_prompt + question_and_options}
]
}
]
response = dashscope.MultiModalConversation.call(
api_key=DASHSCOPE_API_KEY,
model=VLM_MODEL,
messages=messages,
max_length=2048,
stream=False,
top_k=1
)
return response.output.choices[0].message.content[0]["text"]
# Process a single sample
def process_sample(meta, idx):
"""
Process one video-question sample.
Returns (raw_response, extracted_answer) or (None, None) on failure.
"""
mp4_path = os.path.join(VIDEO_BASE_DIR, VIDEO_AUG, meta["relative_path"][idx])
question = meta["question"][idx]
options = meta["options"][idx]
try:
raw_response = query_vlm(mp4_path, question, options)
final_answer = extract_single_choice_with_word_boundary(raw_response)
return raw_response, final_answer
except Exception as e:
return None, None
# Batch processing with retries
def run_batch_inference(meta, num_workers=NUM_WORKERS, max_retries=MAX_RETRIES):
"""
Run inference on all samples with parallel execution and retry logic.
Ensures output order matches input order.
"""
print(f"Running inference with model: {VLM_MODEL}, video variant: {VIDEO_AUG}")
n = len(meta)
results = [None] * n
def worker(idx):
raw, ans = process_sample(meta, idx)
return idx, raw, ans
def run_parallel(indices, desc="Processing"):
temp = [None] * n
with ThreadPoolExecutor(max_workers=num_workers) as executor:
futures = {executor.submit(worker, i): i for i in indices}
for future in tqdm(as_completed(futures), total=len(futures), desc=desc):
idx, raw, ans = future.result()
temp[idx] = {"result_text": raw, "final_answer": ans}
return temp
# Initial run
current_results = run_parallel(list(range(n)), desc="Initial Run")
for i, res in enumerate(current_results):
results[i] = res
# Retry failed samples
for retry in range(1, max_retries + 1):
failed = [i for i in range(n) if results[i]["final_answer"] is None]
if not failed:
print(f"All samples succeeded after {retry - 1} retries.")
break
print(f"Retry {retry}/{max_retries} for {len(failed)} failed samples...")
retry_results = run_parallel(failed, desc=f"Retry {retry}")
for i in failed:
results[i] = retry_results[i]
# Handle permanently failed samples
for i in range(n):
if results[i]["final_answer"] is None:
results[i]["final_answer"] = "E" # Default error answer
if results[i]["result_text"] is None:
results[i]["result_text"] = ""
success_count = sum(1 for r in results if r["final_answer"] != "E")
print(f"Completed. Success: {success_count}/{n}")
return results
if __name__ == "__main__":
for aug in ["std", "hflip", "reverse", "reverse_hflip"]:
VIDEO_AUG = aug
meta_path = os.path.join(METADATA_BASE_DIR, f"{VIDEO_AUG}.csv")
df = pd.read_csv(meta_path)
print(f"Loaded metadata: {meta_path} with {len(df)} samples")
# Set directories
output_dir = os.path.join(OUTPUT_BASE_DIR, VIDEO_AUG)
os.makedirs(output_dir, exist_ok=True)
# Run inference
results = run_batch_inference(df)
# Save results
output_file = os.path.join(output_dir, f"{VLM_MODEL}.csv")
pd.DataFrame(results).to_csv(output_file, index=False)
print(f"Results saved to: {output_file}")
```
### 4. Evaluate model performance
Use the following code to get the Sample-wise Accuracy and Group-wise Accuracy of the model.
```python
import pandas as pd
import os
from typing import Dict
# ==============================
# Configuration
# ==============================
VLM_MODEL = "qwen2.5-vl-32b-instruct" # Model name
VIDEO_AUGS = ["std", "reverse", "hflip", "reverse_hflip"]
# Base paths (relative to project root)
META_BASE_PATH = "/path/to/metadatas" # Contains {aug}.csv
OUTPUT_BASE_PATH = "/path/to/outputs" # Contains {aug}/{VLM_MODEL}.csv
# Category name mapping
CATE_NAMES = [
"Obj:static cam",
"Obj:moving cam",
"Cam:static scene",
"Cam:dynamic scene",
"Obj-Cam distance",
"Obj-Cam orientation"
]
def load_all_data() -> Dict[str, Dict[str, pd.DataFrame]]:
"""
Load metadata and prediction results for all augmentations.
Returns: {aug: {'meta': DataFrame, 'result': DataFrame}}
"""
data_dict = {}
for aug in VIDEO_AUGS:
meta_path = os.path.join(META_BASE_PATH, f"{aug}.csv")
res_path = os.path.join(OUTPUT_BASE_PATH, aug, f"{VLM_MODEL}.csv")
if not os.path.exists(meta_path):
raise FileNotFoundError(f"Metadata not found: {meta_path}")
if not os.path.exists(res_path):
raise FileNotFoundError(f"Result file not found: {res_path}")
meta = pd.read_csv(meta_path)
result = pd.read_csv(res_path)
if len(meta) != len(result):
raise ValueError(f"Length mismatch in {aug}: meta={len(meta)}, result={len(result)}")
if "GT" not in meta.columns:
raise ValueError(f"'GT' column missing in metadata: {meta_path}")
if "final_answer" not in result.columns:
raise ValueError(f"'final_answer' column missing in results: {res_path}")
data_dict[aug] = {"meta": meta, "result": result}
# Ensure all augmentations have the same number of samples
lengths = [len(data_dict[aug]["meta"]) for aug in VIDEO_AUGS]
if len(set(lengths)) > 1:
raise ValueError(f"Inconsistent sample counts: {dict(zip(VIDEO_AUGS, lengths))}")
return data_dict
def sample_wise_evaluation():
"""
Treat all samples across all augmentations as independent.
Compute per-category and overall accuracy.
"""
print("=== Method 1: Independent Samples ===")
data_dict = load_all_data()
records = []
for aug in VIDEO_AUGS:
meta = data_dict[aug]["meta"]
res = data_dict[aug]["result"]
for i in range(len(meta)):
gt = str(meta.iloc[i]["GT"]).strip()
pred = str(res.iloc[i]["final_answer"]).strip()
pred_letter = pred[0] if pred else ""
correct = int(gt == pred_letter)
records.append({"cate": meta.iloc[i]["cate"], "correct": correct})
df = pd.DataFrame(records)
acc_by_cat = df.groupby("cate")["correct"].mean()
overall_acc = df["correct"].mean()
print_metrics(acc_by_cat, overall_acc)
def group_wise_evaluation(n: int):
"""
For each original question (4 views), count how many augmented views are correct
under their own ground truth. If >= n are correct, count as robustly correct.
"""
print(f"=== Method 2: Ensemble Voting (n>={n}) ===")
data_dict = load_all_data()
num_samples = len(data_dict[VIDEO_AUGS[0]]["meta"])
records = []
total_robust_correct = 0
for i in range(num_samples):
correct_count = 0
cate = None
for aug in VIDEO_AUGS:
meta = data_dict[aug]["meta"]
res = data_dict[aug]["result"]
gt = str(meta.iloc[i]["GT"]).strip()
pred = str(res.iloc[i]["final_answer"]).strip()
pred_letter = pred[0] if pred else ""
if gt == pred_letter:
correct_count += 1
if cate is None:
cate = meta.iloc[i]["cate"]
is_robust_correct = int(correct_count >= n)
records.append({"cate": cate, "correct": is_robust_correct})
total_robust_correct += is_robust_correct
df = pd.DataFrame(records)
acc_by_cat = df.groupby("cate")["correct"].mean()
overall_acc = total_robust_correct / num_samples
print_metrics(acc_by_cat, overall_acc)
def single_evaluation(aug: str):
"""
Evaluate performance on a single augmentation variant.
"""
if aug not in VIDEO_AUGS:
raise ValueError(f"Invalid augmentation: {aug}. Choose from {VIDEO_AUGS}")
print(f"=== Method 3: Single View Evaluation ({aug}) ===")
data_dict = load_all_data()
meta = data_dict[aug]["meta"]
res = data_dict[aug]["result"]
correct_list = []
for i in range(len(meta)):
gt = str(meta.iloc[i]["GT"]).strip()
pred = str(res.iloc[i]["final_answer"]).strip()
pred_letter = pred[0] if pred else ""
correct_list.append(int(gt == pred_letter))
df = pd.DataFrame({"cate": meta["cate"], "correct": correct_list})
acc_by_cat = df.groupby("cate")["correct"].mean()
overall_acc = df["correct"].mean()
print_metrics(acc_by_cat, overall_acc)
def print_metrics(acc_by_cat: pd.Series, overall_acc: float):
"""
Print per-category and overall accuracy in a readable format.
"""
for cat, ratio in acc_by_cat.items():
name = CATE_NAMES[cat] if cat < len(CATE_NAMES) else f"Category {cat}"
print('category = {0} {1:<20} Acc = {2:.2%}'.format(cat, name, ratio))
print(f'
Overall Acc = {overall_acc:.2%}
')
if __name__ == "__main__":
print(f"Model: {VLM_MODEL}")
sample_wise_evaluation()
group_wise_evaluation(n=3)
```
## Citation
If you find this repository useful for your research, please use the following BibTeX entry:
```bibtex
@misc{zhang2025dsibenchbenchmarkdynamicspatial,
title={DSI-Bench: A Benchmark for Dynamic Spatial Intelligence},
author={Ziang Zhang and Zehan Wang and Guanghao Zhang and Weilong Dai and Yan Xia and Ziang Yan and Minjie Hong and Zhou Zhao},
year={2025},
eprint={2510.18873},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2510.18873},
}
``` |