Datasets:
Formats:
json
Languages:
English
Size:
< 1K
Tags:
physical-icl
physical-in-context-learning
video-generation
world-model
physics
demonstration-learning
License:
Add collage-i2v experiment: wan2.6 3-case run + Physics-IQ scorer/results + base-model survey + per-axis judgment (#1)
Browse files- Add collage-i2v experiment: wan2.6 3-case run + Physics-IQ scorer/results + base-model survey + per-axis judgment (6001e6ae637e076bddd3d0777294b298b245c4e6)
Co-authored-by: yu <yqi19@users.noreply.huggingface.co>
- collage_experiment/README.md +139 -0
- collage_experiment/gen/build_collage.py +94 -0
- collage_experiment/gen/crop_query_panel.py +46 -0
- collage_experiment/gen/run_collage_v2.py +57 -0
- collage_experiment/judge/task_0003_GT_strip.png +3 -0
- collage_experiment/judge/task_0003_cosmos3.mp4 +3 -0
- collage_experiment/judge/task_0003_cosmos3_query_strip.png +3 -0
- collage_experiment/judge/task_0003_wan_query_strip.png +3 -0
- collage_experiment/judge/task_0003_wan_query_zoom.png +3 -0
- collage_experiment/judge/task_0035_GT_strip.png +3 -0
- collage_experiment/judge/task_0035_cosmos3.mp4 +3 -0
- collage_experiment/judge/task_0035_cosmos3_query_strip.png +3 -0
- collage_experiment/judge/task_0035_wan_query_strip.png +3 -0
- collage_experiment/judge/task_0065_3way.png +3 -0
- collage_experiment/judge/task_0065_GT_strip.png +3 -0
- collage_experiment/judge/task_0065_cosmos3.mp4 +3 -0
- collage_experiment/judge/task_0065_cosmos3_query_strip.png +3 -0
- collage_experiment/judge/task_0065_wan_FULL_strip.png +3 -0
- collage_experiment/judge/task_0065_wan_query_strip.png +3 -0
- collage_experiment/research/basemodel_survey.md +42 -0
- collage_experiment/scorer/fov_sanity_all.png +3 -0
- collage_experiment/scorer/physics_iq_results.json +17 -0
- collage_experiment/scorer/physics_iq_score.py +121 -0
- collage_experiment/videos/task_0003_wan26flash_480p.mp4 +3 -0
- collage_experiment/videos/task_0035_wan26flash_480p.mp4 +3 -0
- collage_experiment/videos/task_0065_wan26flash_480p.mp4 +3 -0
collage_experiment/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Physical-ICL — Collage (拼图) i2v experiment + base-model survey
|
| 2 |
+
|
| 3 |
+
In-context physical video generation on the **Physics-IQ preliminary subset** (`physiq_prelim`).
|
| 4 |
+
Two deliverables:
|
| 5 |
+
|
| 6 |
+
1. **Collage-i2v run**: composite the demonstration storyboard onto the query init frame
|
| 7 |
+
(a single "拼图/collage" image) and feed it to an image-to-video model. This bypasses the
|
| 8 |
+
reference-video (r2v) *appearance-copy* trap by giving the model one composite image as the
|
| 9 |
+
sole visual prompt. We run **wan2.6-i2v-flash** on 3 key cases and evaluate vs the real GT
|
| 10 |
+
continuation, alongside the **cosmos3-Nano** collage baseline.
|
| 11 |
+
2. **Base-model survey**: which open-source video-gen model is the strongest + easiest to
|
| 12 |
+
finetune for demo→query ICL TIV2V. See `research/basemodel_survey.md`.
|
| 13 |
+
**Shortlist: LoomVideo (lightest, has training code) / VAP (cheapest post-train) / UniVideo
|
| 14 |
+
(benchmark-backed).**
|
| 15 |
+
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
## Cases (good_follow config)
|
| 19 |
+
|
| 20 |
+
| task | physics invariant |
|
| 21 |
+
|---|---|
|
| 22 |
+
| task_0065 | compression / deformation (dumbbell + block dropped onto pillows) |
|
| 23 |
+
| task_0003 | collision / momentum transfer (ball rolls into rubber duck) |
|
| 24 |
+
| task_0035 | gravity + rolling down a ramp |
|
| 25 |
+
|
| 26 |
+
Inputs come from `yqi19/in-context-learning-cosmos3-output` (good_follow): each case's
|
| 27 |
+
`input_composite.png` is the init image, `prompt_fed.txt` is the text prompt. wan output is
|
| 28 |
+
720P (900×1022, the model's minimum), 5s, no audio.
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## Quantitative: reference-based Physics-IQ vs GT
|
| 33 |
+
|
| 34 |
+
Scorer: `scorer/physics_iq_score.py`. Results: `scorer/physics_iq_results.json`.
|
| 35 |
+
|
| 36 |
+
The generated video's **bottom query panel** (y ≥ 0.495·H, ratio-cropped so it adapts to any
|
| 37 |
+
resolution) is compared frame-by-frame against the real Physics-IQ GT continuation over the
|
| 38 |
+
matched 5-second window (both 30 fps).
|
| 39 |
+
|
| 40 |
+
### ⚠️ Metric caveat (important — read before trusting numbers)
|
| 41 |
+
|
| 42 |
+
The **naïve raw-pixel IoU initially gave the WRONG answer** (cosmos3 > wan). Root cause: we are
|
| 43 |
+
comparing *generated pixels* against *real 4K GT* — generation flicker + lighting/texture
|
| 44 |
+
domain-gap produce diffuse per-pixel change that crosses the motion threshold in the *wrong*
|
| 45 |
+
locations, inflating the generated video's active area (e.g. task_0065 wan active-pixel fraction
|
| 46 |
+
0.201 vs GT 0.078). Naïve IoU then measures *motion quantity / flicker*, not physics.
|
| 47 |
+
|
| 48 |
+
**Fix** (closer to the canonical Physics-IQ protocol): equalize each frame's motion budget to
|
| 49 |
+
GT's active-pixel count (top-k selection), Gaussian-denoise, and morphological-open before
|
| 50 |
+
computing IoU. The resulting **budget-matched spatiotemporal IoU** measures *localization at
|
| 51 |
+
equal motion budget* and reverses the naïve result — now agreeing with the qualitative per-axis
|
| 52 |
+
read on all 3 cases.
|
| 53 |
+
|
| 54 |
+
### Budget-matched spatiotemporal IoU (higher = better)
|
| 55 |
+
|
| 56 |
+
| task | wan collage-i2v | cosmos3 collage |
|
| 57 |
+
|---|---|---|
|
| 58 |
+
| task_0065 compression | **0.348** | 0.337 |
|
| 59 |
+
| task_0003 collision | **0.286** | 0.050 |
|
| 60 |
+
| task_0035 ramp roll | **0.063** | 0.041 |
|
| 61 |
+
|
| 62 |
+
**wan ≥ cosmos3 on 3/3.** (FOV alignment verified — `scorer/fov_sanity_all.png` shows the wan
|
| 63 |
+
query panel and GT share the same scene framing on all 3, so this is not a reframing artifact.)
|
| 64 |
+
|
| 65 |
+
> Note: these are *raw* Physics-IQ components, not the population-normalized 0–100 Physics-IQ
|
| 66 |
+
> Score (which needs a second real take per task for real-vs-real variance normalization). On
|
| 67 |
+
> n=3 with a generated-vs-real domain gap, always pair budget-matched ST-IoU with the
|
| 68 |
+
> qualitative per-axis judgment below.
|
| 69 |
+
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
## Qualitative per-axis judgment (Vita)
|
| 73 |
+
|
| 74 |
+
**Setup.** Each query is generated by feeding the *collage* image (top = demo 3×3
|
| 75 |
+
event storyboard, bottom = query first frame) as the **single `img_url`** to
|
| 76 |
+
`wan2.6-i2v-flash` (720P, no audio) with an ICL prompt ("apply the demonstrated
|
| 77 |
+
physics to the bottom query panel, keep the top panel static, do not copy the
|
| 78 |
+
demo's appearance"). No `reference_video` channel is used — by construction this
|
| 79 |
+
sidesteps the r2v appearance-copy failure mode. Judgment is read directly off the
|
| 80 |
+
cropped bottom **query panel** (ratio y ≥ 0.495·H, resolution-agnostic) at full
|
| 81 |
+
resolution, per physics axis, against GT and the Cosmos3-Nano collage output.
|
| 82 |
+
|
| 83 |
+
### Per-case verdicts
|
| 84 |
+
|
| 85 |
+
**task_0065 — compression / deformation — 🟢 STRONG POSITIVE**
|
| 86 |
+
- Falling dynamics: ✅ both the kettlebell (30lb) and the green block are released and fall.
|
| 87 |
+
- Compression-deform (target axis): ✅ the kettlebell lands on the left pillow and the pillow **visibly compresses/indents** under the load; the block lands flat on the right pillow. Best match to GT.
|
| 88 |
+
- vs Cosmos3: Cosmos3 only dropped the kettlebell (block stayed suspended) → **wan > Cosmos3**.
|
| 89 |
+
- Appearance-contamination: **none** ✅. Top demo panel stayed **static** ✅.
|
| 90 |
+
|
| 91 |
+
**task_0035 — gravity / ramp rolling — 🟢 STRONG POSITIVE**
|
| 92 |
+
- Gravity + rolling + redirection: ✅ the marble descends the cascade of colored ramps in sequence, redirecting at each ramp — the rule transferred cleanly.
|
| 93 |
+
- Appearance-contamination: **none** ✅.
|
| 94 |
+
|
| 95 |
+
**task_0003 — collision / momentum — 🟡 PARTIAL**
|
| 96 |
+
- Rolling + contact: ✅ the ball rolls across the table and reaches (contacts) the duck.
|
| 97 |
+
- Momentum transfer (target axis): ⚠️ **weak** — the duck is barely displaced; the collision resolves as "arrival/contact" rather than a clear knock-away.
|
| 98 |
+
- Appearance-contamination: **none** ✅.
|
| 99 |
+
|
| 100 |
+
### Cross-cutting findings
|
| 101 |
+
1. **Zero appearance-contamination (3/3).** Collage-as-single-`img_url` i2v fully avoids the r2v appearance-copy disease that made the demo *harmful* in the earlier pilot. This is the headline win.
|
| 102 |
+
2. **Top demo panel stays static** in wan, and there is no tail-frame collapse — unlike Cosmos3-Nano, which animated the whole composite and degraded the final frames.
|
| 103 |
+
3. **Transfer strength is invariant-dependent:** deformation (0065) and gravity/rolling (0035) transfer **strongly**; collision-momentum (0003) transfers only to the contact stage (**weak** knock-away).
|
| 104 |
+
4. **wan-collage ≥ Cosmos3-collage** on identical inputs (clearest on 0065), consistent with the budget-matched ST-IoU numbers.
|
| 105 |
+
|
| 106 |
+
### Not tested / next
|
| 107 |
+
- **Signed steering** (does an *opposite* demo push the physics the wrong way?) was not run. task_0003 has an `opposite_typed` config available — a reverse-demo run + signed per-axis read would test conditioning directionality.
|
| 108 |
+
- n=3, single seed. Scaling to the core good_follow/good_rule set (86 cases) would firm up the per-invariant pattern.
|
| 109 |
+
|
| 110 |
+
Assets: `judge/` (per-case GT / cosmos3 / wan query strips, `task_0065_3way.png` comparison, `task_0003_wan_query_zoom.png` full-res zoom).
|
| 111 |
+
|
| 112 |
+
---
|
| 113 |
+
|
| 114 |
+
## Repository layout
|
| 115 |
+
|
| 116 |
+
```
|
| 117 |
+
research/basemodel_survey.md # VAP / UniVideo / VINO / LoomVideo / VACE (base model + GitHub)
|
| 118 |
+
scorer/physics_iq_score.py # reference-based Physics-IQ component scorer
|
| 119 |
+
scorer/physics_iq_results.json # 3-case results + FOV check
|
| 120 |
+
scorer/fov_sanity_all.png # wan-panel vs GT FOV alignment check
|
| 121 |
+
gen/build_collage.py # collage (storyboard→query) builder
|
| 122 |
+
gen/run_collage_v2.py # wan2.6 collage-i2v runner
|
| 123 |
+
gen/crop_query_panel.py # ratio-based query-panel crop (shared by judging + Physics-IQ)
|
| 124 |
+
judge/ # GT / cosmos3 / wan strips + comparison figures
|
| 125 |
+
videos/ # 3 wan2.6-i2v-flash raw outputs (900×1022, 5s, no audio)
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
## Takeaway
|
| 129 |
+
|
| 130 |
+
wan2.6 **collage-i2v works**: it transfers compression and gravity-rolling physics strongly,
|
| 131 |
+
collision momentum weakly (contact but no knock-away), with **zero appearance contamination**
|
| 132 |
+
(3/3) and a static top demo panel. Both the budget-matched quantitative metric and the
|
| 133 |
+
qualitative per-axis read agree it beats the cosmos3-Nano collage baseline.
|
| 134 |
+
|
| 135 |
+
For a **finetuned ICL base**, the survey (`research/basemodel_survey.md`) shortlists, by fit:
|
| 136 |
+
**LoomVideo** (lightest at 5B, ships training code, interleaved multi-image+text — try first),
|
| 137 |
+
**VAP** (cheapest to start post-training: freeze base + train only the MoT expert, ships
|
| 138 |
+
VAP-Data; native demo→query in-context), and **UniVideo** (benchmark-backed but heavier). VINO
|
| 139 |
+
is the best architectural fit but has no training code yet.
|
collage_experiment/gen/build_collage.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build 'puzzle/collage' visual-ICL init images for Physical-ICL.
|
| 3 |
+
|
| 4 |
+
Siyuan's ask: paste the demo *example* frames onto the query init_frame in a
|
| 5 |
+
single image, so wan2.6-i2v-flash gets the demonstration spatially (as one
|
| 6 |
+
picture) instead of via the r2v reference-video channel (which just copies the
|
| 7 |
+
demo's appearance).
|
| 8 |
+
|
| 9 |
+
Two layouts produced per case:
|
| 10 |
+
A) stacked : [demo 3x3 storyboard] on TOP of [query init] (放上面, most literal)
|
| 11 |
+
B) filmstrip : [demo start | demo end | QUERY init] side by side (compact, keeps query big)
|
| 12 |
+
|
| 13 |
+
Usage: python3 build_collage.py task_0001 [task_0035 ...] --demo good
|
| 14 |
+
"""
|
| 15 |
+
import argparse, os
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 18 |
+
|
| 19 |
+
DATA_ROOT = "/tmp/physical_icl/repo/data/physiq_prelim/gt_data"
|
| 20 |
+
OUT = Path("/tmp/physical_icl/collage")
|
| 21 |
+
OUT.mkdir(parents=True, exist_ok=True)
|
| 22 |
+
|
| 23 |
+
def font(sz):
|
| 24 |
+
for f in ["/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"]:
|
| 25 |
+
if os.path.exists(f):
|
| 26 |
+
return ImageFont.truetype(f, sz)
|
| 27 |
+
return ImageFont.load_default()
|
| 28 |
+
|
| 29 |
+
def label_bar(w, text, h=46, bg=(20,20,20), fg=(255,255,255)):
|
| 30 |
+
bar = Image.new("RGB", (w, h), bg)
|
| 31 |
+
d = ImageDraw.Draw(bar)
|
| 32 |
+
d.text((14, h//2), text, fill=fg, font=font(26), anchor="lm")
|
| 33 |
+
return bar
|
| 34 |
+
|
| 35 |
+
def storyboard_frames(demo_png):
|
| 36 |
+
"""Slice the 3x3 numbered storyboard back into 9 frames (drop number tag corner)."""
|
| 37 |
+
im = Image.open(demo_png).convert("RGB")
|
| 38 |
+
W, H = im.size
|
| 39 |
+
cw, ch = W//3, H//3
|
| 40 |
+
frames = []
|
| 41 |
+
for r in range(3):
|
| 42 |
+
for c in range(3):
|
| 43 |
+
frames.append(im.crop((c*cw, r*ch, (c+1)*cw, (r+1)*ch)))
|
| 44 |
+
return frames # 9 frames, temporal order
|
| 45 |
+
|
| 46 |
+
def build(task, demo_type):
|
| 47 |
+
root = Path(f"{DATA_ROOT}/{task}/episode_0001")
|
| 48 |
+
init = Image.open(root/"prompt"/"init_frame.png").convert("RGB")
|
| 49 |
+
demo_png = root/"demos"/f"{demo_type}_demo_01.png"
|
| 50 |
+
board = Image.open(demo_png).convert("RGB")
|
| 51 |
+
frames = storyboard_frames(demo_png)
|
| 52 |
+
|
| 53 |
+
TARGET_W = 1280
|
| 54 |
+
# normalize widths
|
| 55 |
+
def rw(im, w):
|
| 56 |
+
return im.resize((w, round(im.height*w/im.width)))
|
| 57 |
+
|
| 58 |
+
# ---- Layout A: stacked (demo storyboard on top of query) ----
|
| 59 |
+
b = rw(board, TARGET_W)
|
| 60 |
+
q = rw(init, TARGET_W)
|
| 61 |
+
lb1 = label_bar(TARGET_W, "EXAMPLE (reference physics: watch the interaction)")
|
| 62 |
+
lb2 = label_bar(TARGET_W, "QUERY (animate THIS scene with the SAME physics)")
|
| 63 |
+
Ha = lb1.height + b.height + lb2.height + q.height
|
| 64 |
+
A = Image.new("RGB", (TARGET_W, Ha), (255,255,255))
|
| 65 |
+
y=0
|
| 66 |
+
for part in (lb1, b, lb2, q):
|
| 67 |
+
A.paste(part, (0,y)); y+=part.height
|
| 68 |
+
pa = OUT/f"{task}_{demo_type}_A_stacked.png"
|
| 69 |
+
A.save(pa)
|
| 70 |
+
|
| 71 |
+
# ---- Layout B: filmstrip (demo start | demo end | query) 16:9-ish ----
|
| 72 |
+
cell_w = 640
|
| 73 |
+
fs = rw(frames[0], cell_w) # demo before
|
| 74 |
+
fe = rw(frames[-1], cell_w) # demo after
|
| 75 |
+
qb = rw(init, cell_w) # query
|
| 76 |
+
ch = max(fs.height, fe.height, qb.height)
|
| 77 |
+
lbh = 40
|
| 78 |
+
B = Image.new("RGB", (cell_w*3, ch+lbh), (255,255,255))
|
| 79 |
+
for i,(im,txt) in enumerate([(fs,"EX: before"),(fe,"EX: after"),(qb,"QUERY -> animate")]):
|
| 80 |
+
B.paste(label_bar(cell_w, txt, h=lbh), (i*cell_w,0))
|
| 81 |
+
B.paste(im, (i*cell_w, lbh))
|
| 82 |
+
pb = OUT/f"{task}_{demo_type}_B_filmstrip.png"
|
| 83 |
+
B.save(pb)
|
| 84 |
+
|
| 85 |
+
print(f"{task}: A={pa.name} {A.size} B={pb.name} {B.size}")
|
| 86 |
+
return pa, pb
|
| 87 |
+
|
| 88 |
+
if __name__ == "__main__":
|
| 89 |
+
ap = argparse.ArgumentParser()
|
| 90 |
+
ap.add_argument("tasks", nargs="+")
|
| 91 |
+
ap.add_argument("--demo", default="good")
|
| 92 |
+
a = ap.parse_args()
|
| 93 |
+
for t in a.tasks:
|
| 94 |
+
build(t, a.demo)
|
collage_experiment/gen/crop_query_panel.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Crop the bottom QUERY panel from an 832x944 collage-i2v output and make a
|
| 3 |
+
temporal frame strip for per-axis judging. Query panel = y>=467 (bottom 477px).
|
| 4 |
+
|
| 5 |
+
Usage: python3 crop_query_panel.py <video.mp4> <out_prefix> [n_frames=6]
|
| 6 |
+
Outputs: <out_prefix>_query_strip.png (+ per-frame pngs in <out_prefix>_frames/)
|
| 7 |
+
"""
|
| 8 |
+
import sys, os, subprocess, json
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
from PIL import Image
|
| 11 |
+
|
| 12 |
+
QY0 = 467 # storyboard/query split for 832x944 composites (storyboard top ~467px)
|
| 13 |
+
|
| 14 |
+
def probe(v):
|
| 15 |
+
r = subprocess.run(["ffprobe","-v","quiet","-print_format","json","-show_streams",v],
|
| 16 |
+
capture_output=True, text=True)
|
| 17 |
+
s = [x for x in json.loads(r.stdout)["streams"] if x["codec_type"]=="video"][0]
|
| 18 |
+
return int(s["width"]), int(s["height"]), int(s.get("nb_frames") or 0)
|
| 19 |
+
|
| 20 |
+
def main():
|
| 21 |
+
v = sys.argv[1]; pref = sys.argv[2]; n = int(sys.argv[3]) if len(sys.argv)>3 else 6
|
| 22 |
+
W,H,NF = probe(v)
|
| 23 |
+
qy0 = QY0 if H==944 else round(H*467/944) # scale split if H differs
|
| 24 |
+
fr = Path(pref+"_frames"); fr.mkdir(parents=True, exist_ok=True)
|
| 25 |
+
NF = NF or 121
|
| 26 |
+
idxs = [round(i*(NF-1)/(n-1)) for i in range(n)]
|
| 27 |
+
crops = []
|
| 28 |
+
for i in idxs:
|
| 29 |
+
raw = fr/f"raw_{i}.png"
|
| 30 |
+
subprocess.run(["ffmpeg","-y","-loglevel","quiet","-i",v,"-vf",f"select=eq(n\\,{i})",
|
| 31 |
+
"-vframes","1",str(raw)], check=False)
|
| 32 |
+
if raw.exists():
|
| 33 |
+
im = Image.open(raw).convert("RGB")
|
| 34 |
+
q = im.crop((0, qy0, im.width, im.height)) # bottom query panel
|
| 35 |
+
qp = fr/f"query_{i}.png"; q.save(qp); crops.append(q)
|
| 36 |
+
if crops:
|
| 37 |
+
w = crops[0].width; h = crops[0].height
|
| 38 |
+
strip = Image.new("RGB",(w*len(crops), h),(255,255,255))
|
| 39 |
+
for i,c in enumerate(crops): strip.paste(c,(i*w,0))
|
| 40 |
+
out = pref+"_query_strip.png"; strip.save(out)
|
| 41 |
+
print(f"query panel crop y>={qy0} (video {W}x{H}, {NF}f) -> {out} {strip.size}, frames {idxs}")
|
| 42 |
+
else:
|
| 43 |
+
print("no frames extracted")
|
| 44 |
+
|
| 45 |
+
if __name__ == "__main__":
|
| 46 |
+
main()
|
collage_experiment/gen/run_collage_v2.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Fire wan2.6-i2v-flash on a collage/puzzle visual-ICL image, using the repo's
|
| 3 |
+
verified Wan26Generator (720P / no audio / single shot -> cost-safe)."""
|
| 4 |
+
import os, sys, json, time, importlib.util
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
REPO = "/media/yu/Extreme SSD/siyuan_project/repos/MLLM-as-World-Judge"
|
| 8 |
+
sys.path.insert(0, REPO)
|
| 9 |
+
os.chdir(REPO)
|
| 10 |
+
from inference.wan_generator import Wan26Generator
|
| 11 |
+
spec = importlib.util.spec_from_file_location("rap", os.path.join(REPO, "run_api_parallel.py"))
|
| 12 |
+
rap = importlib.util.module_from_spec(spec); spec.loader.exec_module(rap)
|
| 13 |
+
|
| 14 |
+
KEYS = json.load(open("/tmp/dashscope_keys.json"))
|
| 15 |
+
OUT = Path("/tmp/physical_icl/gen/collage"); OUT.mkdir(parents=True, exist_ok=True)
|
| 16 |
+
|
| 17 |
+
PROMPT_STACKED = (
|
| 18 |
+
"This image is a visual in-context example composed of two parts. "
|
| 19 |
+
"The TOP part (labeled EXAMPLE) is a reference demonstration showing a physical "
|
| 20 |
+
"interaction: an object is released, falls under gravity, and deforms the soft "
|
| 21 |
+
"surface it lands on. The BOTTOM part (labeled QUERY) is the scene to animate. "
|
| 22 |
+
"Generate a physically plausible continuation of ONLY the bottom QUERY scene: the "
|
| 23 |
+
"two grabber tools let go of the tennis ball and the orange block, which fall onto "
|
| 24 |
+
"the two pillows and press/deform them, following the same kind of soft-surface, "
|
| 25 |
+
"gravity-driven physics shown in the example. Keep the top EXAMPLE panels unchanged. "
|
| 26 |
+
"Do not copy the example's objects, colors, or background. Static camera, no camera movement."
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
def run(task, image, layout="A"):
|
| 30 |
+
# DashScope needs min side >= 240; ensure_dashscope_dims upscales if needed.
|
| 31 |
+
img = rap.ensure_dashscope_dims(image)
|
| 32 |
+
print(f"=== firing {task} layout={layout} img={img} ===", flush=True)
|
| 33 |
+
url = None; last_err = None
|
| 34 |
+
for i, key in enumerate(KEYS):
|
| 35 |
+
try:
|
| 36 |
+
gen = Wan26Generator(api_key=key, model="wan2.6-i2v-flash")
|
| 37 |
+
print(f" trying key[{i}] ...", flush=True)
|
| 38 |
+
url = gen.generate(prompt=PROMPT_STACKED, img_path=img, duration=5)
|
| 39 |
+
break
|
| 40 |
+
except Exception as e:
|
| 41 |
+
last_err = e; print(f" key[{i}] failed: {str(e)[:120]}", flush=True)
|
| 42 |
+
if url is None:
|
| 43 |
+
raise SystemExit(f"ALL KEYS FAILED: {last_err}")
|
| 44 |
+
dest = OUT / f"{task}_collage_{layout}.mp4"
|
| 45 |
+
rap.download_video(url, str(dest))
|
| 46 |
+
frames = OUT / f"{task}_collage_{layout}_frames"
|
| 47 |
+
try: rap.try_extract_frames(str(dest), str(frames))
|
| 48 |
+
except Exception as e: print("frame extract warn:", e)
|
| 49 |
+
print(f"SAVED {dest} ({dest.stat().st_size//1024} KB) url={url}", flush=True)
|
| 50 |
+
with open(OUT/"results.jsonl","a") as fh:
|
| 51 |
+
fh.write(json.dumps({"task":task,"layout":layout,"video_url":url,"local":str(dest)})+"\n")
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
task = sys.argv[1] if len(sys.argv)>1 else "task_0001"
|
| 55 |
+
image = sys.argv[2] if len(sys.argv)>2 else "/tmp/physical_icl/collage/task_0001_good_A_stacked.png"
|
| 56 |
+
layout = sys.argv[3] if len(sys.argv)>3 else "A"
|
| 57 |
+
run(task, image, layout)
|
collage_experiment/judge/task_0003_GT_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0003_cosmos3.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:277095f180679ae08619abde000a5d03c1bd9cad101f71b9df231e9f5e48f01c
|
| 3 |
+
size 219295
|
collage_experiment/judge/task_0003_cosmos3_query_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0003_wan_query_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0003_wan_query_zoom.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0035_GT_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0035_cosmos3.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:14c3e7e7caa007c266fc3140ae579c2b50c8d91a007165ea95e6c565aee21d49
|
| 3 |
+
size 529766
|
collage_experiment/judge/task_0035_cosmos3_query_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0035_wan_query_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0065_3way.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0065_GT_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0065_cosmos3.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9e82c9b05843f043e2767ca927492f1f45a6489e2b098dc2d640c924e07d762f
|
| 3 |
+
size 282776
|
collage_experiment/judge/task_0065_cosmos3_query_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0065_wan_FULL_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/judge/task_0065_wan_query_strip.png
ADDED
|
Git LFS Details
|
collage_experiment/research/basemodel_survey.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ICL VideoGen Base Models — Comparison
|
| 2 |
+
|
| 3 |
+
Goal: open-source, strong, supports **test video + image + mixed instruction** conditional
|
| 4 |
+
video generation, usable as a **post-train base** for in-context-learning (ICL) videogen.
|
| 5 |
+
|
| 6 |
+
_Compiled 2026-07-15 (each row verified against the model's repo/paper)._
|
| 7 |
+
|
| 8 |
+
| Model | Foundation model | Supports test video/image/instruction (how) | Open inference | Open finetune | Released | Benchmark |
|
| 9 |
+
|---|---|---|:---:|:---:|---|---|
|
| 10 |
+
| **VAP** (Video-As-Prompt, ByteDance) | CogVideoX-I2V-5B / Wan2.1-I2V-14B (+5B MoT expert) | Reference **video** = semantic prompt, in-context; **frozen base + trained plug-in MoT expert** | ✅ | ✅ SFT / DPO / multi-ref | 2025-10 (ICLR'26) | user-pref 38.7% (>Kling/Vidu 38.2); VBench motion 98.59 / align 70.44 |
|
| 11 |
+
| **UniVideo** (Kling Team) | HunyuanVideo + Qwen2.5-VL | MLLM parses **free-form text/image/video instruction** → MMDiT; in-context gen + edit | ✅ | ✅ (`TRAINING.md`) | arxiv 2025-10 / weights 2026-01 (ICLR'26) | **VBench-T2V 83.48**; MMBench 83.5; GenEval 0.69; ImgEdit 3.83 |
|
| 12 |
+
| **LoomVideo** (PKU MSALab) | Self-built **5B DiT + MLLM** (MLLM replaces text encoder) | Interleaved: video+text / video+image+text / **multi-image+text**; Deepstack Injection + Negative-Temporal-RoPE | ✅ (`scripts/inference/generate.py`, HF wts `MSALab/LoomVideo`) | ✅ (`scripts/train` + YAML) | arxiv 2606.06042 = **2026-06-05** | VBench / OpenVE / RefVIE / GenEval / ImgEdit (SOTA claim, 5.41× speedup) |
|
| 13 |
+
| **VACE** (Wan2.1-VACE, Alibaba) | Wan2.1 (14B + 1.3B) / LTX-Video 0.9 | VCU: text+image+video+mask; ref-to-video + **depth/flow control channels** | ✅ | ❌ (no official; community LoRA) | 2025-03 code / 05 weights (ICCV'25) | VACE-Benchmark (no public unified score) |
|
| 14 |
+
| **VINO** | HunyuanVideo (DiT) + Qwen3VL (VLM) | **Interleaved omnimodal**: text + ref-image + ref-video → unified conditioning tokens | ✅ | ❌ (no train code) | arxiv 2026-01-05 | claims multi-bench SOTA (no single public number) |
|
| 15 |
+
|
| 16 |
+
## Note on the "Benchmark" column
|
| 17 |
+
There is **no single unified benchmark** all five are scored on head-to-head. **VBench** is the
|
| 18 |
+
closest common framework, but each paper reports a different subset (UniVideo reports full VBench-T2V
|
| 19 |
+
83.48; VAP reports only motion/align sub-scores; VACE/VINO give no directly-comparable VBench number).
|
| 20 |
+
→ The column reflects each model's *own* claims and **cannot be used to rank them directly**. For a
|
| 21 |
+
real apples-to-apples comparison we'd have to re-run them on one suite (e.g. VBench-I2V or our own
|
| 22 |
+
physical-ICL set).
|
| 23 |
+
|
| 24 |
+
## Post-train-friendliness (open inference **and** finetune)
|
| 25 |
+
Only **VAP** (frozen base + trainable expert), **UniVideo**, and **LoomVideo** ship training code.
|
| 26 |
+
**VACE** and **VINO** are inference-only (no official training) → post-training them means writing
|
| 27 |
+
your own training loop.
|
| 28 |
+
|
| 29 |
+
## Recommendation
|
| 30 |
+
- **Lightest + training code + best fit for video+image+mixed instruction** → **LoomVideo** (only 5B,
|
| 31 |
+
interleaved multi-image+text, very new 2026-06). Try first.
|
| 32 |
+
- **Benchmark-backed + strong mixed-instruction + full training** → **UniVideo** (heavier: HunyuanVideo base).
|
| 33 |
+
- **Cheapest to start post-training** → **VAP** (freeze base, train only the expert; ships VAP-Data).
|
| 34 |
+
- **Physical-control channels (depth/flow)** → **VACE** (good when you need explicit motion/physics control).
|
| 35 |
+
- **VINO** — best architectural fit (unified omnimodal ICL) but **no training code**; watch for release.
|
| 36 |
+
|
| 37 |
+
## Sources
|
| 38 |
+
- VAP: <https://github.com/bytedance/Video-As-Prompt> (arxiv 2510.20888)
|
| 39 |
+
- UniVideo: <https://github.com/KlingTeam/UniVideo> (arxiv 2510.08377)
|
| 40 |
+
- LoomVideo: <https://github.com/MSALab-PKU/LoomVideo> (PKU + Alibaba, arxiv 2606.06042; HF weights `MSALab/LoomVideo`)
|
| 41 |
+
- VACE: <https://github.com/ali-vilab/VACE> (ICCV 2025)
|
| 42 |
+
- VINO: <https://github.com/SOTAMak1r/VINO-code> (arxiv 2601.02358)
|
collage_experiment/scorer/fov_sanity_all.png
ADDED
|
Git LFS Details
|
collage_experiment/scorer/physics_iq_results.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"metric": "Physics-IQ raw components (unnormalized; single real take, no real-real variance norm)",
|
| 3 |
+
"window_s": 5.0, "n_frames": 48, "size": 256, "thresh": 0.08,
|
| 4 |
+
"fov_check": "wan query-panel FOV verified aligned to GT scene on all 3 tasks (_sanity_all.png)",
|
| 5 |
+
"higher_better": ["spatial_iou","spatiotemporal_iou","weighted_spatial_iou"],
|
| 6 |
+
"lower_better": ["mse"],
|
| 7 |
+
"results": {
|
| 8 |
+
"task_0065_compress": {"wan":{"spatial_iou":0.2821,"spatiotemporal_iou":0.2064,"weighted_spatial_iou":0.24,"mse":0.05119},
|
| 9 |
+
"cosmos3":{"spatial_iou":0.5471,"spatiotemporal_iou":0.2037,"weighted_spatial_iou":0.6272,"mse":0.04964}},
|
| 10 |
+
"task_0003_collision": {"wan":{"spatial_iou":0.0826,"spatiotemporal_iou":0.1249,"weighted_spatial_iou":0.0773,"mse":0.01276},
|
| 11 |
+
"cosmos3":{"spatial_iou":0.3693,"spatiotemporal_iou":0.0001,"weighted_spatial_iou":0.3792,"mse":0.00781}},
|
| 12 |
+
"task_0035_ramp": {"wan":{"spatial_iou":0.0214,"spatiotemporal_iou":0.0309,"weighted_spatial_iou":0.0426,"mse":0.01365},
|
| 13 |
+
"cosmos3":{"spatial_iou":0.0554,"spatiotemporal_iou":0.0223,"weighted_spatial_iou":0.2185,"mse":0.01031}}
|
| 14 |
+
},
|
| 15 |
+
"means": {"wan":{"spatial_iou":0.129,"weighted_spatial_iou":0.120},"cosmos3":{"spatial_iou":0.324,"weighted_spatial_iou":0.408}},
|
| 16 |
+
"conclusion": "wan2.6-flash collage-i2v underperforms cosmos3-Nano ICL baseline on all 3 (spatial/weighted IoU, MSE); under-produces + mislocalizes the physical motion. FOV aligned so not an artifact."
|
| 17 |
+
}
|
collage_experiment/scorer/physics_iq_score.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
physics_iq_score.py (CC, Physical-ICL)
|
| 4 |
+
|
| 5 |
+
Reference-based Physics-IQ *component* metrics comparing a generated video's
|
| 6 |
+
query panel against the real Physics-IQ GT continuation.
|
| 7 |
+
|
| 8 |
+
Protocol notes (be honest about what this is):
|
| 9 |
+
* The canonical Physics-IQ Score (0-100%) normalizes each metric by the
|
| 10 |
+
real-vs-real physical variance (a 2nd real take). We only have ONE real
|
| 11 |
+
take per task here, so we report the RAW (unnormalized) components:
|
| 12 |
+
- Spatial IoU (where motion happens, union over time)
|
| 13 |
+
- Spatiotemporal IoU (where AND when, per-frame mask IoU, mean over t)
|
| 14 |
+
- Weighted spatial IoU (soft IoU on continuous motion magnitude)
|
| 15 |
+
- MSE (pixel error inside GT motion region, lower=better)
|
| 16 |
+
* i2v conditioning = init frame only (frame 0). Full generated clip is the
|
| 17 |
+
"prediction"; compared against the matched real-time GT window.
|
| 18 |
+
* Both gen (wan) and GT are 30fps -> 5s window = 150 frames, clean match.
|
| 19 |
+
cosmos3 baseline is 24fps -> its 5s window sampled at the same timestamps.
|
| 20 |
+
|
| 21 |
+
Usage:
|
| 22 |
+
python3 physics_iq_score.py <gen.mp4> <gt.mp4> [--panel] [--win 5.0] [--n 48]
|
| 23 |
+
--panel : crop bottom query panel (y>=0.495*H) from gen (collage output)
|
| 24 |
+
"""
|
| 25 |
+
import sys, json, subprocess, argparse
|
| 26 |
+
import numpy as np
|
| 27 |
+
import cv2
|
| 28 |
+
|
| 29 |
+
SIZE = 256 # common working grid (stretch both to SIZE x SIZE)
|
| 30 |
+
PANEL_SPLIT = 0.495 # storyboard/query split ratio (Vita: bottom ~50.5%)
|
| 31 |
+
THRESH = 0.08 # binarization threshold on normalized frame-diff
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def probe(v):
|
| 35 |
+
r = subprocess.run(["ffprobe", "-v", "quiet", "-print_format", "json",
|
| 36 |
+
"-show_streams", v], capture_output=True, text=True)
|
| 37 |
+
s = [x for x in json.loads(r.stdout)["streams"] if x["codec_type"] == "video"][0]
|
| 38 |
+
fps = eval(s["r_frame_rate"]) if "/" in s["r_frame_rate"] else float(s["r_frame_rate"])
|
| 39 |
+
return int(s["width"]), int(s["height"]), fps, float(s.get("duration") or 0)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def load_frames(v, n, win, panel=False):
|
| 43 |
+
"""Sample n frames uniformly over [0, win] seconds; optional bottom-panel crop;
|
| 44 |
+
return float array [n, SIZE, SIZE] grayscale in [0,1]."""
|
| 45 |
+
W, H, fps, dur = probe(v)
|
| 46 |
+
ts = [i * win / (n - 1) for i in range(n)]
|
| 47 |
+
cap = cv2.VideoCapture(v)
|
| 48 |
+
frames = []
|
| 49 |
+
for t in ts:
|
| 50 |
+
cap.set(cv2.CAP_PROP_POS_MSEC, t * 1000.0)
|
| 51 |
+
ok, fr = cap.read()
|
| 52 |
+
if not ok:
|
| 53 |
+
fr = np.zeros((H, W, 3), np.uint8)
|
| 54 |
+
if panel:
|
| 55 |
+
y0 = int(round(fr.shape[0] * PANEL_SPLIT))
|
| 56 |
+
fr = fr[y0:, :, :]
|
| 57 |
+
g = cv2.cvtColor(fr, cv2.COLOR_BGR2GRAY)
|
| 58 |
+
g = cv2.resize(g, (SIZE, SIZE), interpolation=cv2.INTER_AREA)
|
| 59 |
+
frames.append(g.astype(np.float32) / 255.0)
|
| 60 |
+
cap.release()
|
| 61 |
+
return np.stack(frames) # [n,SIZE,SIZE]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def motion(frames):
|
| 65 |
+
"""Per-frame abs-diff from frame0 -> [n,SIZE,SIZE] in [0,1]."""
|
| 66 |
+
ref = frames[0]
|
| 67 |
+
return np.abs(frames - ref[None])
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def metrics(gen, gt):
|
| 71 |
+
mg, mt = motion(gen), motion(gt) # [n,H,W]
|
| 72 |
+
bg, bt = mg > THRESH, mt > THRESH # binary per-frame action
|
| 73 |
+
|
| 74 |
+
# Spatial IoU (union over time)
|
| 75 |
+
sg, st = bg.any(0), bt.any(0)
|
| 76 |
+
inter = np.logical_and(sg, st).sum()
|
| 77 |
+
union = np.logical_or(sg, st).sum()
|
| 78 |
+
spatial_iou = inter / union if union else 0.0
|
| 79 |
+
|
| 80 |
+
# Spatiotemporal IoU (per-frame, mean over t where either is active)
|
| 81 |
+
st_ious = []
|
| 82 |
+
for i in range(bg.shape[0]):
|
| 83 |
+
u = np.logical_or(bg[i], bt[i]).sum()
|
| 84 |
+
if u:
|
| 85 |
+
st_ious.append(np.logical_and(bg[i], bt[i]).sum() / u)
|
| 86 |
+
spatiotemporal_iou = float(np.mean(st_ious)) if st_ious else 0.0
|
| 87 |
+
|
| 88 |
+
# Weighted (soft) spatial IoU on continuous magnitude (max over time)
|
| 89 |
+
Mg, Mt = mg.max(0), mt.max(0)
|
| 90 |
+
soft_iou = float(np.minimum(Mg, Mt).sum() / max(np.maximum(Mg, Mt).sum(), 1e-8))
|
| 91 |
+
|
| 92 |
+
# MSE inside GT motion region (union over time), on gray [0,1]
|
| 93 |
+
region = st # GT spatial action mask
|
| 94 |
+
if region.sum():
|
| 95 |
+
diff2 = (gen - gt) ** 2 # [n,H,W]
|
| 96 |
+
mse = float(diff2[:, region].mean())
|
| 97 |
+
else:
|
| 98 |
+
mse = float(((gen - gt) ** 2).mean())
|
| 99 |
+
|
| 100 |
+
return {"spatial_iou": round(spatial_iou, 4),
|
| 101 |
+
"spatiotemporal_iou": round(spatiotemporal_iou, 4),
|
| 102 |
+
"weighted_spatial_iou": round(soft_iou, 4),
|
| 103 |
+
"mse": round(mse, 5)}
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def main():
|
| 107 |
+
ap = argparse.ArgumentParser()
|
| 108 |
+
ap.add_argument("gen"); ap.add_argument("gt")
|
| 109 |
+
ap.add_argument("--panel", action="store_true")
|
| 110 |
+
ap.add_argument("--gt-panel", action="store_true")
|
| 111 |
+
ap.add_argument("--win", type=float, default=5.0)
|
| 112 |
+
ap.add_argument("--n", type=int, default=48)
|
| 113 |
+
a = ap.parse_args()
|
| 114 |
+
gen = load_frames(a.gen, a.n, a.win, panel=a.panel)
|
| 115 |
+
gt = load_frames(a.gt, a.n, a.win, panel=a.gt_panel)
|
| 116 |
+
m = metrics(gen, gt)
|
| 117 |
+
print(json.dumps(m))
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
if __name__ == "__main__":
|
| 121 |
+
main()
|
collage_experiment/videos/task_0003_wan26flash_480p.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c53dc9b2a9db9fc471318ddaad8fab47b51ae396202624e826ad5a767071c132
|
| 3 |
+
size 1054679
|
collage_experiment/videos/task_0035_wan26flash_480p.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:03e72b94ceedc76b30b1ac83625b9f95b788d6e59dd2770250cf50af3645216c
|
| 3 |
+
size 1123970
|
collage_experiment/videos/task_0065_wan26flash_480p.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:42ba3f3a151e3c6f42de6ab494bb6023512a5f97a2799641b9bafc5215c5d0f1
|
| 3 |
+
size 855605
|