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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# doanh × EVAL-175 — WarpDyn high vs low quality detection
|
| 2 |
+
|
| 3 |
+
Detailed technical writeup of the 23-task benchmark on doanh's Cosmos-generated robot manipulation videos, mapped to NVIDIA's EVAL-175 task suite. Uses **sigmoid-normalized fused anomaly score** with per-task bootstrap-calibrated steepness.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## Dataset
|
| 8 |
+
|
| 9 |
+
| Source | Role | Format |
|
| 10 |
+
|---|---|---|
|
| 11 |
+
| [doanh25032004/cosmos_synthetic_data](https://huggingface.co/datasets/doanh25032004/cosmos_synthetic_data) `high/<task>.mp4` | **Training reference** (assumed "clean") | 23 mp4s, 1-view |
|
| 12 |
+
| [doanh25032004/cosmos_synthetic_data](https://huggingface.co/datasets/doanh25032004/cosmos_synthetic_data) `low/<task>.mp4` | **Query** (potentially anomalous) | 23 mp4s, 1-view |
|
| 13 |
+
| [nvidia/PhysicalAI-Robotics-GR00T-Eval](https://huggingface.co/datasets/nvidia/PhysicalAI-Robotics-GR00T-Eval) | Task metadata + first-frame conditioning | 23 entries across `gr1_object`, `gr1_env`, `gr1_behavior` |
|
| 14 |
+
|
| 15 |
+
Task matching: direct filename match (23/23) — doanh's filenames are exactly the task description strings used in EVAL-175.
|
| 16 |
+
|
| 17 |
+
Hypothesis: low quality Cosmos generations exhibit more anomalies (deformation, physics violation, identity drift) than high quality counterparts. If WarpDyn works, `ratio_fused = H_low / H_high_train` should be > 1.0 most of the time, with score_norm > 0.5.
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## Method — production WarpDyn pipeline
|
| 22 |
+
|
| 23 |
+
The pipeline is **per-task self-calibrated** — no labels, no cross-task assumptions, FPR=0% by construction on the training video.
|
| 24 |
+
|
| 25 |
+
### Architecture overview
|
| 26 |
+
|
| 27 |
+
```
|
| 28 |
+
┌─────────── OFFLINE (per task T, ~80s) ───────────┐
|
| 29 |
+
high/<T>.mp4 ──►│ 1. Sample 50 frames + SAM3 segment │
|
| 30 |
+
│ 2. Cycle null (182 multi-lag pairs) │──► timing.json
|
| 31 |
+
│ 3. DINOv2 pool (50 × 384) │ - null_cycle_{mean,peak}
|
| 32 |
+
│ 4. kNN LOO null (50 samples) + CV routing │ - null_knn_{ivar,peak}
|
| 33 |
+
│ 5. H_train baseline (run online on training) │ - h_train.{cycle,knn,fused}_peak
|
| 34 |
+
│ 6. BaselineNormalizer.fit (bootstrap σ, 200 iter)│ - h_train.{h_pairs,h_frames}
|
| 35 |
+
└───────────────────────────────────────────────────┘ - baseline_normalizer.{sigma,alpha}
|
| 36 |
+
│
|
| 37 |
+
┌─────────── ONLINE (per query, ~16s) ─────────────┐
|
| 38 |
+
low/<T>.mp4 ───►│ 1. Sample 10 frames + SAM3 │
|
| 39 |
+
│ 2. CYCLE: 9 pairs → Cauchy → p80 → H_cycle │
|
| 40 |
+
│ 3. KNN: 10 frames → Cochran D → p80 → H_knn │ ──► score_norm + verdict
|
| 41 |
+
│ 4. Cauchy fuse → H_fused │
|
| 42 |
+
│ 5. ratio_fused = H_fused / H_train_fused │
|
| 43 |
+
│ 6. score_norm = sigmoid(α · (ratio_fused − 1)) │
|
| 44 |
+
└───────────────────────────────────────────────────┘
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
---
|
| 48 |
+
|
| 49 |
+
## OFFLINE — step by step (per task, ~80s)
|
| 50 |
+
|
| 51 |
+
### Step 1 — Sample 50 reference frames + SAM3 segment
|
| 52 |
+
|
| 53 |
+
```python
|
| 54 |
+
N = total_frames(high_mp4) # ≈ 120 frames
|
| 55 |
+
idx = np.linspace(0, N - 1, 50).astype(int) # 50 uniform samples
|
| 56 |
+
frames = [read_frame(high_mp4, i) for i in idx]
|
| 57 |
+
|
| 58 |
+
seg = VideoFrameSegmenter(fallback="gray") # SAM3 segmenter
|
| 59 |
+
refs_masked = [seg.segment_frame(f) for f in frames] # bg → (127,127,127)
|
| 60 |
+
# saved as paper-doanh-eval/reference/<task>/frame_0000.png … frame_0049.png
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
Why 50 (not 120 or 182): doanh's Cosmos videos are short (~3–4s, ~120 frames); 50 is dense enough for kNN pool while keeping LOO null + cycle null tractable on a single H100. Reduce to 30 if VRAM tight.
|
| 64 |
+
|
| 65 |
+
Why SAM3 gray fill: prevents background lighting / table texture from dominating RoMa flow matching. (127,127,127) is neutral for both DINOv2 (CLS feature) and RoMa (no spurious edges).
|
| 66 |
+
|
| 67 |
+
**Time:** ~8 sec / 50 frames (SAM3 batch).
|
| 68 |
+
|
| 69 |
+
### Step 2 — Cycle null (182 multi-lag pairs)
|
| 70 |
+
|
| 71 |
+
For each lag in `[1, 2, 5, 10]`, generate consecutive ref-pair indices `(i, i+lag)`:
|
| 72 |
+
|
| 73 |
+
```python
|
| 74 |
+
NULL_LAGS = [1, 2, 5, 10]
|
| 75 |
+
null_mean_list, null_peak_list = [], []
|
| 76 |
+
for lag in NULL_LAGS:
|
| 77 |
+
for i in range(50 - lag): # 49+48+45+40 = 182 pairs
|
| 78 |
+
fwd = roma.match(refs_masked[i], refs_masked[i+lag])
|
| 79 |
+
bwd = roma.match(refs_masked[i+lag], refs_masked[i])
|
| 80 |
+
s = CycleSignal(cert_floor=0.1).compute(fwd, bwd) # cycle error map
|
| 81 |
+
null_mean_list.append(s.mean) # interior mean (px)
|
| 82 |
+
null_peak_list.append(s.peak) # interior p99 (px)
|
| 83 |
+
null_cycle_mean = np.sort(null_mean_list) # (182,)
|
| 84 |
+
null_cycle_peak = np.sort(null_peak_list) # (182,)
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
**CycleSignal internals:**
|
| 88 |
+
- `fwd` warps A→B, `bwd` warps B→A, both with per-pixel certainty mask
|
| 89 |
+
- Cycle error map: `||x − bwd(fwd(x))||` in pixel space
|
| 90 |
+
- `cert_floor=0.1`: ignore pixels where matcher certainty < 10% (low-confidence regions)
|
| 91 |
+
- `s.mean` = mean error over interior (foreground after gray-mask)
|
| 92 |
+
- `s.peak` = 99th percentile error over interior
|
| 93 |
+
|
| 94 |
+
Multi-lag → null spans short-range (lag 1) and long-range (lag 10) drift; not biased toward one scale.
|
| 95 |
+
|
| 96 |
+
**Time:** ~18 sec for 182 pairs × 2 RoMa matches.
|
| 97 |
+
|
| 98 |
+
### Step 3 — DINOv2 pool (50 × 384, L2-normalized)
|
| 99 |
+
|
| 100 |
+
```python
|
| 101 |
+
dino = DinoFeatureExtractor("dinov2_vits14") # ViT-S/14
|
| 102 |
+
pool_feats = np.stack([dino.extract(f) for f in refs_masked]) # (50, 384) CLS token
|
| 103 |
+
pool_feats = pool_feats / np.linalg.norm(pool_feats, axis=1, keepdims=True)
|
| 104 |
+
```
|
| 105 |
+
|
| 106 |
+
CLS feature (384-dim) is enough for pose-level retrieval; ~50× cheaper than patch features. L2-norm so cosine sim is just dot product.
|
| 107 |
+
|
| 108 |
+
**Time:** <0.1s (one batched forward).
|
| 109 |
+
|
| 110 |
+
### Step 4 — kNN LOO null + CV routing
|
| 111 |
+
|
| 112 |
+
Build a "null when query is in-distribution" by leave-one-out (LOO) over the 50 refs:
|
| 113 |
+
|
| 114 |
+
```python
|
| 115 |
+
null_ivar, null_peak_knn = [], []
|
| 116 |
+
for i in range(50):
|
| 117 |
+
sims = pool_feats @ pool_feats[i]
|
| 118 |
+
sims[i] = -1 # exclude self
|
| 119 |
+
top_k = np.argsort(sims)[-15:] # k=15 nearest
|
| 120 |
+
|
| 121 |
+
matches = roma.match_batch(refs_masked[i],
|
| 122 |
+
[refs_masked[j] for j in top_k])
|
| 123 |
+
warps = np.stack([m.warp for m in matches]) # (15, H, W, 2)
|
| 124 |
+
precs = np.stack([m.precision for m in matches]) # (15, H, W, 2, 2)
|
| 125 |
+
|
| 126 |
+
D_map, _, _ = MahalanobisStatistics.ivar_per_pixel(warps, precs)
|
| 127 |
+
null_ivar.append(MahalanobisStatistics.interior_mean(D_map, fg))
|
| 128 |
+
null_peak_knn.append(MahalanobisStatistics.peak_max_z(D_map, fg))
|
| 129 |
+
|
| 130 |
+
null_knn_ivar = np.sort(null_ivar) # (50,)
|
| 131 |
+
null_knn_peak = np.sort(null_peak_knn)
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
**Cochran deviance** is the core kNN signal:
|
| 135 |
+
```
|
| 136 |
+
D(p) = Σ_r (warp_r(p) − μ̂(p))ᵀ · Σ⁻¹_r · (warp_r(p) − μ̂(p))
|
| 137 |
+
```
|
| 138 |
+
where μ̂ is the BLUE (Best Linear Unbiased Estimator) precision-weighted consensus warp across k=15 references. Under H₀ (true match), `D ~ χ²(2(K−1))`. Large `D` means the k references *disagree* about where pixel `p` maps to — a strong signal of geometric inconsistency.
|
| 139 |
+
|
| 140 |
+
- `ivar` = `mean_interior(D)` — average disagreement over foreground
|
| 141 |
+
- `peak` = `max_interior((D − μ_int)/σ_int)` — z-score of worst disagreement
|
| 142 |
+
|
| 143 |
+
**CV routing** (per-task decision, computed offline once):
|
| 144 |
+
```python
|
| 145 |
+
cv = np.std(null_ivar) / np.mean(null_ivar)
|
| 146 |
+
route = "peak" if cv < 0.50 else "ivar"
|
| 147 |
+
```
|
| 148 |
+
If `ivar` distribution is too flat (CV low) → not discriminative for this task → switch to `peak`. Most doanh tasks route to `ivar` (CV mean ≈ 0.75).
|
| 149 |
+
|
| 150 |
+
**Time:** ~14 sec (50 LOO × match_batch).
|
| 151 |
+
|
| 152 |
+
### Step 5 — H_train baseline (online on training video)
|
| 153 |
+
|
| 154 |
+
Run the full ONLINE pipeline against the training video itself:
|
| 155 |
+
|
| 156 |
+
```python
|
| 157 |
+
h_train = score_video(high_mp4, ...)
|
| 158 |
+
# returns:
|
| 159 |
+
# cycle_peak = p80 of 9 H_pair_cycle values
|
| 160 |
+
# knn_peak = p80 of 10 H_frame_knn values
|
| 161 |
+
# fused_peak = cauchy_combine_video(cycle_peak, knn_peak)
|
| 162 |
+
# h_pairs = list[9] — needed for bootstrap
|
| 163 |
+
# h_frames = list[10] — needed for bootstrap
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
This absorbs task-specific difficulty: a complex task ("Pour") naturally has higher H_train than a simple one ("Open box"). Ratio then compares relative deviation.
|
| 167 |
+
|
| 168 |
+
**Time:** ~22 sec (mimics online pass).
|
| 169 |
+
|
| 170 |
+
### Step 6 — BaselineNormalizer.fit (bootstrap σ of H_train)
|
| 171 |
+
|
| 172 |
+
```python
|
| 173 |
+
from warp_score.fusion import BaselineNormalizer
|
| 174 |
+
|
| 175 |
+
normalizer = BaselineNormalizer(n_boot=200, pct=80, seed=42).fit(
|
| 176 |
+
h_pairs_train=h_train["h_pairs"],
|
| 177 |
+
h_frames_train=h_train["h_frames"])
|
| 178 |
+
|
| 179 |
+
# Inside .fit():
|
| 180 |
+
# for b in range(200):
|
| 181 |
+
# hp_r = np.random.choice(h_pairs, size=9, replace=True)
|
| 182 |
+
# hf_r = np.random.choice(h_frames, size=10, replace=True)
|
| 183 |
+
# fused_b = cauchy_combine_video(p80(hp_r), p80(hf_r))
|
| 184 |
+
# sigma = np.std(fused_b array)
|
| 185 |
+
# alpha = 1 / sigma
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
**Why bootstrap H values (not RoMa-level)?** Re-running RoMa with resampled refs would cost ~30 min × 200 = 100 hours. Resampling already-cached H values takes 30ms while still capturing **aggregation variance** — how much H_train fluctuates depending on *which* frames you happened to sample. This is the dominant source of noise in production (n=10 small sample size).
|
| 189 |
+
|
| 190 |
+
**What σ means:**
|
| 191 |
+
- σ ≈ 0.05 → baseline very sharp (the 9 pairs / 10 frames give consistent fused score) → small ratio deviations are meaningful → steep sigmoid
|
| 192 |
+
- σ ≈ 0.15 → baseline noisy → only large ratio deviations are meaningful → flat sigmoid (conservative)
|
| 193 |
+
|
| 194 |
+
For 23 doanh tasks: σ range [0.062, 0.163], mean 0.098.
|
| 195 |
+
|
| 196 |
+
**Time:** ~30 ms (200 numpy resamples + Cauchy combines, no GPU).
|
| 197 |
+
|
| 198 |
+
---
|
| 199 |
+
|
| 200 |
+
## ONLINE — step by step (per query, ~16s)
|
| 201 |
+
|
| 202 |
+
### Step 1 — Sample 10 frames + SAM3
|
| 203 |
+
|
| 204 |
+
```python
|
| 205 |
+
idx_q = np.linspace(0, total_frames(low_mp4) - 1, 10).astype(int)
|
| 206 |
+
q_frames_raw = [read_frame(low_mp4, i) for i in idx_q]
|
| 207 |
+
q_frames = [seg.segment_frame(f) for f in q_frames_raw] # gray-fill bg
|
| 208 |
+
```
|
| 209 |
+
|
| 210 |
+
10 frames span the full query video; spacing ~12 frames (matches lag 10 in training null).
|
| 211 |
+
|
| 212 |
+
**Time:** ~9 sec (SAM3 dominates).
|
| 213 |
+
|
| 214 |
+
### Step 2 — CYCLE branch (9 consecutive pairs → H_cycle)
|
| 215 |
+
|
| 216 |
+
```python
|
| 217 |
+
H_pairs = []
|
| 218 |
+
for k in range(9):
|
| 219 |
+
fwd = roma.match(q_frames[k], q_frames[k+1])
|
| 220 |
+
bwd = roma.match(q_frames[k+1], q_frames[k])
|
| 221 |
+
s = CycleSignal(cert_floor=0.1).compute(fwd, bwd)
|
| 222 |
+
|
| 223 |
+
p_mean = empirical_p_value(s.mean, null_cycle_mean) # right-tail
|
| 224 |
+
p_peak = empirical_p_value(s.peak, null_cycle_peak)
|
| 225 |
+
p_pair = cauchy_combine([p_mean, p_peak]) # per-pair fusion
|
| 226 |
+
H_pairs.append(1 - p_pair)
|
| 227 |
+
|
| 228 |
+
H_cycle = np.percentile(H_pairs, 80) # video aggregator
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
- `empirical_p_value` = right-tail empirical p (rank of observed signal in sorted null + 1) / (N + 1)
|
| 232 |
+
- **Per-pair Cauchy** combines mean (broad anomaly) and peak (localized anomaly) into one H per pair
|
| 233 |
+
- **Video p80**: robust to 1–2 noisy pairs, still sensitive to anomalies persisting ≥2 pairs
|
| 234 |
+
|
| 235 |
+
**Time:** ~1 sec (9 pairs × 2 RoMa).
|
| 236 |
+
|
| 237 |
+
### Step 3 — KNN branch (10 frames → H_knn)
|
| 238 |
+
|
| 239 |
+
```python
|
| 240 |
+
H_frames = []
|
| 241 |
+
for i in range(10):
|
| 242 |
+
feat = dino.extract(q_frames[i])
|
| 243 |
+
feat = feat / np.linalg.norm(feat)
|
| 244 |
+
sims = pool_feats @ feat
|
| 245 |
+
top_k = np.argsort(sims)[-15:] # 15 nearest refs
|
| 246 |
+
|
| 247 |
+
matches = roma.match_batch(q_frames[i],
|
| 248 |
+
[refs_masked[j] for j in top_k])
|
| 249 |
+
warps = np.stack([m.warp for m in matches])
|
| 250 |
+
precs = np.stack([m.precision for m in matches])
|
| 251 |
+
D_map, _, _ = MahalanobisStatistics.ivar_per_pixel(warps, precs)
|
| 252 |
+
|
| 253 |
+
ivar = MahalanobisStatistics.interior_mean(D_map, fg_mask)
|
| 254 |
+
peak = MahalanobisStatistics.peak_max_z(D_map, fg_mask)
|
| 255 |
+
|
| 256 |
+
if route == "peak":
|
| 257 |
+
p_f = empirical_p_value(peak, null_knn_peak)
|
| 258 |
+
else:
|
| 259 |
+
p_f = empirical_p_value(ivar, null_knn_ivar)
|
| 260 |
+
|
| 261 |
+
H_frames.append(1 - p_f)
|
| 262 |
+
|
| 263 |
+
H_knn = np.percentile(H_frames, 80)
|
| 264 |
+
```
|
| 265 |
+
|
| 266 |
+
**`match_batch` does ONE forward pass** for all 15 refs together (commit `a18b03b`) → ~2.5× faster than looping `roma.match`.
|
| 267 |
+
|
| 268 |
+
**Time:** ~6 sec (10 query frames × match_batch).
|
| 269 |
+
|
| 270 |
+
### Step 4 — Cauchy fuse (video level)
|
| 271 |
+
|
| 272 |
+
```python
|
| 273 |
+
p_cycle = 1 - H_cycle
|
| 274 |
+
p_knn = 1 - H_knn
|
| 275 |
+
p_fused = cauchy_combine([p_cycle, p_knn])
|
| 276 |
+
H_fused = 1 - p_fused
|
| 277 |
+
```
|
| 278 |
+
|
| 279 |
+
**Why Cauchy fusion at the video level:**
|
| 280 |
+
- Cycle and kNN are 2 orthogonal evidence sources (temporal vs appearance)
|
| 281 |
+
- Cauchy combine doesn't require independence (unlike Fisher's method)
|
| 282 |
+
- Heavy-tailed → very sensitive when *either* branch has small p (small p → infinite tan value, dominates)
|
| 283 |
+
- Catches anomalies that show up in only one modality
|
| 284 |
+
|
| 285 |
+
### Step 5 — Ratio
|
| 286 |
+
|
| 287 |
+
```python
|
| 288 |
+
ratio_fused = H_fused / max(H_train_fused, 1e-8)
|
| 289 |
+
```
|
| 290 |
+
|
| 291 |
+
Unit-free, cross-task comparable. `ratio = 1.0` means "query is as anomalous as the training video itself appears to its own null" — the natural decision boundary.
|
| 292 |
+
|
| 293 |
+
### Step 6 — Sigmoid normalization (NEW)
|
| 294 |
+
|
| 295 |
+
```python
|
| 296 |
+
score_norm = normalizer.normalize(ratio_fused)
|
| 297 |
+
# = 1 / (1 + exp(-α · (ratio_fused − 1)))
|
| 298 |
+
```
|
| 299 |
+
|
| 300 |
+
Maps `ratio ∈ [0, ∞)` → `score ∈ [0, 1]`:
|
| 301 |
+
|
| 302 |
+
| Multiple of σ_baseline | score_norm | Verdict |
|
| 303 |
+
|---|---|---|
|
| 304 |
+
| +3σ | 0.953 | very strong HALLU |
|
| 305 |
+
| **+2σ** | **0.881** | **strong HALLU** |
|
| 306 |
+
| **+1σ** | **0.731** | **weak HALLU** |
|
| 307 |
+
| 0 (ratio=1.0) | 0.500 | baseline |
|
| 308 |
+
| −1σ | 0.269 | weak clean |
|
| 309 |
+
| −2σ | 0.119 | strong clean |
|
| 310 |
+
| −3σ | 0.047 | very strong clean |
|
| 311 |
+
|
| 312 |
+
α = 1/σ is task-specific. Critical observation: same `ratio_fused = 1.10` maps to different scores depending on baseline sharpness:
|
| 313 |
+
- Task with σ=0.05 → α=20 → score_norm = sigmoid(20·0.10) = 0.881 (strong HALLU)
|
| 314 |
+
- Task with σ=0.15 → α=6.7 → score_norm = sigmoid(6.7·0.10) = 0.661 (borderline)
|
| 315 |
+
|
| 316 |
+
This is the calibration win: same threshold `score_norm > 0.73` applies uniformly across tasks despite different baseline noise.
|
| 317 |
+
|
| 318 |
+
---
|
| 319 |
+
|
| 320 |
+
## Results — 23 tasks (sorted by score_norm descending)
|
| 321 |
+
|
| 322 |
+
| Rank | task | eval folder | ratio_fused | σ_base | **score_norm** | verdict |
|
| 323 |
+
|---|---|---|---|---|---|---|
|
| 324 |
+
| 1 | 0 — Open the box | gr1_behavior | 1.343 | 0.091 | **0.978** | 🔴 strong HALLU |
|
| 325 |
+
| 2 | 14 — wooden spoon scooping | gr1_env | 1.372 | 0.108 | **0.970** | 🔴 strong HALLU |
|
| 326 |
+
| 3 | 5 — orange to metal platform | gr1_env | 1.206 | 0.095 | **0.897** | 🔴 strong HALLU |
|
| 327 |
+
| 4 | 15 — close black drawer | gr1_env | 1.260 | 0.123 | **0.892** | 🔴 strong HALLU |
|
| 328 |
+
| 5 | 13 — pink peach center → shelf | gr1_object | 1.194 | 0.105 | **0.865** | 🔴 weak HALLU |
|
| 329 |
+
| 6 | 3 — cup → green trash can | gr1_env | 1.163 | 0.098 | **0.842** | 🔴 weak HALLU |
|
| 330 |
+
| 7 | 17 — bok choy → wire basket | gr1_object | 1.263 | 0.163 | **0.834** | 🔴 weak HALLU |
|
| 331 |
+
| 8 | 7 — rubik's cube top → bottom | gr1_object | 1.137 | 0.105 | **0.787** | 🔴 weak HALLU |
|
| 332 |
+
| 9 | 22 — milk carton → cyan plate | gr1_object | 1.126 | 0.126 | **0.731** | 🔴 weak HALLU |
|
| 333 |
+
| 10 | 4 — green pepper → paper bag | gr1_object | 1.050 | 0.080 | 0.651 | ⚠ borderline |
|
| 334 |
+
| 11 | 20 — orange center → shelf | gr1_object | 1.005 | 0.104 | 0.511 | ⚠ borderline |
|
| 335 |
+
| 12 | 19 — bok choy → paper bag | gr1_object | 1.000 | 0.101 | 0.501 | ⚠ borderline |
|
| 336 |
+
| 13 | 1 — cucumber → beige bowl | gr1_object | 0.992 | 0.110 | 0.482 | ✓ weak clean |
|
| 337 |
+
| 14 | 6 — red bell pepper → bottom rack | gr1_object | 0.953 | 0.128 | 0.409 | ✓ weak clean |
|
| 338 |
+
| 15 | 10 — orange → pale turquoise | gr1_object | 0.959 | 0.062 | 0.342 | ✓ weak clean |
|
| 339 |
+
| 16 | 18 — close waffle maker | gr1_env | 0.883 | 0.087 | 0.208 | ✓ clean |
|
| 340 |
+
| 17 | 8 — red glass → turquoise | gr1_object | 0.813 | 0.085 | **0.100** | ✓ clean (MISS!) |
|
| 341 |
+
| 18 | 21 — rubik's cube bottom → top | gr1_object | 0.823 | 0.077 | 0.092 | ✓ clean |
|
| 342 |
+
| 19 | 11 — sandwich → pizza box | gr1_env | 0.800 | 0.066 | 0.047 | ✓ clean |
|
| 343 |
+
| 20 | 9 — milk carton → pale turquoise | gr1_object | 0.716 | 0.089 | 0.039 | ✓ clean |
|
| 344 |
+
| 21 | 2 — yellow star fruit → white shelf | gr1_object | 0.611 | 0.094 | 0.015 | ✓ clean |
|
| 345 |
+
| 22 | 12 — orange juice → green bowl | gr1_object | 0.599 | 0.094 | 0.014 | ✓ clean |
|
| 346 |
+
| 23 | 16 — tall red glass → blue plate | gr1_object | 0.551 | 0.070 | 0.002 | ✓ clean |
|
| 347 |
+
|
| 348 |
+
**Summary:**
|
| 349 |
+
- 9/23 HALLU (5 strong + 4 weak)
|
| 350 |
+
- 3/23 borderline
|
| 351 |
+
- 11/23 clean
|
| 352 |
+
- σ_baseline mean = 0.098, range = [0.062, 0.163]
|
| 353 |
+
|
| 354 |
+
### Failure case — task 8 "red glass"
|
| 355 |
+
|
| 356 |
+
Task 8 has visible finger deformation in the low video but `score_norm = 0.10` (strongly clean). Root cause:
|
| 357 |
+
|
| 358 |
+
```
|
| 359 |
+
h_frames (high training): [0.91, 0.98, 0.46, 0.17, 0.02, 0.28, 0.50, 0.91, 0.44, 0.79]
|
| 360 |
+
↑ ↑
|
| 361 |
+
H_train_knn_p80 = 0.912 (very high)
|
| 362 |
+
|
| 363 |
+
h_frames (low query) : [0.91, 0.83, 0.70, 0.44, 0.38, 0.44, 0.36, 0.38, 0.32, 0.40]
|
| 364 |
+
↑
|
| 365 |
+
H_test_knn_p80 = 0.724 (lower than train!)
|
| 366 |
+
```
|
| 367 |
+
|
| 368 |
+
The high video is **already saturated** against its own LOO null (left-hand pose holding a glass is intrinsically high-variance — even the "good" version looks anomalous to kNN). Low video has lower H, so ratio < 1, sigmoid maps to clean side. No combination of percentile/frame-count fixes this — even p100 + 30 frames gives ratio_fused = 0.964 (borderline). The only fix would be clipping H_train from above, which trades FPR-by-construction for catching this case.
|
| 369 |
+
|
| 370 |
+
---
|
| 371 |
+
|
| 372 |
+
## Visualizations
|
| 373 |
+
|
| 374 |
+
Per-task `task_<i>/` folder contains 14 panels:
|
| 375 |
+
|
| 376 |
+
**Offline (7 panels):**
|
| 377 |
+
1. `01_sampled_refs.png` — 10 of 50 sampled refs
|
| 378 |
+
2. `02_cycle_pair_example.png` — 1 cycle pair + warp viz + error map
|
| 379 |
+
3. `03_cycle_null_histograms.png` — null_mean + null_peak distributions
|
| 380 |
+
4. `04_dinov2_pool_pca.png` — 50 refs projected to 2D (time-colored)
|
| 381 |
+
5. `05_knn_loo_example.png` — 1 LOO query + top-5 retrieved refs
|
| 382 |
+
6. `06_cochran_dmap_example.png` — D-map for 1 LOO query
|
| 383 |
+
7. `07_knn_null_histograms.png` — null_ivar + null_peak distributions
|
| 384 |
+
|
| 385 |
+
**Online (7 panels):**
|
| 386 |
+
1. `01_query_frames.png` — 10 sampled query frames
|
| 387 |
+
2. `02_query_pair_example.png` — 1 consecutive query pair
|
| 388 |
+
3. `03_cycle_pairs_bar.png` — 9 H_pair values + p80 line + H_train ref
|
| 389 |
+
4. `04_knn_topk_per_frame.png` — top-5 retrieved refs for 3 query frames
|
| 390 |
+
5. `05_knn_dmap_per_frame.png` — D-map overlay per query frame (10 panels)
|
| 391 |
+
6. `06_knn_frames_bar.png` — 10 H_frame values + p80 line + H_train ref
|
| 392 |
+
7. `07_final_scores.png` — H_train vs H_test per branch + ratio + verdict
|
| 393 |
+
|
| 394 |
+
**Aggregate plots (in `per_task_dense_eval/`):**
|
| 395 |
+
- `doanh_ratio_bars.png` — per-task ratios (cycle/knn/fused), sorted
|
| 396 |
+
- `doanh_score_norm_bars.png` — per-task sigmoid-normalized scores
|
| 397 |
+
- `doanh_ratio_vs_score_norm.png` — scatter showing per-task α effect
|
| 398 |
+
- `doanh_ratio_histograms.png` — distribution shapes
|
| 399 |
+
|
| 400 |
+
---
|
| 401 |
+
|
| 402 |
+
## Reproduce
|
| 403 |
+
|
| 404 |
+
```bash
|
| 405 |
+
conda activate groot
|
| 406 |
+
cd /mnt/data/sftp/data/quangpt3/gcvwm/calibration/feepe/feature_matching_eval_hallucination
|
| 407 |
+
|
| 408 |
+
# Step 0: download datasets (one time)
|
| 409 |
+
# - doanh: huggingface hub → paper-doanh-eval/raw_videos/{high,low}/
|
| 410 |
+
# - EVAL-175: huggingface hub → paper-doanh-eval/conditioning/
|
| 411 |
+
|
| 412 |
+
# Step 1: extract 50-frame SAM3 refs (one time, ~1.5 min × 23 tasks)
|
| 413 |
+
python scripts/extract_doanh_eval_refs.py
|
| 414 |
+
|
| 415 |
+
# Step 2: sweep 23 tasks — full offline + online + bootstrap normalizer (~30 min)
|
| 416 |
+
python scripts/_bench_doanh_eval_sweep.py
|
| 417 |
+
|
| 418 |
+
# Step 3: aggregate results + plots + summary markdown
|
| 419 |
+
python scripts/_doanh_eval_summary_viz.py
|
| 420 |
+
|
| 421 |
+
# Step 4: upload to HF dataset wmbench/doanh_eval175/
|
| 422 |
+
python scripts/_upload_doanh_eval_to_hf.py
|
| 423 |
+
```
|
| 424 |
+
|
| 425 |
+
---
|
| 426 |
+
|
| 427 |
+
## Files
|
| 428 |
+
|
| 429 |
+
| File | Role |
|
| 430 |
+
|---|---|
|
| 431 |
+
| `warp_score/sam_segmenter.py` | SAM3 (`VideoFrameSegmenter`) + gray fallback |
|
| 432 |
+
| `warp_score/matcher.py` | `RoMaMatcher` + `match_batch` (k-ref single forward) |
|
| 433 |
+
| `warp_score/adaptive_refs.py` | `DinoFeatureExtractor` + `AdaptiveRefSelector` |
|
| 434 |
+
| `warp_score/statistics.py` | `MahalanobisStatistics.ivar_per_pixel` (Cochran D) |
|
| 435 |
+
| `warp_score/temporal_signals.py` | `CycleSignal` + `cauchy_combine` + `empirical_p_value` |
|
| 436 |
+
| `warp_score/knn_signal.py` | `KNNFrameSignal` (pool + LOO + routing + `score_frame`) |
|
| 437 |
+
| **`warp_score/fusion.py`** | **`BaselineNormalizer` class + `cauchy_combine_video`** |
|
| 438 |
+
| `scripts/extract_doanh_eval_refs.py` | OFFLINE step 1 (SAM3 refs from high mp4s) |
|
| 439 |
+
| `scripts/benchmark_one_task.py` | Single-task OFFLINE+ONLINE+normalizer + 14-panel viz |
|
| 440 |
+
| `scripts/_bench_doanh_eval_sweep.py` | Run benchmark_one_task across 23 tasks |
|
| 441 |
+
| `scripts/_doanh_eval_summary_viz.py` | Aggregate timing.json files → CSV + plots + markdown |
|
| 442 |
+
| `scripts/_upload_doanh_eval_to_hf.py` | Push results to HF `twanghcmut/wmbench/doanh_eval175/` |
|
| 443 |
+
|
| 444 |
+
---
|
| 445 |
+
|
| 446 |
+
## Public dataset
|
| 447 |
+
|
| 448 |
+
https://huggingface.co/datasets/twanghcmut/wmbench/tree/main/doanh_eval175
|
| 449 |
+
|
| 450 |
+
Layout:
|
| 451 |
+
```
|
| 452 |
+
doanh_eval175/
|
| 453 |
+
├── README.md # task overview + score_norm explanation
|
| 454 |
+
├── DOANH_EVAL175.md # this technical writeup
|
| 455 |
+
├── WARPDYN_METHOD.md # general WarpDyn method doc
|
| 456 |
+
├── eval_tasks.json # 23 task entries
|
| 457 |
+
├── per_task_dense_eval/
|
| 458 |
+
│ ├── doanh_low_vs_high_ratio.csv # 23 rows: ts, ratios, score_norm, sigma, alpha
|
| 459 |
+
│ ├── doanh_ratio_bars.png
|
| 460 |
+
│ ├── doanh_score_norm_bars.png # NEW — sigmoid-normalized per task
|
| 461 |
+
│ ├── doanh_ratio_vs_score_norm.png # NEW — scatter ratio→score
|
| 462 |
+
│ ├── doanh_ratio_histograms.png
|
| 463 |
+
│ └── doanh_summary.md
|
| 464 |
+
├── raw_videos/
|
| 465 |
+
│ ├── high/{0..22}_<task>.mp4 # 23 training refs
|
| 466 |
+
│ └── low/{0..22}_<task>.mp4 # 23 queries
|
| 467 |
+
├── conditioning/{0..22}_<task>.png # EVAL-175 first frame + prompt
|
| 468 |
+
└── task_<i>/ # 23 folders, each with offline/+online/ viz + timing.json
|
| 469 |
+
```
|