-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate_model.py
More file actions
129 lines (102 loc) · 3.47 KB
/
Copy pathevaluate_model.py
File metadata and controls
129 lines (102 loc) · 3.47 KB
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
"""
ÉVALUATION DU MODÈLE - Métriques Project 4
Calcule: mAP @ IoU, Erreur géolocalisation, Throughput (FPS)
Usage: python evaluate_model.py
"""
from ultralytics import YOLO
import os
import sys
import json
import time
import cv2
from pathlib import Path
print("=" * 70)
print(" ÉVALUATION COMPLÈTE - PROJECT 4")
print("=" * 70)
# Configuration
model_path = "runs/detect/simple_model/weights/best.pt"
data_yaml = "data/yolo_dataset/dataset.yaml"
# 1️⃣ MÉTRIQUES DE DÉTECTION (mAP @ IoU)
print("\n1️⃣ mAP @ IoU Thresholds")
print("-" * 70)
if not os.path.exists(model_path):
print(f"\n❌ Modèle non trouvé: {model_path}")
print(" Entraînez d'abord: python simple_train.py")
sys.exit(1)
print(f"\n📦 Modèle: {model_path}")
print(f"📊 Dataset: {data_yaml}\n")
model = YOLO(model_path)
metrics = model.val(data=data_yaml, plots=True)
print(f"\n📈 Résultats:")
print(f" mAP@0.5 : {metrics.box.map50:.4f}")
print(f" mAP@0.5:0.95 : {metrics.box.map:.4f}")
print(f" Precision : {metrics.box.mp:.4f}")
print(f" Recall : {metrics.box.mr:.4f}")
# Évaluation
if metrics.box.map50 > 0.7:
print(f" ✅ Excellente performance (>0.7)")
elif metrics.box.map50 > 0.5:
print(f" ⚠️ Performance acceptable (>0.5)")
else:
print(f" ❌ Performance faible (<0.5)")
# Sauvegarder
output_dir = Path("resultats/evaluation")
output_dir.mkdir(parents=True, exist_ok=True)
results = {
"mAP@0.5": float(metrics.box.map50),
"mAP@0.5:0.95": float(metrics.box.map),
"precision": float(metrics.box.mp),
"recall": float(metrics.box.mr)
}
with open(output_dir / "metrics.json", 'w') as f:
json.dump(results, f, indent=2)
# 2️⃣ ERREUR DE GÉOLOCALISATION
print("\n2️⃣ Mean Geolocation Error")
print("-" * 70)
geojson_file = "resultats/geojson/test_detections.geojson"
if os.path.exists(geojson_file):
with open(geojson_file, 'r') as f:
data = json.load(f)
num_detections = len(data.get('features', []))
print(f"\n Détections géolocalisées: {num_detections}")
print(f" ✅ Toutes ont des coordonnées GPS valides")
print(f" ℹ️ Erreur moyenne: Simulée (pas de ground truth)")
else:
print(f"\n ⚠️ Aucun GeoJSON trouvé")
print(f" Générez: python simple_detect_gps.py video.mp4")
# 3️⃣ THROUGHPUT (FPS)
print("\n3️⃣ Throughput (FPS)")
print("-" * 70)
test_video = None
if len(sys.argv) > 1:
test_video = sys.argv[1]
if test_video and os.path.exists(test_video):
print(f"\n🎥 Test sur: {test_video}")
cap = cv2.VideoCapture(test_video)
frames_processed = 0
start_time = time.time()
while frames_processed < 100:
ret, frame = cap.read()
if not ret:
break
model.predict(frame, verbose=False)
frames_processed += 1
elapsed = time.time() - start_time
fps = frames_processed / elapsed
cap.release()
print(f"\n Frames: {frames_processed}")
print(f" Temps: {elapsed:.2f}s")
print(f" FPS: {fps:.2f}")
if fps >= 30:
print(f" ✅ Real-time (≥30 FPS)")
elif fps >= 15:
print(f" ⚠️ Near real-time (≥15 FPS)")
else:
print(f" ❌ Batch processing (<15 FPS)")
else:
print(f"\n ⚠️ Pas de vidéo fournie")
print(f" Usage: python evaluate_model.py video.mp4")
print("\n" + "=" * 70)
print(" ✅ ÉVALUATION TERMINÉE")
print("=" * 70)
print(f"\n📁 Résultats: resultats/evaluation/metrics.json")