-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_improved_system.py
More file actions
292 lines (230 loc) · 10.1 KB
/
Copy pathtest_improved_system.py
File metadata and controls
292 lines (230 loc) · 10.1 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/env python3
"""
Test script for the improved facial recognition system.
This script validates the new components and compares them with the original system.
"""
import os
import sys
import time
from pathlib import Path
from typing import List, Dict, Any
# Add the facesorter module to the path
sys.path.append(os.path.abspath('.'))
def test_improved_face_detector():
"""Test the improved face detector."""
print("Testing Improved Face Detector...")
try:
from facesorter.improved_face_detector import ImprovedFaceDetector, FaceQuality
# Initialize detector
detector = ImprovedFaceDetector(model="adaptive")
print("✓ Detector initialized successfully")
# Test quality levels
quality_levels = [FaceQuality.EXCELLENT, FaceQuality.GOOD, FaceQuality.FAIR, FaceQuality.POOR]
print(f"✓ Quality levels available: {[q.name for q in quality_levels]}")
print("✓ Improved Face Detector test passed\n")
return True
except Exception as e:
print(f"✗ Improved Face Detector test failed: {e}\n")
return False
def test_improved_clusterer():
"""Test the improved face clusterer."""
print("Testing Improved Face Clusterer...")
try:
from facesorter.improved_face_clusterer import ImprovedFaceClusterer, AdaptiveThreshold
from facesorter.improved_face_detector import FaceQuality
# Initialize clusterer
clusterer = ImprovedFaceClusterer(enable_hierarchical=True)
print("✓ Clusterer initialized successfully")
# Test adaptive threshold
threshold_manager = AdaptiveThreshold()
print("✓ Adaptive threshold manager created")
# Test quality-based thresholds
thresholds = threshold_manager.quality_thresholds
expected_qualities = [FaceQuality.EXCELLENT, FaceQuality.GOOD, FaceQuality.FAIR, FaceQuality.POOR]
for quality in expected_qualities:
if quality in thresholds:
print(f"✓ Threshold for {quality.name}: {thresholds[quality]}")
else:
print(f"✗ Missing threshold for {quality.name}")
return False
print("✓ Improved Face Clusterer test passed\n")
return True
except Exception as e:
print(f"✗ Improved Face Clusterer test failed: {e}\n")
return False
def test_improved_config():
"""Test the improved configuration system."""
print("Testing Improved Configuration...")
try:
from facesorter.improved_config import improved_config, ProcessingMode
# Test configuration loading
print(f"✓ Configuration loaded successfully")
print(f"✓ Face detection model: {improved_config.face_detection.model}")
print(f"✓ Clustering method: {improved_config.clustering.method}")
print(f"✓ Processing mode: {improved_config.processing.processing_mode.value}")
# Test adaptive configuration
adaptive_config = improved_config.get_adaptive_config(image_count=100)
print("✓ Adaptive configuration generated")
# Test processing recommendations
recommendations = improved_config.get_processing_recommendations()
print(f"✓ Processing recommendations: {recommendations['estimated_speed']}/{recommendations['estimated_accuracy']}")
# Test quality-based thresholds
thresholds = improved_config.get_quality_based_thresholds()
print(f"✓ Quality thresholds: {thresholds}")
print("✓ Improved Configuration test passed\n")
return True
except Exception as e:
print(f"✗ Improved Configuration test failed: {e}\n")
return False
def test_improved_worker():
"""Test the improved worker system."""
print("Testing Improved Worker...")
try:
from facesorter.improved_worker import init_improved_worker, get_worker_statistics
# Test worker initialization
init_improved_worker(model="hog", enable_gpu=False)
print("✓ Worker initialized successfully")
# Test worker statistics
stats = get_worker_statistics()
print(f"✓ Worker statistics: {stats}")
if stats['worker_initialized']:
print("✓ Worker is properly initialized")
else:
print("✗ Worker initialization failed")
return False
print("✓ Improved Worker test passed\n")
return True
except Exception as e:
print(f"✗ Improved Worker test failed: {e}\n")
return False
def test_integration():
"""Test the integration module."""
print("Testing Integration Module...")
try:
from facesorter.improved_app_integration import (
get_improved_diagnostic_info,
update_config_from_feedback,
get_processing_recommendations
)
# Test diagnostic info with empty data
diagnostic_info = get_improved_diagnostic_info([])
print("✓ Diagnostic info function works")
# Test feedback update
update_config_from_feedback(5, 3, 100)
print("✓ Feedback update function works")
# Test processing recommendations
recommendations = get_processing_recommendations(dataset_size=50)
print(f"✓ Processing recommendations: {recommendations}")
print("✓ Integration Module test passed\n")
return True
except Exception as e:
print(f"✗ Integration Module test failed: {e}\n")
return False
def test_dependencies():
"""Test that all required dependencies are available."""
print("Testing Dependencies...")
required_packages = [
'numpy',
'opencv-python',
'scikit-learn',
'face_recognition',
'PIL',
'yaml'
]
missing_packages = []
for package in required_packages:
try:
if package == 'opencv-python':
import cv2
print(f"✓ {package} (cv2) available")
elif package == 'PIL':
from PIL import Image
print(f"✓ {package} available")
elif package == 'yaml':
import yaml
print(f"✓ {package} available")
else:
__import__(package)
print(f"✓ {package} available")
except ImportError:
print(f"✗ {package} missing")
missing_packages.append(package)
if missing_packages:
print(f"\n✗ Missing packages: {missing_packages}")
print("Please install them with:")
for package in missing_packages:
print(f" pip install {package}")
return False
print("✓ All dependencies available\n")
return True
def run_performance_comparison():
"""Run a basic performance comparison if possible."""
print("Performance Comparison...")
try:
from facesorter.improved_config import improved_config
# Test different processing modes
modes = ["speed", "balanced", "accuracy"]
for mode in modes:
start_time = time.time()
# Simulate configuration for different modes
if mode == "speed":
config = improved_config.get_adaptive_config(1000) # Large dataset
elif mode == "balanced":
config = improved_config.get_adaptive_config(200) # Medium dataset
else: # accuracy
config = improved_config.get_adaptive_config(50) # Small dataset
end_time = time.time()
print(f"✓ {mode.capitalize()} mode configuration: {(end_time - start_time)*1000:.2f}ms")
print(f" - Detection model: {config.face_detection.model}")
print(f" - Clustering method: {config.clustering.method}")
print(f" - Max workers: {config.processing.max_workers}")
print("✓ Performance comparison completed\n")
return True
except Exception as e:
print(f"✗ Performance comparison failed: {e}\n")
return False
def main():
"""Run all tests."""
print("=" * 60)
print("IMPROVED FACIAL RECOGNITION SYSTEM - TEST SUITE")
print("=" * 60)
print()
tests = [
("Dependencies", test_dependencies),
("Improved Face Detector", test_improved_face_detector),
("Improved Face Clusterer", test_improved_clusterer),
("Improved Configuration", test_improved_config),
("Improved Worker", test_improved_worker),
("Integration Module", test_integration),
("Performance Comparison", run_performance_comparison)
]
passed = 0
total = len(tests)
for test_name, test_func in tests:
print(f"Running {test_name}...")
if test_func():
passed += 1
else:
print(f"❌ {test_name} failed!")
print("=" * 60)
print(f"TEST RESULTS: {passed}/{total} passed")
if passed == total:
print("🎉 All tests passed! The improved system is ready to use.")
print("\nNext steps:")
print("1. Review the IMPROVED_FACIAL_RECOGNITION_GUIDE.md")
print("2. Choose an integration approach (replace pipeline, gradual, or config-based)")
print("3. Test with a small dataset first")
print("4. Monitor performance and provide feedback")
else:
print(f"⚠️ {total - passed} tests failed. Please fix the issues before using the system.")
if passed == 0:
print("\nIt looks like the improved system isn't properly installed.")
print("Make sure all the new files are in the facesorter/ directory:")
print("- improved_face_detector.py")
print("- improved_face_clusterer.py")
print("- improved_config.py")
print("- improved_worker.py")
print("- improved_app_integration.py")
print("=" * 60)
if __name__ == "__main__":
main()