Download figure_data/plot_qualitative_cases.py.bak from SitongGong/paper_final_results: direct link, hf CLI and curl.
- Browser
- Download file 10.6 kB
-
https://huggingface.co/datasets/SitongGong/paper_final_results/resolve/main/figure_data/plot_qualitative_cases.py.bak
- Command line
-
hf download hf://datasets/SitongGong/paper_final_results/figure_data/plot_qualitative_cases.py.bak
-
curl -L -o plot_qualitative_cases.py.bak https://huggingface.co/datasets/SitongGong/paper_final_results/resolve/main/figure_data/plot_qualitative_cases.py.bak
10.6 kB
| # -*- coding: utf-8 -*- | |
| """GROVE 定性结果图: 每case = 视频帧时间线(证据帧红框) + Q气泡 + GT行 + Ours行""" | |
| 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 | |
| S = "/mnt/tokyo-ai/gst/paper_final_results/figure_cases/ovo_backward/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" | |
| CASES = [ | |
| dict( | |
| tag="OVO-Bench · Backward (EPM)", | |
| 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)", | |
| 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)", | |
| 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.”", | |
| ), | |
| dict( | |
| tag="EgoServe / EgoLife · Proactive Service (safety)", | |
| 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)", | |
| ), | |
| ] | |
| # ---- 版面度量 (figure 坐标, 0-1) ---- | |
| FIG_W, FIG_H = 13.6, 19.6 | |
| fig = plt.figure(figsize=(FIG_W, FIG_H)) | |
| fig.patch.set_facecolor("white") | |
| L, R = 0.035, 0.965 | |
| W = R - L | |
| 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) | |
| # 每个 case 块的高度分配(英寸) | |
| 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") | |
| return h | |
| total = sum(case_height(c) for c in CASES) + H_GAP*(len(CASES)-1) | |
| TOP_PAD, BOT_PAD = 0.55, 0.30 | |
| scale = 1.0 | |
| y_cur = 1.0 - fh(TOP_PAD) | |
| # 标题 | |
| fig.text(0.5, 1 - fh(0.28), "Qualitative results of GROVE on long-horizon egocentric benchmarks", | |
| ha="center", va="center", fontsize=15.5, fontweight="bold", color="#12253d") | |
| for ci, c in enumerate(CASES): | |
| # ---------- tag ---------- | |
| y_cur -= fh(H_TAG) | |
| txt(L, y_cur + fh(0.185), c["tag"], size=10.5, weight="bold", color="#12253d") | |
| # 右上角 CORRECT 徽章 | |
| 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 | |
| # 帧图高度 (16:9 或 1:1) | |
| 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") | |
| # 分段着色: pre(黑) + hl(蓝粗) + post(黑) | |
| 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 ---------- | |
| y_cur -= fh(H_GT) | |
| rbox(L, y_cur+fh(0.04), W, fh(H_GT)-fh(0.06), C_GT, C_GT_EDGE, lw=1.0, r=0.011) | |
| gy = y_cur + fh(0.04) + (fh(H_GT)-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") | |
| # ---------- 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(OUTDIR+"/qualitative_cases.pdf", format="pdf", bbox_inches="tight", facecolor="white") | |
| fig.savefig(OUTDIR+"/qualitative_cases.png", dpi=180, bbox_inches="tight", facecolor="white") | |
| print("saved ->", OUTDIR) | |