Repository navigation
Expand file tree
/
Copy pathplot_dataset_scale.py
More file actions
118 lines (102 loc) · 3.69 KB
/
Copy pathplot_dataset_scale.py
File metadata and controls
118 lines (102 loc) · 3.69 KB
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
"""
Dataset scale ablation figure — CVPR style.
Usage:
python plot_dataset_scale.py
python plot_dataset_scale.py --out dataset_scale.pdf
"""
import argparse
import os
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import numpy as np
# ── Publication RC params (mirrors plot_conflict_comparison.py) ────────────────
plt.rcParams.update({
"font.family": "sans-serif",
"font.sans-serif": ["Helvetica", "Arial", "DejaVu Sans"],
"font.size": 8,
"axes.titlesize": 8,
"axes.labelsize": 8,
"xtick.labelsize": 7,
"ytick.labelsize": 7,
"legend.fontsize": 7,
"legend.title_fontsize":7,
"lines.linewidth": 1.4,
"axes.linewidth": 0.6,
"xtick.major.width": 0.6,
"ytick.major.width": 0.6,
"xtick.major.size": 3,
"ytick.major.size": 3,
"xtick.direction": "in",
"ytick.direction": "in",
"axes.spines.top": False,
"axes.spines.right": False,
"axes.grid": True,
"grid.color": "#E0E0E0",
"grid.linewidth": 0.4,
"grid.linestyle": "-",
"axes.axisbelow": True,
"figure.dpi": 300,
"savefig.dpi": 300,
"savefig.bbox": "tight",
"savefig.pad_inches": 0,
})
# ── Data ───────────────────────────────────────────────────────────────────────
RATIOS = [1, 20, 50, 100]
DATASETS = {
"Caltech101": {
"acc": [63.1, 85.8, 88.0, 94.4],
"color": "#2980B9",
"marker": "o",
"ls": "-",
},
"CUB": {
"acc": [49.4, 80.1, 83.3, 90.8],
"color": "#C0392B",
"marker": "s",
"ls": "--",
},
"Aircraft": {
"acc": [46.1, 76.6, 81.3, 91.1],
"color": "#27AE60",
"marker": "^",
"ls": ":",
},
}
# ── Plot ───────────────────────────────────────────────────────────────────────
def plot(out: str):
fig, ax = plt.subplots(figsize=(2.8, 1.8))
for name, cfg in DATASETS.items():
ax.plot(RATIOS, cfg["acc"],
color=cfg["color"],
linestyle=cfg["ls"],
linewidth=1.4,
marker=cfg["marker"],
markersize=4,
markeredgewidth=0.6,
markeredgecolor="white",
label=name,
zorder=3)
ax.set_xscale("log")
ax.set_xticks(RATIOS)
ax.xaxis.set_major_formatter(mticker.FuncFormatter(lambda x, _: f"{int(x)}%"))
ax.set_xlabel("Training Data Ratio")
ax.set_ylabel("Accuracy (%)")
# y-axis: start just below min value, end just above max
ax.set_ylim(40, 98)
ax.yaxis.set_major_locator(mticker.MultipleLocator(10))
ax.yaxis.set_minor_locator(mticker.MultipleLocator(5))
ax.tick_params(which="minor", length=1.5, width=0.4)
ax.legend(loc="upper left", frameon=False,
handlelength=1.8, handletextpad=0.4, borderpad=0)
plt.savefig(out, pad_inches=0)
plt.close()
print(f"Saved → {out}")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--out", default="dataset_scale.pdf")
args = parser.parse_args()
base = os.path.dirname(os.path.abspath(__file__))
out_path = args.out if os.path.isabs(args.out) else os.path.join(base, args.out)
plot(out_path)