Mise à jour de l'affichage du résultat (% de précision)
This commit is contained in:
parent
0d15b16e9f
commit
04f563ee8e
3 changed files with 42 additions and 3 deletions
41
main.py
41
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}")
|
||||
|
|
|
@ -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
|
||||
|
|
2
train.py
2
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}")
|
||||
|
|
Loading…
Add table
Reference in a new issue