File size: 4,418 Bytes
16231ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Draw the final-model architecture figure (reports/figures/fig2_best_model_architecture.png / .pdf)."""
import sys as _sys
from pathlib import Path as _Path
_SCRIPTS = next(_p for _p in _Path(__file__).resolve().parents if _p.name == "scripts")
_sys.path[:0] = [str(_SCRIPTS.parent), str(_SCRIPTS.parent / "models")] + [str(_d) for _d in sorted(_SCRIPTS.rglob("*")) if _d.is_dir() and _d.name != "__pycache__"]
import argparse
from pathlib import Path

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.patches import FancyBboxPatch

INK, QUIET, GREY_E, GREY_F = "#1f1f1f", "#6b6b6b", "#6b6b66", "#f3f2ef"
BLUE_E, BLUE_F, ORANGE_E, ORANGE_F = "#2f7bd6", "#eef4fb", "#e8683a", "#fdf0ea"
FOOTER = ("Targets: SoundAQNet AQ of the photo's synchronized 10-s clip, one gain per dataset (median clip at −40 LUFS); "
          "only pairs with image–audio cosine ≥ 0.2 train.\n"
          "16,422 training pairs: original datasets (without TAU indoor scenes, YFCC sky-only / indoor or too-dark frames, indoor 360+x videos) "
          "+ open sound-image pairs, SonicUrban, ETH Zurich, Taiwan; panoramas as 4 views.\n"
          "10-fold CV, every training pair held out once: original datasets (8,655 pairs) Spearman 0.621; all 16,422 pairs 0.520; "
          "80% range coverage 0.81 (Winkler 1.620); 5 photos per place 0.67.\n"
          "Earlier DINOv3 / sound-localization / OpenCLIP / geometry blocks added nothing (−0.002) and were dropped.")


def box(ax, x, y, w, h, title, sub, edge, face):
    ax.add_patch(FancyBboxPatch((x, y), w, h, boxstyle="round,pad=0,rounding_size=0.12", lw=2.2, ec=edge, fc=face))
    ax.text(x + w / 2, y + h * 0.62, title, ha="center", va="center", fontsize=15, weight="bold", color=INK)
    ax.text(x + w / 2, y + h * 0.30, sub, ha="center", va="center", fontsize=12.5, color=QUIET, linespacing=1.4)


def arrow(ax, x0, y0, x1, y1, color=GREY_E):
    ax.annotate("", xy=(x1, y1), xytext=(x0, y0), arrowprops=dict(arrowstyle="-|>", lw=2, color=color, mutation_scale=16))


def main():
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument("--output", type=Path, default=Path("reports/figures/fig2_best_model_architecture"))
    a = p.parse_args()
    fig = plt.figure(figsize=(21.5, 11.07), dpi=100)
    ax = fig.add_axes([0, 0, 1, 1])
    ax.set_xlim(0, 21.5); ax.set_ylim(0, 11.07); ax.axis("off")
    ax.text(0.5, 10.45, "Final model: frozen image features + kernel ridge (photo → 8 perceived affective qualities with an 80% range)",
            fontsize=19, weight="bold", color=INK, va="center")
    box(ax, 0.25, 4.95, 2.75, 1.6, "Single photo", "no panorama, no audio", GREY_E, GREY_F)
    box(ax, 3.75, 6.75, 6.3, 1.45, "SigLIP 2 giant (frozen, 384 px)", "pooled 1,536 + mean token 1,536 → 3,072-d", BLUE_E, BLUE_F)
    box(ax, 3.75, 3.8, 6.3, 1.45, "PE-Core bigG/14 (frozen, 448 px)", "Perception Encoder image embedding → 1,280-d", BLUE_E, BLUE_F)
    box(ax, 11.0, 4.9, 2.4, 1.75, "Concatenate", "4,352-d", GREY_E, GREY_F)
    box(ax, 14.0, 4.9, 2.55, 1.75, "Standardize", "z-score, ÷ √D", GREY_E, GREY_F)
    box(ax, 17.25, 6.9, 4.0, 1.85, "Kernel ridge (RBF)", "8 AQ means", ORANGE_E, ORANGE_F)
    box(ax, 17.25, 4.1, 4.0, 1.85, "Spread kernel ridge (RBF)", "same kernel; predicts log |error|\nper AQ → photo-specific scale s(x)", ORANGE_E, ORANGE_F)
    box(ax, 17.25, 1.45, 4.0, 1.85, "80% AQ range", "mean + s(x) · q10 / q90 of\nscaled out-of-fold errors", ORANGE_E, ORANGE_F)
    ax.text(19.25, 9.15, "kernel width + λ by grouped\n5-fold CV on the training side", ha="center", va="center", fontsize=12.5, color=QUIET, linespacing=1.4)
    arrow(ax, 3.0, 5.75, 3.75, 7.45); arrow(ax, 3.0, 5.75, 3.75, 4.55)
    arrow(ax, 10.05, 7.45, 11.0, 5.95); arrow(ax, 10.05, 4.55, 11.0, 5.6)
    arrow(ax, 13.4, 5.77, 14.0, 5.77)
    arrow(ax, 16.55, 6.1, 17.25, 7.6); arrow(ax, 16.55, 5.5, 17.25, 5.0)
    arrow(ax, 19.25, 6.9, 19.25, 5.95, ORANGE_E); arrow(ax, 19.25, 4.1, 19.25, 3.3, ORANGE_E)
    ax.text(0.5, 0.65, FOOTER, fontsize=12.5, color=QUIET, va="center", linespacing=1.6)
    a.output.parent.mkdir(parents=True, exist_ok=True)
    fig.savefig(a.output.with_suffix(".png"), dpi=100, facecolor="white")
    fig.savefig(a.output.with_suffix(".pdf"), facecolor="white")
    print(f"Wrote {a.output.with_suffix('.png')} and .pdf")


if __name__ == "__main__":
    main()