File size: 2,618 Bytes
1ea7ba6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
"""Teaser (Figure 1): the asymmetric cross-source shortcut in one glance. Same class
(coriander) in the studio and in the wild, with the two directional transfer numbers.
Saves outputs/teaser_asymmetry.{png,pdf}.
"""
from pathlib import Path
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.patches import FancyArrowPatch, Rectangle
import matplotlib.image as mpimg

matplotlib.rcParams.update({"font.family": "DejaVu Sans", "font.size": 9})
ROOT = Path("/mnt/d/SpiceNet") if Path("/mnt/d/SpiceNet").exists() else Path("D:/SpiceNet")
STUDIO = ROOT / "Indian_Spices/Coriander Seeds/Coriander Seeds/CorianderSeeds1.jpg"
WILD = ROOT / "Spice_Spectrum/coriander/coriander_1.jpg"
RED, GREEN, EDGE = "#c0504d", "#4a7a3f", "#333"

fig, ax = plt.subplots(figsize=(7.2, 3.5))
ax.set_xlim(0, 10); ax.set_ylim(0, 5); ax.axis("off")


def thumb(path, x, y, s=2.2, label="", acc=""):
    try:
        ax.imshow(mpimg.imread(str(path)), extent=[x, x + s, y, y + s], aspect="auto", zorder=3)
    except Exception:
        ax.add_patch(Rectangle((x, y), s, s, fc="#eee", ec=EDGE))
    ax.add_patch(Rectangle((x, y), s, s, fill=False, ec=EDGE, lw=1.3, zorder=4))
    ax.text(x + s / 2, y - 0.22, label, ha="center", va="top", fontsize=9)
    if acc:
        ax.text(x + s / 2, y + s + 0.18, acc, ha="center", va="bottom", fontsize=10, weight="bold")


thumb(STUDIO, 0.6, 1.5, label="studio acquisition\n(plain background)", acc="coriander: 100%")
thumb(WILD, 7.2, 1.5, label="in the wild\n(cluttered scenes)", acc="coriander: 8.2%")

# studio -> wild : catastrophic collapse (red, thick)
ax.add_patch(FancyArrowPatch((3.0, 3.2), (7.0, 3.2), arrowstyle="-|>", mutation_scale=22,
                             lw=3.2, color=RED, connectionstyle="arc3,rad=-0.28", zorder=2))
ax.text(5.0, 4.35, "train studio $\\rightarrow$ test wild", ha="center", fontsize=9.5)
ax.text(5.0, 3.95, "$-37.8$ pp collapse", ha="center", fontsize=11, color=RED, weight="bold")

# wild -> studio : nearly free (green, thin)
ax.add_patch(FancyArrowPatch((7.0, 2.0), (3.0, 2.0), arrowstyle="-|>", mutation_scale=16,
                             lw=1.6, color=GREEN, connectionstyle="arc3,rad=-0.28", zorder=2))
ax.text(5.0, 0.95, "train wild $\\rightarrow$ test studio", ha="center", fontsize=9.5)
ax.text(5.0, 0.55, "$-0.5$ pp (nearly free)", ha="center", fontsize=10, color=GREEN, weight="bold")

fig.tight_layout(pad=0.3)
out = ROOT / "outputs" / "teaser_asymmetry"
fig.savefig(str(out) + ".png", dpi=300, bbox_inches="tight")
fig.savefig(str(out) + ".pdf", bbox_inches="tight")
print("saved", out)