"""Results figure: avg relative accuracy vs budget (SPLIT/attn/random + paper), and TextVQA absolute accuracy vs budget (shows random collapse vs SPLIT robustness).""" import json import numpy as np import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt agg = json.load(open("outputs/aggregate.json")) rel = agg["relative_accuracy_avg"] paper = agg["paper_reference"]["SPLIT"] budgets = [192, 128, 64] x = budgets[::-1] tv = json.load(open("outputs/textvqa_results.json"))["results"] van_tv = tv["vanilla@576"]["accuracy"] fig, ax = plt.subplots(1, 2, figsize=(13, 4.6)) # panel 1: avg relative accuracy def series(m): return [rel[m][str(b)] for b in x] ax[0].plot(x, [paper[str(b)] for b in x], "s--", color="#888", label="SPLIT (paper, 10 bench)") ax[0].plot(x, series("split"), "o-", color="#2D5F8B", lw=2.5, label="SPLIT (ours, 3 bench)") ax[0].plot(x, series("attn"), "^-", color="#C1666B", label="attn-topk (ours)") ax[0].plot(x, series("random"), "v-", color="#9AA0A6", label="random (ours)") ax[0].set_xticks(x); ax[0].invert_xaxis() ax[0].set_xlabel("retained vision tokens"); ax[0].set_ylabel("avg relative accuracy (%)") ax[0].set_title("Avg relative accuracy vs token budget\n(LLaVA-1.5-7B, POPE+TextVQA+ScienceQA)") ax[0].axhline(100, color="k", lw=0.5, ls=":"); ax[0].legend(fontsize=9); ax[0].grid(alpha=0.3) # panel 2: TextVQA absolute def tvs(m): return [tv[f"{m}@{b}"]["accuracy"] for b in x] ax[1].axhline(van_tv, color="k", ls=":", lw=1, label=f"vanilla 576 = {van_tv:.1f}") ax[1].plot(x, tvs("split"), "o-", color="#2D5F8B", lw=2.5, label="SPLIT") ax[1].plot(x, tvs("attn"), "^-", color="#C1666B", label="attn-topk") ax[1].plot(x, tvs("random"), "v-", color="#9AA0A6", label="random") ax[1].set_xticks(x); ax[1].invert_xaxis() ax[1].set_xlabel("retained vision tokens"); ax[1].set_ylabel("TextVQA accuracy (%)") ax[1].set_title("TextVQA (OCR, token-sensitive)\nSPLIT robust; random collapses at 64") ax[1].legend(fontsize=9); ax[1].grid(alpha=0.3) plt.tight_layout() plt.savefig("outputs/fig_relative_accuracy.png", dpi=130, bbox_inches="tight") print("wrote outputs/fig_relative_accuracy.png")