paper_final_results / figure_data /plot_qualitative_cases.py
SitongGong's picture
upload paper_final_results (part 2)
a83d3e5 verified
Raw History Blame Contribute Delete
16 kB
# -*- coding: utf-8 -*-
"""GROVE 定性结果图: 每case = 视频帧时间线(证据帧红框) + Q气泡 + GT行 + Ours行
拆成两张图:
qualitative_cases_qa.pdf = OVO-Bench (3) + MMLifelong (1) + ESTP (2) —— 问答类
qualitative_cases_service.pdf = EgoServe 即时安全 (1) + 中长期例程优化 (1) —— 主动服务类
同时仍输出合并版 qualitative_cases.pdf (向后兼容)。
每个 case 用 `strip` 字段指定自己的帧目录; 帧文件名 = {prefix}_{k}.jpg, 证据帧后缀 _EV.jpg。
"""
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.patches import FancyBboxPatch, Rectangle
import matplotlib.image as mpimg
import numpy as np, os, textwrap
FC = "/mnt/tokyo-ai/gst/paper_final_results/figure_cases"
S_OVO = f"{FC}/ovo_backward/strip" # OVO + EgoServe 即时(stairs)
S_MM = f"{FC}/mmlifelong/strip"
S_ESTP = f"{FC}/estp/strip"
S_LT = f"{FC}/egoserve_longterm/strip"
OUTDIR = "/mnt/tokyo-ai/gst/paper_final_results/figure_data"
os.makedirs(OUTDIR, exist_ok=True)
# 配色
C_FRAME_BG = "#EAF2FB" # 帧排底色 浅蓝
C_Q = "#DDF2F3" # Q气泡 浅青
C_Q_EDGE = "#7FBFC4"
C_GT = "#F0F0F0" # GT 浅灰
C_GT_EDGE = "#B8B8B8"
C_OURS = "#DFF3E0" # Ours 浅绿
C_OURS_EDGE= "#5FA968"
C_EV = "#D62728" # 证据帧红框
C_HL = "#1F5FA8" # 问题关键短语蓝
C_OK = "#2E7D32"
# ===========================================================================
# 所有 case 均为「真实答对」样本, Q / GT / 我们的回答全部取自评测文件英文原文
# ===========================================================================
CASES_QA = [
dict(
tag="OVO-Bench · Backward (EPM)",
strip=S_OVO, prefix="microwave", n=6,
span="evidence @ 03:54 → question @ 07:47 (look-back 3.9 min)",
ev_cap="closes the microwave door",
q_pre="", q_hl="Did I close the microwave?", q_post="",
opts="A. yes B. no",
gt="A. yes",
ours="A. yes",
ours_note="“Video facts show the camera-wearer pressing down and closing the silver microwave door (DAY1-00:07:44) and then pressing the control buttons to set 1:00, so the microwave was closed.”",
),
dict(
tag="OVO-Bench · Backward (EPM)",
strip=S_OVO, prefix="scraper", n=6,
span="evidence @ 00:25–00:30 → question @ 19:58 (look-back 19.6 min)",
ev_cap="the dough cutter in use",
q_pre="", q_hl="Where was the dough cutter before I picked it?", q_post="",
opts="A. Table B. Floor C. Cabinet D. Shelf",
gt="A. Table",
ours="Table",
ours_note="“The entity log shows a ‘dough scraper [metal blade, wooden handle]’ located on the table just before the pick-up event, so it was on the table.”",
),
dict(
tag="OVO-Bench · Backward (ASI)",
strip=S_OVO, prefix="pierogi", n=6,
span="anchor step “boil” @ 07:30 → successor step @ 08:20 (spans the full 9-min recipe)",
ev_cap="pan-frying the boiled pierogies",
q_pre="What does the person do after ", q_hl="boil the wrapped pierogies in boiling salted water", q_post="",
opts="A. fry the boiled pierogies with a little oil in a pan and then serve B. combine the meat with half of the onion salt bay leaf dried\nmushrooms peppercorns and water C. wrap the meat mixture in the small dough portions D. keep rolling until you get 1 to 2 mm thick dough",
gt="A. fry the boiled pierogies with a little oil in a pan and then serve",
ours="A. fry the boiled pierogies with a little oil in a pan and then serve",
ours_note="“The video shows golden-brown pan-fried dumplings and the sequence after boiling the sealed pierogies proceeds to pan-fry them to crisp the bottoms, matching option A.”",
),
# ---------------- MMLifelong: 25h+ 超长视频里的几秒细节 ----------------
dict(
tag="MM-Lifelong · month scale (Entity Recognition)",
strip=S_MM, prefix="hotpot", n=6,
span="evidence @ 03:40:15 of a 5.4-h video — hour 61 of a 99-hour, 22-video multi-day recording (needle-in-a-haystack)",
ev_cap="sipping the green soy-milk bottle",
q_pre="", q_hl="What drink did the streamer have when eating hot pot in Chengdu, China?", q_post="",
opts="",
gt="Soy milk",
ours="Soy milk",
ours_note="“During the Chengdu hot pot segment, the facts show him picking up and sipping a green bottle labeled ‘Soy Milk’ through a straw while eating.” — official judge (gpt-5) Final Score = 5/5",
),
# ---------------- ESTP-Bench: 半主动服务 ----------------
dict(
tag="ESTP-Bench · Contextual QA (Object Relative Context)",
strip=S_ESTP, prefix="stopsign", n=6,
span="user asks @ 31:49 → system stays silent and keeps watching → fires @ 31:58, the moment the sign enters view (54-min drive)",
ev_cap="the red STOP sign comes into view",
q_pre="", q_hl="Could you remind me when I see the red road sign saying “STOP”?", q_post="",
opts="",
gt="There is a red road sign on your right hand side saying “STOP”.",
ours="You see the red ‘STOP’ sign now.",
ours_note="emitted at t = 1918.0 s, inside the GT evidence window 1916.0–1920.5 s — DeepSeek judge correctness = 5.0 / 5",
),
dict(
tag="ESTP-Bench · Contextual QA (Object Relative Context)",
strip=S_ESTP, prefix="ladder", n=6,
span="question @ 14:05 → answered @ 14:11 from the streaming memory (22-min studio session)",
ev_cap="red ladder against the white wall",
q_pre="", q_hl="Could you tell me where the red ladder in the room is?", q_post="",
opts="",
gt="The red ladder stands by the wall on the left.",
ours="The red ladder is standing against the plain white wall to your left.",
ours_note="emitted at t = 851.0 s, inside the GT evidence window 851.0–872.5 s — DeepSeek judge correctness = 5.0 / 5",
),
]
CASES_SERVICE = [
dict(
tag="EgoServe / EgoLife · Proactive Service — Instant (safety)",
strip=S_OVO, prefix="stairs", n=6,
span="continuous egocentric stream → hazard trigger @ DAY3 12:12:00 (no user query — the system speaks first)",
ev_cap="descending stairs, eyes on phone",
q_pre="", q_hl="[ no question asked ]", q_post=" user is walking down the stairs while reading messages on the phone",
opts="",
gt="Be careful; walking down the stairs while staring at your phone is risky.",
ours="Careful — you're looking at your phone while going down the stairs, which could\nmake you lose your footing. Please pause and watch your step.",
ours_note="matched to GT event safety_001 (sub-type “safety”, overlapping time window)",
),
# ---------------- 中长期: 跨时段 pattern 层 ----------------
dict(
tag="EgoServe / EgoLife · Proactive Service — Long-Term (routine_optimization)",
strip=S_LT, prefix="assembly", n=6,
span="the same furniture-assembly routine recurs on DAY1 12:52 and DAY4 12:25 → recognised again and acted on @ DAY4 17:13 (a 4-day, cross-session pattern — not a single-clip cue)",
ev_cap="assembling the storage drawers again",
q_pre="", q_hl="[ no question asked ]", q_post=" user starts assembling yet another storage unit",
opts="",
gt="I see you're assembling another storage unit. Would you like me to search for an\nassembly video for this model to help you out?",
ours="You're assembling storage drawers again. Want me to pull up your last assembly\nphotos/checklist, auto-display the instruction steps for this model, or create a\nquick parts/tools checklist to streamline the process?",
ours_note="“ROUTINE_CANDIDATES: multiple prior furniture-assembly episodes (DAY4 12:25:30, DAY1 12:52:00, etc.). Current window shows assembly restarting around 17:13:00.” — strict sub-type match, GT DAY4 17:13:01 vs ours DAY4 17:13:00. Requires the cross-session pattern layer: the trigger is the repetition itself, which no single frame contains.",
),
]
# ---- 版面度量 (figure 坐标, 0-1) ----
L, R = 0.035, 0.965
W = R - L
H_TAG = 0.34
H_STRIP = 1.52
H_SPAN = 0.24
H_Q = 0.50
H_OPT = 0.36
H_GT = 0.40
H_OURS = 0.86
H_GAP = 0.50
def case_height(c):
h = H_TAG + H_STRIP + H_SPAN + H_Q + H_GT + H_OURS
if c["opts"]:
h += H_OPT * (1 + c["opts"].count("\n"))
h += 0.30 * c["ours"].count("\n")
h += 0.30 * c["gt"].count("\n")
h += 0.16 * (len(textwrap.fill(c["ours_note"], 118).split("\n")) - 1)
return h
def render(cases, title, outname):
FIG_W = 13.6
FIG_H = sum(case_height(c) for c in cases) + H_GAP * (len(cases) - 1) + 1.05
fig = plt.figure(figsize=(FIG_W, FIG_H))
fig.patch.set_facecolor("white")
def fw(x_in): return x_in / FIG_W
def fh(y_in): return y_in / FIG_H
def rbox(x, y, w, h, fc, ec, lw=1.1, r=0.012, z=2):
p = FancyBboxPatch((x, y), w, h, boxstyle=f"round,pad=0,rounding_size={r}",
facecolor=fc, edgecolor=ec, linewidth=lw,
transform=fig.transFigure, zorder=z,
mutation_aspect=FIG_W / FIG_H)
fig.patches.append(p); return p
def txt(x, y, s, size=9.5, color="#1a1a1a", weight="normal", ha="left", va="center",
style="normal", family="DejaVu Sans", z=5, **kw):
return fig.text(x, y, s, fontsize=size, color=color, fontweight=weight, ha=ha, va=va,
style=style, family=family, zorder=z, **kw)
fig.text(0.5, 1 - fh(0.30), title, ha="center", va="center",
fontsize=15.5, fontweight="bold", color="#12253d")
y_cur = 1.0 - fh(0.58)
for c in cases:
S = c["strip"]
# ---------- tag ----------
y_cur -= fh(H_TAG)
txt(L, y_cur + fh(0.185), c["tag"], size=10.5, weight="bold", color="#12253d")
bw, bh = fw(1.02), fh(0.20)
rbox(R - bw, y_cur + fh(0.085), bw, bh, C_OURS, C_OURS_EDGE, lw=1.0, r=0.010)
txt(R - bw / 2, y_cur + fh(0.085) + bh / 2, "✓ CORRECT", size=8.6, weight="bold",
color=C_OK, ha="center")
fig.add_artist(plt.Line2D([L, R], [y_cur + fh(0.045)] * 2, color="#c9d6e4", lw=0.9,
transform=fig.transFigure, zorder=1))
# ---------- 帧排 ----------
y_cur -= fh(H_STRIP)
rbox(L, y_cur, W, fh(H_STRIP), C_FRAME_BG, "#BBD3EA", lw=1.0, r=0.010, z=1)
n = c["n"]
pad = fw(0.13)
gap = fw(0.075)
avail = W - 2 * pad - gap * (n - 1)
cw = avail / n
inner_h = fh(H_STRIP) - fh(0.62)
y_img = y_cur + fh(0.30)
for k in range(n):
fn = f"{S}/{c['prefix']}_{k}.jpg"
fn_ev = f"{S}/{c['prefix']}_{k}_EV.jpg"
is_ev = os.path.exists(fn_ev)
path = fn_ev if is_ev else fn
if not os.path.exists(path):
continue
im = mpimg.imread(path)
ih, iw = im.shape[:2]
ar = iw / ih
h_ax = inner_h
w_ax = h_ax * ar * (FIG_H / FIG_W)
if w_ax > cw:
w_ax = cw
h_ax = w_ax / ar * (FIG_W / FIG_H)
x_ax = L + pad + k * (cw + gap) + (cw - w_ax) / 2
yy = y_img + (inner_h - h_ax) / 2
ax = fig.add_axes([x_ax, yy, w_ax, h_ax], zorder=3)
ax.imshow(im); ax.set_xticks([]); ax.set_yticks([])
for sp in ax.spines.values():
sp.set_edgecolor(C_EV if is_ev else "#9DB4CC")
sp.set_linewidth(3.0 if is_ev else 0.8)
if is_ev:
fig.patches.append(Rectangle((x_ax - fw(0.028), yy - fh(0.028)),
w_ax + fw(0.056), h_ax + fh(0.056), fill=False, edgecolor=C_EV,
linewidth=1.5, transform=fig.transFigure, zorder=4))
txt(x_ax + w_ax / 2, yy + h_ax + fh(0.105), "key evidence frame", size=8.0,
weight="bold", color=C_EV, ha="center")
txt(x_ax + w_ax / 2, yy - fh(0.115), c["ev_cap"], size=7.6, color=C_EV,
ha="center", style="italic")
else:
txt(x_ax + w_ax / 2, yy - fh(0.115), "·", size=7.0, color="#9DB4CC", ha="center")
txt(L + fw(0.10), y_cur + fh(0.13), "video timeline (uniformly sampled frames)",
size=8.0, color="#5B7FA6", style="italic")
# ---------- 跨度说明 ----------
y_cur -= fh(H_SPAN)
txt(L + fw(0.04), y_cur + fh(0.10), c["span"], size=8.6, color="#7a5a00", style="italic")
# ---------- Q 气泡 ----------
y_cur -= fh(H_Q)
rbox(L, y_cur + fh(0.05), W, fh(H_Q) - fh(0.05), C_Q, C_Q_EDGE, lw=1.2, r=0.011)
qy = y_cur + fh(0.05) + (fh(H_Q) - fh(0.05)) / 2
txt(L + fw(0.16), qy, "Q:", size=11, weight="bold", color="#14606a")
xoff = L + fw(0.46)
rend = fig.canvas.get_renderer()
for seg, col, wt in [(c["q_pre"], "#1a1a1a", "normal"),
(c["q_hl"], C_HL, "bold"),
(c["q_post"], "#1a1a1a", "normal")]:
if not seg:
continue
t = txt(xoff, qy, seg, size=10.2, color=col, weight=wt)
bb = t.get_window_extent(renderer=rend)
xoff += bb.width / (FIG_W * fig.dpi)
# ---------- options ----------
if c["opts"]:
nl = 1 + c["opts"].count("\n")
y_cur -= fh(H_OPT * nl)
txt(L + fw(0.62), y_cur + fh(H_OPT * nl) / 2, c["opts"], size=8.5,
color="#4a5b6b", va="center")
# ---------- GT ----------
gt_lines = 1 + c["gt"].count("\n")
gt_in = H_GT + 0.24 * (gt_lines - 1)
y_cur -= fh(gt_in)
rbox(L, y_cur + fh(0.04), W, fh(gt_in) - fh(0.06), C_GT, C_GT_EDGE, lw=1.0, r=0.011)
gy = y_cur + fh(0.04) + (fh(gt_in) - fh(0.06)) / 2
txt(L + fw(0.16), gy, "GT", size=9.8, weight="bold", color="#4a4a4a")
txt(L + fw(1.42), gy, c["gt"], size=9.8, color="#2b2b2b", linespacing=1.35)
# ---------- Ours ----------
ans_lines = 1 + c["ours"].count("\n")
note = textwrap.fill(c["ours_note"], 118)
note_lines = 1 + note.count("\n")
box_in = 0.30 + 0.185 * ans_lines + 0.145 * note_lines
y_cur -= fh(box_in)
bh2 = fh(box_in) - fh(0.08)
rbox(L, y_cur + fh(0.04), W, bh2, C_OURS, C_OURS_EDGE, lw=1.4, r=0.011)
oy_top = y_cur + fh(0.04) + bh2
ny = oy_top - fh(0.18)
txt(L + fw(0.16), ny, "GROVE", size=9.8, weight="bold", color=C_OK, va="top")
txt(L + fw(0.72), ny, "(ours)", size=8.4, color="#5c8a63", style="italic", va="top")
txt(L + fw(1.42), ny, c["ours"], size=9.8, color="#14421a", weight="bold",
va="top", linespacing=1.35)
txt(L + fw(1.42), ny - fh(0.185 * ans_lines + 0.06), note, size=7.6, color="#4d6b52",
style="italic", va="top", linespacing=1.4)
y_cur -= fh(H_GAP)
fig.text(0.5, fh(0.16),
"Red box = the single frame containing the answer evidence; all other frames are uniformly sampled distractors that do not support the answer.",
ha="center", va="center", fontsize=8.3, color="#6b7a8a", style="italic")
fig.savefig(f"{OUTDIR}/{outname}.pdf", format="pdf", bbox_inches="tight", facecolor="white")
fig.savefig(f"{OUTDIR}/{outname}.png", dpi=170, bbox_inches="tight", facecolor="white")
plt.close(fig)
print(f"saved -> {OUTDIR}/{outname}.pdf ({len(cases)} cases, {FIG_H:.1f} in tall)")
render(CASES_QA,
"Qualitative results of GROVE on long-horizon egocentric question answering",
"qualitative_cases_qa")
render(CASES_SERVICE,
"Qualitative results of GROVE on proactive service (instant hazard vs. long-term routine)",
"qualitative_cases_service")
# 合并版(向后兼容)
render(CASES_QA + CASES_SERVICE,
"Qualitative results of GROVE on long-horizon egocentric benchmarks",
"qualitative_cases")