Jules Musquin commited on
Commit ·
09216c3
1
Parent(s): ef8cc33
[update] adding log capacity on IoU_yolo.py
Browse files- IoU_yolo.py +27 -9
IoU_yolo.py
CHANGED
|
@@ -1,8 +1,13 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def yolo_to_corners(box):
|
| 8 |
"""Convertit (x_center, y_center, w, h) en (x1, y1, x2, y2)."""
|
|
@@ -89,7 +94,7 @@ def match_boxes(gt_boxes, pred_boxes):
|
|
| 89 |
gt_files = sorted(f for f in os.listdir(GT_DIR) if f.endswith(".txt"))
|
| 90 |
|
| 91 |
all_ious = []
|
| 92 |
-
|
| 93 |
for filename in gt_files:
|
| 94 |
gt_path = os.path.join(GT_DIR, filename)
|
| 95 |
pred_path = os.path.join(PRED_DIR, filename)
|
|
@@ -102,9 +107,22 @@ for filename in gt_files:
|
|
| 102 |
all_ious.extend(ious)
|
| 103 |
|
| 104 |
mean_iou = np.mean(ious) if ious else 0.0
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
+
|
| 6 |
+
# GT_DIR = "test_images/wit396_pdf545/labels"
|
| 7 |
+
GT_DIR = sys.argv[1]
|
| 8 |
+
|
| 9 |
+
# PRED_DIR = "test/yolo8Lg-17-07-2026/labels"
|
| 10 |
+
PRED_DIR = sys.argv[2]
|
| 11 |
|
| 12 |
def yolo_to_corners(box):
|
| 13 |
"""Convertit (x_center, y_center, w, h) en (x1, y1, x2, y2)."""
|
|
|
|
| 94 |
gt_files = sorted(f for f in os.listdir(GT_DIR) if f.endswith(".txt"))
|
| 95 |
|
| 96 |
all_ious = []
|
| 97 |
+
|
| 98 |
for filename in gt_files:
|
| 99 |
gt_path = os.path.join(GT_DIR, filename)
|
| 100 |
pred_path = os.path.join(PRED_DIR, filename)
|
|
|
|
| 107 |
all_ious.extend(ious)
|
| 108 |
|
| 109 |
mean_iou = np.mean(ious) if ious else 0.0
|
| 110 |
+
message_paires = f"{filename}: {len(matches)} paires, IoU moyen = {mean_iou:.4f}, "
|
| 111 |
+
message_erreurs = f"GT manqués = {len(unmatched_gt)}, faux positifs = {len(unmatched_pred)}"
|
| 112 |
+
print(f"{message_paires}\n{message_erreurs}\n")
|
| 113 |
+
|
| 114 |
+
base_dir = PRED_DIR.split('/')
|
| 115 |
+
base_dir = f"{base_dir[0]}/{base_dir[1]}"
|
| 116 |
+
with open(f"{base_dir}/log.txt","w") as f:
|
| 117 |
+
f.write(f"{message_paires}\n{message_erreurs}")
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
fichiers_traités = f"Fichiers traités : {len(gt_files)}"
|
| 121 |
+
print(fichiers_traités)
|
| 122 |
+
paires_appariées = f"Paires appariées : {len(all_ious)}"
|
| 123 |
+
print(paires_appariées)
|
| 124 |
+
IoUmoyenglobal = f"IoU moyen global : {np.mean(all_ious) if all_ious else 0.0:.4f}"
|
| 125 |
+
print(IoUmoyenglobal)
|
| 126 |
+
|
| 127 |
+
with open(f"{base_dir}/log.txt","a") as f:
|
| 128 |
+
f.write(f"\n{fichiers_traités}\n{paires_appariées}\n{IoUmoyenglobal}")
|