-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate_system.py
More file actions
278 lines (219 loc) · 8.7 KB
/
validate_system.py
File metadata and controls
278 lines (219 loc) · 8.7 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
#!/usr/bin/env python3
"""
System Validation Script
========================
Comprehensive validation of the RecognAIze face recognition system.
This script tests all components, validates functionality, and generates
a detailed validation report.
"""
import os
import sys
import time
import logging
from pathlib import Path
from datetime import datetime
import traceback
# Add src to path for imports
sys.path.insert(0, str(Path(__file__).parent / 'src'))
print("RecognAIze System Validation")
print("=" * 50)
print(f"Start time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
try:
# Import components for testing
from src.face_recognition.detection.detector import FaceDetector
from src.face_recognition.embedding.embedder import FaceEmbedder
from src.face_recognition.inference.similarity_matcher import SimilarityMatcher
from src.face_recognition.inference.pipeline import FaceRecognitionPipeline
from src.face_recognition.inference.embedding_generator import EmbeddingGenerator
from src.face_recognition.inference.test_inference import TestInferencePipeline
from src.face_recognition.utils.data_loader import FaceDataLoader
print("✅ All imports successful")
except Exception as e:
print(f"❌ Import failed: {e}")
sys.exit(1)
def test_dataset_structure(dataset_root):
"""Test dataset structure."""
print("\n🔍 Testing dataset structure...")
required_dirs = [
'reference_faces',
'train/images',
'test/images'
]
required_files = [
'train/labels.csv'
]
for dir_path in required_dirs:
full_path = Path(dataset_root) / dir_path
if not full_path.exists():
print(f" ❌ Missing directory: {dir_path}")
return False
print(f" ✅ Found directory: {dir_path}")
for file_path in required_files:
full_path = Path(dataset_root) / file_path
if not full_path.exists():
print(f" ❌ Missing file: {file_path}")
return False
print(f" ✅ Found file: {file_path}")
# Check for reference employees
ref_path = Path(dataset_root) / 'reference_faces'
emp_dirs = [d for d in ref_path.iterdir() if d.is_dir()]
print(f" ✅ Found {len(emp_dirs)} employee directories")
return len(emp_dirs) >= 10
def test_face_detector():
"""Test face detector."""
print("\n🔍 Testing face detector...")
try:
detector = FaceDetector()
print(" ✅ Face detector initialized")
# Test with synthetic image
import numpy as np
test_image = np.random.randint(0, 255, (200, 200, 3), dtype=np.uint8)
faces = detector.detect_faces(test_image)
print(f" ✅ Detected {len(faces)} faces in synthetic image")
return True
except Exception as e:
print(f" ❌ Face detector test failed: {e}")
return False
def test_face_embedder():
"""Test face embedder."""
print("\n🔍 Testing face embedder...")
try:
embedder = FaceEmbedder()
print(" ✅ Face embedder initialized")
# Test with synthetic face
import numpy as np
test_face = np.random.randint(0, 255, (64, 64, 3), dtype=np.uint8)
embedding = embedder.compute_embedding(test_face)
print(f" ✅ Generated embedding with shape: {embedding.shape}")
return isinstance(embedding, np.ndarray) and len(embedding.shape) == 1
except Exception as e:
print(f" ❌ Face embedder test failed: {e}")
return False
def test_data_loader(dataset_root):
"""Test data loader."""
print("\n🔍 Testing data loader...")
try:
data_loader = FaceDataLoader(dataset_root)
print(" ✅ Data loader initialized")
# Test training data
train_data = data_loader.get_training_data()
print(f" ✅ Loaded {len(train_data[0])} training images")
# Test reference faces
ref_faces = data_loader.get_reference_faces()
print(f" ✅ Loaded {len(ref_faces)} reference employees")
# Test test images
test_images = data_loader.get_test_images()
print(f" ✅ Loaded {len(test_images)} test images")
return len(train_data[0]) > 0 and len(ref_faces) > 0 and len(test_images) > 0
except Exception as e:
print(f" ❌ Data loader test failed: {e}")
return False
def test_pipeline(dataset_root):
"""Test basic pipeline."""
print("\n🔍 Testing pipeline...")
try:
pipeline = FaceRecognitionPipeline(dataset_root=dataset_root)
print(" ✅ Pipeline initialized")
# Test small batch
test_results = pipeline.process_test_images(max_images=2, min_confidence=0.3)
print(f" ✅ Processed {len(test_results)} test images")
return len(test_results) > 0
except Exception as e:
print(f" ❌ Pipeline test failed: {e}")
return False
def test_inference_pipeline(dataset_root):
"""Test inference pipeline."""
print("\n🔍 Testing inference pipeline...")
try:
inference = TestInferencePipeline(dataset_root=dataset_root)
print(" ✅ Inference pipeline initialized")
# Test small inference
output_files = inference.run_complete_inference(
min_confidence=0.3,
max_images=2,
save_debug=False
)
print(f" ✅ Generated {len(output_files)} output files")
# Check files exist
for name, path in output_files.items():
if Path(path).exists():
print(f" ✅ Output file exists: {name}")
else:
print(f" ❌ Missing output file: {name}")
return False
return True
except Exception as e:
print(f" ❌ Inference pipeline test failed: {e}")
return False
def test_main_script():
"""Test main script."""
print("\n🔍 Testing main script...")
try:
import subprocess
# Test help
result = subprocess.run([
sys.executable, 'main.py', '--help'
], capture_output=True, text=True, timeout=30)
if result.returncode == 0:
print(" ✅ Main script help working")
else:
print(" ❌ Main script help failed")
return False
return True
except Exception as e:
print(f" ❌ Main script test failed: {e}")
return False
def main():
"""Run validation."""
dataset_root = "identity-employees-in-surveillance-cctv/dataset"
if len(sys.argv) > 1:
dataset_root = sys.argv[1]
if not os.path.exists(dataset_root):
print(f"❌ Dataset not found: {dataset_root}")
return False
print(f"Dataset: {dataset_root}")
# Run tests
tests = [
("Dataset Structure", lambda: test_dataset_structure(dataset_root)),
("Face Detector", test_face_detector),
("Face Embedder", test_face_embedder),
("Data Loader", lambda: test_data_loader(dataset_root)),
("Pipeline", lambda: test_pipeline(dataset_root)),
("Inference Pipeline", lambda: test_inference_pipeline(dataset_root)),
("Main Script", test_main_script),
]
results = []
for test_name, test_func in tests:
try:
start_time = time.time()
success = test_func()
duration = time.time() - start_time
status = "✅ PASS" if success else "❌ FAIL"
print(f"\n{status} {test_name} ({duration:.1f}s)")
results.append((test_name, success, duration))
except Exception as e:
duration = time.time() - start_time
print(f"\n💥 ERROR {test_name} ({duration:.1f}s): {e}")
results.append((test_name, False, duration))
# Summary
passed = sum(1 for _, success, _ in results if success)
total = len(results)
print("\n" + "=" * 50)
print("VALIDATION SUMMARY")
print("=" * 50)
print(f"Tests passed: {passed}/{total}")
print(f"Success rate: {passed/total*100:.1f}%")
if passed == total:
print("\n🎉 ALL TESTS PASSED!")
print("✅ RecognAIze system is fully functional!")
elif passed >= total * 0.8:
print("\n⚠️ MOSTLY FUNCTIONAL")
print("🔧 Minor issues detected but core system works")
else:
print("\n❌ VALIDATION FAILED")
print("🚫 Significant issues detected")
print("=" * 50)
return passed == total
if __name__ == '__main__':
success = main()
sys.exit(0 if success else 1)