From 04f563ee8e860ad429ef594b57b0eac39b547dc9 Mon Sep 17 00:00:00 2001 From: "yanis.bouarfa" Date: Tue, 7 Jan 2025 17:39:42 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20l'affichage=20du=20?= =?UTF-8?q?r=C3=A9sultat=20(%=20de=20pr=C3=A9cision)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 41 ++++++++++++++++++++++++++++++++++++++++- src/pipeline.py | 2 +- train.py | 2 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 66953cd..b6c09cd 100644 --- a/main.py +++ b/main.py @@ -2,10 +2,11 @@ import os import cv2 from src.pipeline import ObjectDetectionPipeline from src.classifiers.bayesian import BayesianClassifier +from collections import defaultdict if __name__ == "__main__": # Chemin vers le modèle entraîné - model_path = "models/bayesian_model.pth" + model_path = "models/bayesian_modelPAGE.pth" # Chargement du modèle bayésien print(f"Chargement du modèle bayésien depuis {model_path}") @@ -52,4 +53,42 @@ if __name__ == "__main__": print("Sauvegarde et affichage des résultats...") pipeline.display_results(class_counts, detected_objects) + # Chargement des comptes réels manuels avec distinction entre minuscule et majuscule + true_counts_manual = { + 'A_': 30, 'A': 30, 'B_': 4, 'B': 0, 'C_': 14, 'C': 14, 'D_': 17, 'D': 17, + 'E_': 68, 'E': 69, 'F_': 2, 'F': 2, 'G_': 8, 'G': 8, 'H_': 9, 'H': 9, + 'I_': 26, 'I': 25, 'J_': 1, 'J': 0, 'K_': 0, 'K': 0, 'L_': 20, 'L': 19, + 'M_': 15, 'M': 15, 'N_': 30, 'N': 29, 'O_': 37, 'O': 37, 'P_': 23, 'P': 22, + 'Q_': 5, 'Q': 4, 'R_': 28, 'R': 27, 'S_': 26, 'S': 25, 'T_': 38, 'T': 38, + 'U_': 25, 'U': 25, 'V_': 7, 'V': 6, 'W_': 1, 'W': 0, 'X_': 2, 'X': 2, + 'Y_': 6, 'Y': 5, 'Z_': 3, 'Z': 2, + '1': 8, '2': 11, '3': 2, '4': 1, '5': 2, '6': 1, '7': 1, '8': 3, '9': 3 + } + + # Chargement des résultats détectés depuis results.txt + results_path = "output/results.txt" + detected_counts = defaultdict(int) + if os.path.exists(results_path): + with open(results_path, "r") as f: + for line in f: + char, count = line.strip().split(":") + detected_counts[char.strip()] = int(count.strip()) + else: + print(f"Le fichier {results_path} n'existe pas.") + exit(1) + + # Calcul du pourcentage de précision + print("Calcul du pourcentage de précision...") + total_true = sum(true_counts_manual.values()) + common_keys = set(true_counts_manual.keys()) & set(detected_counts.keys()) + + correctly_detected = sum(min(detected_counts[char], true_counts_manual[char]) for char in common_keys) + precision = (correctly_detected / total_true) * 100 if total_true > 0 else 0 + + # Afficher les résultats + print("\nRésultats de comparaison :") + for char in sorted(common_keys): + print(f"{char}: True={true_counts_manual[char]}, Detected={detected_counts[char]}") + + print(f"\nPrécision globale : {precision:.2f}%") print(f"Les résultats ont été sauvegardés dans le dossier : {output_dir}") diff --git a/src/pipeline.py b/src/pipeline.py index 31f9d4e..cb2110b 100644 --- a/src/pipeline.py +++ b/src/pipeline.py @@ -87,7 +87,7 @@ class ObjectDetectionPipeline: cv2.rectangle(annotated_image, (x, y), (x + w, y + h), (0, 255, 0), 2) cv2.putText(annotated_image, str(predicted_class), (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 255, 0), 2) - annotated_output_path = os.path.join(self.output_dir, "annotated_image.jpg") + annotated_output_path = os.path.join(self.output_dir, "annotated_page.jpg") cv2.imwrite(annotated_output_path, annotated_image) # Sauvegarder les classes et leurs occurrences diff --git a/train.py b/train.py index 7badc14..588c3f9 100644 --- a/train.py +++ b/train.py @@ -51,6 +51,6 @@ if __name__ == "__main__": print("Entraînement terminé.") # Sauvegarde du modèle entraîné - model_path = "models/bayesian_model.pth" + model_path = "models/bayesian_modelPAGE.pth" bayesian_model.save_model(model_path) print(f"Modèle sauvegardé dans : {model_path}")