File size: 5,891 Bytes
98aaa90 | 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 | """Gera graficos do benchmark 1K (811 testes)."""
import json
import os
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams.update({
"figure.facecolor": "#0d1117",
"axes.facecolor": "#161b22",
"axes.edgecolor": "#30363d",
"axes.labelcolor": "#c9d1d9",
"xtick.color": "#8b949e",
"ytick.color": "#8b949e",
"text.color": "#c9d1d9",
"grid.color": "#21262d",
"grid.linestyle": "--",
"grid.alpha": 0.6,
"font.family": "sans-serif",
"font.size": 11,
})
OUTPUT_DIR = "training_plots"
def load_results(path="benchmark_1k_results.json"):
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
def plot_accuracy_bars(data, save_dir):
fig, axes = plt.subplots(1, 3, figsize=(16, 6))
# 1. Por modalidade
ax = axes[0]
modalities = ["Texto\n(401)", "Imagem\n(250)", "Audio\n(160)", "COMPOSTO\n(811)"]
accs = [
data["text"]["_total"]["acc"],
data["image"]["both_acc"],
data["audio"]["acc"],
data["composite_score"],
]
colors = ["#58a6ff", "#7ee787", "#d2a8ff", "#ffa657"]
bars = ax.bar(modalities, accs, color=colors, width=0.6, edgecolor="#30363d", linewidth=1.2)
for bar, acc in zip(bars, accs):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 1,
f"{acc:.1f}%", ha="center", va="bottom", fontsize=12, fontweight="bold",
color="#c9d1d9")
ax.set_ylim(0, 110)
ax.set_ylabel("Acuracia (%)")
ax.set_title("Por Modalidade", fontsize=13, fontweight="bold", pad=10)
ax.grid(axis="y", alpha=0.3)
# 2. Texto por categoria
ax = axes[1]
cats = []
cat_accs = []
for cat, r in data["text"].items():
if cat != "_total":
label = cat.replace("(fora treino)", "\n(fora treino)")
cats.append(label)
cat_accs.append(r["acc"])
bar_colors = ["#58a6ff"] * len(cats)
bars2 = ax.barh(cats, cat_accs, color=bar_colors, height=0.5, edgecolor="#30363d", linewidth=1)
for bar, acc in zip(bars2, cat_accs):
ax.text(bar.get_width() + 1, bar.get_y() + bar.get_height()/2,
f"{acc:.0f}%", ha="left", va="center", fontsize=11, fontweight="bold",
color="#c9d1d9")
ax.set_xlim(0, 115)
ax.set_xlabel("Acuracia (%)")
ax.set_title("Texto por Categoria", fontsize=13, fontweight="bold", pad=10)
ax.grid(axis="x", alpha=0.3)
# 3. Imagem & Audio detalhe
ax = axes[2]
labels = ["Forma", "Cor", "Forma+Cor", "Audio"]
vals = [
data["image"]["shape_acc"],
data["image"]["color_acc"],
data["image"]["both_acc"],
data["audio"]["acc"],
]
cols = ["#7ee787", "#7ee787", "#7ee787", "#d2a8ff"]
bars3 = ax.bar(labels, vals, color=cols, width=0.5, edgecolor="#30363d", linewidth=1.2)
for bar, acc in zip(bars3, vals):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 1,
f"{acc:.1f}%", ha="center", va="bottom", fontsize=12, fontweight="bold",
color="#c9d1d9")
ax.set_ylim(0, 110)
ax.set_ylabel("Acuracia (%)")
ax.set_title("Imagem & Audio", fontsize=13, fontweight="bold", pad=10)
ax.grid(axis="y", alpha=0.3)
fig.suptitle(
f"Benchmark 1K | Score: {data['composite_score']:.1f}% | "
f"{data['total_tests']} testes (texto + img + audio)",
fontsize=14, fontweight="bold", y=0.98, color="#58a6ff"
)
plt.tight_layout(rect=[0, 0, 1, 0.94])
path = os.path.join(save_dir, "benchmark.png")
fig.savefig(path, dpi=150, bbox_inches="tight")
plt.close(fig)
print(f" Salvo: {path}")
def plot_radar(data, save_dir):
cats_text = {k: v for k, v in data["text"].items() if k != "_total"}
categories = list(cats_text.keys()) + ["Imagem", "Audio"]
values = [v["acc"] for v in cats_text.values()] + [data["image"]["both_acc"], data["audio"]["acc"]]
N = len(categories)
angles = np.linspace(0, 2 * np.pi, N, endpoint=False).tolist()
values_closed = values + [values[0]]
angles += [angles[0]]
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
ax.set_facecolor("#161b22")
fig.patch.set_facecolor("#0d1117")
ax.plot(angles, values_closed, "o-", linewidth=2, color="#58a6ff", alpha=0.9)
ax.fill(angles, values_closed, color="#58a6ff", alpha=0.15)
short_names = []
for c in categories:
c2 = c.replace("(fora treino)", "").strip()
if len(c2) > 14:
c2 = c2[:13] + "."
short_names.append(c2)
ax.set_xticks(angles[:-1])
ax.set_xticklabels(short_names, fontsize=9, color="#c9d1d9")
ax.set_ylim(0, 105)
ax.set_yticks([20, 40, 60, 80, 100])
ax.set_yticklabels(["20%", "40%", "60%", "80%", "100%"], fontsize=8, color="#8b949e")
ax.spines["polar"].set_color("#30363d")
ax.grid(color="#21262d", alpha=0.6)
for angle, val in zip(angles[:-1], values):
ax.text(angle, val + 5, f"{val:.0f}%", ha="center", va="bottom",
fontsize=10, fontweight="bold", color="#ffa657")
ax.set_title(f"Benchmark 1K - Score: {data['composite_score']:.1f}%",
fontsize=14, fontweight="bold", pad=20, color="#c9d1d9")
path = os.path.join(save_dir, "benchmark_radar.png")
fig.savefig(path, dpi=150, bbox_inches="tight")
plt.close(fig)
print(f" Salvo: {path}")
def main():
os.makedirs(OUTPUT_DIR, exist_ok=True)
data = load_results()
print(f" Score: {data['composite_score']}% | {data['total_tests']} testes")
plot_accuracy_bars(data, OUTPUT_DIR)
plot_radar(data, OUTPUT_DIR)
print(" Done!")
if __name__ == "__main__":
main()
|