File size: 7,633 Bytes
efeac49 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | from __future__ import annotations
import csv
import math
from pathlib import Path
import matplotlib
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
import paper_colors
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
plt.rcParams.update(paper_colors.RC_COLORS)
HERE = Path(__file__).resolve().parent
DATA_CSV = HERE / "data.csv"
MODEL_LABELS = {
"OpenVLA": "OpenVLA*",
"pi_0.5": r"$\pi_{0.5}$*",
"GR00T": "GR00T*",
}
MODELS = ["OpenVLA", "pi_0.5", "GR00T"]
MARKERS = {
"OpenVLA": "o",
"pi_0.5": "s",
"GR00T": "^",
}
MIKASA_MODELS = ["qwenoft", "qwenpi_v3", "qwengr00t"]
MIKASA_COLORS = {
"qwenoft": paper_colors.MODEL_COLORS["Qwen OFT"],
"qwenpi_v3": paper_colors.MODEL_COLORS["QwenPI"],
"qwengr00t": paper_colors.MODEL_COLORS["QwenGR00T"],
}
MIKASA_MARKERS = {"qwenoft": "o", "qwenpi_v3": "s", "qwengr00t": "^"}
PANEL_CONFIGS = [
{
"env": "Flappy Bird",
"latencies": [0, 1, 2, 3, 4],
"ylim": (0, 500),
"inset_latencies": [1, 2, 3, 4],
"inset_ylim": (0, 22),
"inset_xticks": [1, 2, 3, 4],
"inset_yticks": [0, 10, 20],
},
{
"env": "Demon Attack",
"latencies": [0, 2, 4],
"ylim": (0, 7000),
"inset_latencies": [2, 4],
"inset_ylim": (50, 320),
"inset_xticks": [2, 4],
"inset_yticks": [100, 200, 300],
},
{
"env": "Deadly Corridor",
"latencies": [0, 1, 2, 3, 4, 5],
"ylim": (0, 700),
"inset_latencies": [1, 2, 3, 4, 5],
"inset_ylim": (50, 280),
"inset_xticks": [1, 3, 5],
"inset_yticks": [80, 160, 240],
},
]
def load_data() -> dict[str, dict[str, dict[int, float]]]:
data: dict[str, dict[str, dict[int, float]]] = {}
with DATA_CSV.open("r", newline="", encoding="utf-8") as handle:
for row in csv.DictReader(handle):
env = row["env"]
model = row["model"]
horizon = row["horizon"]
latency = int(row["latency"])
mean_score = float(row["mean_score"])
series = model if not horizon else f"{model}_{horizon.lower()}"
data.setdefault(env, {}).setdefault(series, {})[latency] = mean_score
return data
def plot_lines(ax, curves: dict[str, dict[int, float]], latencies: list[int], *, small: bool) -> None:
for model in MODELS:
values = curves[model]
ys = [values[latency] for latency in latencies]
ax.plot(
latencies,
ys,
marker=MARKERS[model],
color=paper_colors.MODEL_COLORS[model],
ls="-",
lw=0.8 if small else 1.2,
ms=2.2 if small else 3.2,
alpha=0.98,
zorder=4 if model == "OpenVLA" else 3,
)
def plot_env(ax, config: dict[str, object], data: dict[str, dict[str, dict[int, float]]]) -> None:
env = config["env"]
curves = data[env]
latencies = config["latencies"]
inset_latencies = config["inset_latencies"]
plot_lines(ax, curves, latencies, small=False)
ax.set_title(env, pad=7)
ax.set_xlabel("Eval latency (frames)")
ax.set_xticks(latencies)
ax.set_xlim(min(latencies) - 0.25, max(latencies) + 0.25)
ax.set_ylim(*config["ylim"])
if env == "Flappy Bird":
ax.set_yticks([0, 100, 200, 300, 400, 500])
axins = ax.inset_axes([0.52, 0.53, 0.44, 0.35])
axins.set_facecolor(paper_colors.WHITE)
axins.patch.set_alpha(0.94)
plot_lines(axins, curves, inset_latencies, small=True)
axins.set_xlim(min(inset_latencies) - 0.2, max(inset_latencies) + 0.2)
axins.set_ylim(*config["inset_ylim"])
axins.set_xticks(config["inset_xticks"])
axins.set_yticks(config["inset_yticks"])
axins.tick_params(labelsize=5.5, length=2)
axins.grid(alpha=0.25)
axins.set_title("Zoom: latency > 0", fontsize=5.5, pad=2)
for spine in axins.spines.values():
spine.set_color(paper_colors.GRAY)
spine.set_linewidth(0.5)
# Derive the source box from the inset limits so both views stay aligned.
zoom = ax.indicate_inset_zoom(
axins,
edgecolor=paper_colors.EDGE,
linewidth=0.65,
linestyle="--",
alpha=0.8,
zorder=2,
)
for connector in zoom.connectors:
connector.set_visible(False)
# A single arrow avoids the inset's y ticks and enters between x ticks.
inset_left, inset_right = axins.get_xlim()
ax.annotate(
"",
xy=(0.25, 0),
xycoords=axins.transAxes,
xytext=((inset_left + inset_right) / 2, axins.get_ylim()[1]),
textcoords=ax.transData,
arrowprops={
"arrowstyle": "->",
"color": paper_colors.EDGE,
"linewidth": 0.65,
"linestyle": "--",
"alpha": 0.8,
"mutation_scale": 7,
"shrinkA": 1.5,
"shrinkB": 1.5,
},
zorder=2,
)
def plot_mikasa(ax, data: dict[str, dict[str, dict[int, float]]]) -> None:
curves = data["MIKASA InterceptGrabFast"]
latencies = [0, 1, 2, 3, 4]
max_success = max(
value
for values in curves.values()
for value in values.values()
)
y_max = math.ceil(max_success / 10) * 10
for model in MIKASA_MODELS:
for horizon in (1, 8):
values = curves[f"{model}_h{horizon}"]
ax.plot(
latencies,
[values[latency] for latency in latencies],
marker=MIKASA_MARKERS[model],
color=MIKASA_COLORS[model],
ls="-" if horizon == 1 else "--",
lw=1.15,
ms=3.0,
markerfacecolor=MIKASA_COLORS[model] if horizon == 1 else paper_colors.WHITE,
markeredgewidth=0.8,
)
ax.set_title("Intercept Grab (Fast)", pad=7)
ax.set_xlabel("Eval latency (frames)")
ax.set_ylabel("Success rate (%)", labelpad=1)
ax.set_xticks(latencies)
ax.set_xlim(-0.25, 4.25)
ax.set_ylim(0, y_max)
ax.set_yticks(range(0, y_max + 1, 10))
def main() -> None:
plt.style.use(HERE.parents[1] / "plot_style.mplstyle")
data = load_data()
fig, axes = plt.subplots(1, 4, figsize=(7.2, 2.45), constrained_layout=False)
for ax, config in zip(axes[:3], PANEL_CONFIGS):
plot_env(ax, config, data)
plot_mikasa(axes[3], data)
for ax in axes:
ax.set_box_aspect(1)
handles = [
Line2D([], [], color=paper_colors.MODEL_COLORS[model],
marker=MARKERS[model], linestyle="None", markersize=5,
label=MODEL_LABELS[model])
for model in MODELS
]
handles.extend((
Line2D([], [], color=paper_colors.INK, marker="o", markersize=4,
label="Single action"),
Line2D([], [], color=paper_colors.INK, linestyle="--", marker="o",
markerfacecolor=paper_colors.WHITE, markersize=4,
label="Action chunk (horizon 8)"),
))
fig.legend(handles=handles, loc="upper center", ncol=5,
bbox_to_anchor=(0.5, 0.95), fontsize=7, frameon=False,
handlelength=1.4, handletextpad=0.35, columnspacing=0.8)
axes[0].set_ylabel("Mean return")
fig.subplots_adjust(left=0.055, right=0.995, bottom=0.22, top=0.76, wspace=0.38)
fig.savefig(HERE / "fig.pdf", bbox_inches="tight")
fig.savefig(HERE / "fig.png", dpi=300, bbox_inches="tight")
plt.close(fig)
print(f"wrote {HERE / 'fig.pdf'}")
print(f"wrote {HERE / 'fig.png'}")
if __name__ == "__main__":
main()
|