Update app.py
Browse files
app.py
CHANGED
|
@@ -49,17 +49,30 @@ def metrics_markdown():
|
|
| 49 |
if not p.exists():
|
| 50 |
return "_metrics.json not found._"
|
| 51 |
m = json.loads(p.read_text())
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
return "\n".join(out)
|
| 64 |
|
| 65 |
PLOTS = [
|
|
|
|
| 49 |
if not p.exists():
|
| 50 |
return "_metrics.json not found._"
|
| 51 |
m = json.loads(p.read_text())
|
| 52 |
+
cm = np.array(m["confusion_matrix"])
|
| 53 |
+
tp = cm.diagonal()
|
| 54 |
+
precision = tp / cm.sum(axis=0).clip(min=1)
|
| 55 |
+
recall = tp / cm.sum(axis=1).clip(min=1)
|
| 56 |
+
f1 = 2 * precision * recall / (precision + recall + 1e-12)
|
| 57 |
+
|
| 58 |
+
head = [f"**Test accuracy:** {m['test_accuracy']:.2%}",
|
| 59 |
+
f"**Macro F1:** {m['macro_f1']:.3f}"]
|
| 60 |
+
if m.get("best_val_accuracy"):
|
| 61 |
+
head.append(f"**Best val accuracy:** {m['best_val_accuracy']:.2%}")
|
| 62 |
+
if m.get("params"):
|
| 63 |
+
head.append(f"**Parameters:** {m['params']:,}")
|
| 64 |
+
|
| 65 |
+
out = [" · ".join(head), "",
|
| 66 |
+
"| Class | Precision | Recall | F1 | Test images |",
|
| 67 |
+
"|---|---|---|---|---|"]
|
| 68 |
+
for i, c in enumerate(CLASSES):
|
| 69 |
+
out.append(f"| {c} | {precision[i]:.3f} | {recall[i]:.3f} | {f1[i]:.3f} | {cm[i].sum()} |")
|
| 70 |
+
|
| 71 |
+
# top confusions
|
| 72 |
+
off = [(cm[i, j], CLASSES[i], CLASSES[j]) for i in range(len(CLASSES))
|
| 73 |
+
for j in range(len(CLASSES)) if i != j]
|
| 74 |
+
out += ["", "**Most confused (actual → predicted):** " +
|
| 75 |
+
", ".join(f"{a} → {b} ({n})" for n, a, b in sorted(off, reverse=True)[:4])]
|
| 76 |
return "\n".join(out)
|
| 77 |
|
| 78 |
PLOTS = [
|