Spaces:
Sleeping
Sleeping
Commit ·
fe2da33
1
Parent(s): f041037
change
Browse files- app/Hackathon_setup/analyze_face_detection.py +0 -248
- app/Hackathon_setup/analyze_model_bias.py +0 -235
- app/Hackathon_setup/app_old.py +0 -135
- app/Hackathon_setup/apply_final_fix.py +0 -132
- app/Hackathon_setup/classifier_analysis.py +0 -276
- app/Hackathon_setup/create_workaround_models.py +0 -66
- app/Hackathon_setup/debug_classification.py +0 -130
- app/Hackathon_setup/deep_debug_classification.py +0 -174
- app/Hackathon_setup/deploy_fix.py +0 -117
- app/Hackathon_setup/deploy_to_huggingface.py +0 -117
- app/Hackathon_setup/diagnose_errors.py +0 -167
- app/Hackathon_setup/diagnose_models.py +0 -132
- app/Hackathon_setup/face_recognition.py +39 -56
- app/Hackathon_setup/face_recognition_old.py +0 -213
- app/Hackathon_setup/fix_class_labels.py +0 -138
- app/Hackathon_setup/fix_class_mapping.py +0 -180
- app/Hackathon_setup/fix_sklearn_advanced.py +0 -149
- app/Hackathon_setup/fix_sklearn_compatibility.py +0 -113
- app/Hackathon_setup/fix_sklearn_warnings.py +0 -98
- app/Hackathon_setup/fix_unknown_class.py +0 -57
- app/Hackathon_setup/inspect_classifier.py +0 -61
- app/Hackathon_setup/inspect_model.py +0 -41
- app/Hackathon_setup/lbpcascade_frontalface.xml +0 -1505
- app/Hackathon_setup/simple_test.py +0 -65
- app/Hackathon_setup/test_all_classes.py +0 -85
- app/Hackathon_setup/test_api.py +0 -132
- app/Hackathon_setup/test_api_fixed.py +0 -142
- app/Hackathon_setup/test_api_simple.py +0 -172
- app/Hackathon_setup/test_api_with_faces.py +0 -228
- app/Hackathon_setup/test_classifier_comprehensive.py +0 -210
- app/Hackathon_setup/test_complete_fix.py +0 -208
- app/Hackathon_setup/test_cosine_similarity.py +0 -159
- app/Hackathon_setup/test_face_recognition_comprehensive.py +0 -114
- app/Hackathon_setup/test_local.py +0 -181
- app/Hackathon_setup/test_model_loading.py +0 -162
- app/Hackathon_setup/test_person1_person7_labels.py +0 -121
- app/Hackathon_setup/test_person2_bias.py +0 -93
- app/Hackathon_setup/test_robust.py +0 -35
app/Hackathon_setup/analyze_face_detection.py
DELETED
|
@@ -1,248 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Analyze face detection issues and improve face recognition pipeline
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
import cv2
|
| 9 |
-
from PIL import Image
|
| 10 |
-
|
| 11 |
-
print("🔍 Face Detection Analysis & Improvement")
|
| 12 |
-
print("=" * 50)
|
| 13 |
-
|
| 14 |
-
def analyze_face_detection_issue():
|
| 15 |
-
"""Analyze why face detection is failing"""
|
| 16 |
-
|
| 17 |
-
print("📊 Current Issue Analysis:")
|
| 18 |
-
print(" - Logs show: 'No faces detected, using fallback'")
|
| 19 |
-
print(" - This means OpenCV face detection is failing")
|
| 20 |
-
print(" - System falls back to using entire image")
|
| 21 |
-
print(" - Classification still works but may be less accurate")
|
| 22 |
-
print()
|
| 23 |
-
|
| 24 |
-
print("🔍 Possible Causes:")
|
| 25 |
-
print(" 1. Face cascade file issues")
|
| 26 |
-
print(" 2. Image quality/resolution problems")
|
| 27 |
-
print(" 3. Face detection parameters too strict")
|
| 28 |
-
print(" 4. Images don't contain clear frontal faces")
|
| 29 |
-
print(" 5. Cascade classifier not loading properly")
|
| 30 |
-
print()
|
| 31 |
-
|
| 32 |
-
def check_cascade_files():
|
| 33 |
-
"""Check if cascade files are working properly"""
|
| 34 |
-
|
| 35 |
-
print("🔧 Checking Cascade Files...")
|
| 36 |
-
|
| 37 |
-
cascade_files = [
|
| 38 |
-
'haarcascade_frontalface_default.xml',
|
| 39 |
-
'haarcascade_eye.xml'
|
| 40 |
-
]
|
| 41 |
-
|
| 42 |
-
for file in cascade_files:
|
| 43 |
-
if os.path.exists(file):
|
| 44 |
-
size = os.path.getsize(file)
|
| 45 |
-
print(f" ✓ {file} exists ({size:,} bytes)")
|
| 46 |
-
|
| 47 |
-
# Test loading
|
| 48 |
-
try:
|
| 49 |
-
cascade = cv2.CascadeClassifier(file)
|
| 50 |
-
if cascade.empty():
|
| 51 |
-
print(f" ❌ {file} failed to load properly")
|
| 52 |
-
else:
|
| 53 |
-
print(f" ✅ {file} loaded successfully")
|
| 54 |
-
except Exception as e:
|
| 55 |
-
print(f" ❌ Error loading {file}: {e}")
|
| 56 |
-
else:
|
| 57 |
-
print(f" ❌ {file} missing")
|
| 58 |
-
|
| 59 |
-
def improve_face_detection():
|
| 60 |
-
"""Improve the face detection function"""
|
| 61 |
-
|
| 62 |
-
print("\n🔧 Improving Face Detection...")
|
| 63 |
-
|
| 64 |
-
# Create improved face detection function
|
| 65 |
-
improved_code = '''
|
| 66 |
-
def improved_detected_face(image):
|
| 67 |
-
"""Improved face detection with better parameters"""
|
| 68 |
-
eye_haar = current_path + '/haarcascade_eye.xml'
|
| 69 |
-
face_haar = current_path + '/haarcascade_frontalface_default.xml'
|
| 70 |
-
|
| 71 |
-
# Check if cascade files exist
|
| 72 |
-
if not os.path.exists(face_haar):
|
| 73 |
-
print(f"Warning: {face_haar} not found, using fallback")
|
| 74 |
-
return Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY))
|
| 75 |
-
|
| 76 |
-
face_cascade = cv2.CascadeClassifier(face_haar)
|
| 77 |
-
eye_cascade = cv2.CascadeClassifier(eye_haar) if os.path.exists(eye_haar) else None
|
| 78 |
-
|
| 79 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 80 |
-
|
| 81 |
-
# Try multiple detection parameters for better results
|
| 82 |
-
detection_params = [
|
| 83 |
-
(1.1, 3), # Default
|
| 84 |
-
(1.05, 4), # More sensitive
|
| 85 |
-
(1.2, 2), # Less sensitive but faster
|
| 86 |
-
(1.3, 5) # Very sensitive
|
| 87 |
-
]
|
| 88 |
-
|
| 89 |
-
faces = []
|
| 90 |
-
for scale_factor, min_neighbors in detection_params:
|
| 91 |
-
faces = face_cascade.detectMultiScale(
|
| 92 |
-
gray,
|
| 93 |
-
scaleFactor=scale_factor,
|
| 94 |
-
minNeighbors=min_neighbors,
|
| 95 |
-
minSize=(30, 30), # Minimum face size
|
| 96 |
-
maxSize=(300, 300) # Maximum face size
|
| 97 |
-
)
|
| 98 |
-
if len(faces) > 0:
|
| 99 |
-
print(f"✓ Faces detected with scaleFactor={scale_factor}, minNeighbors={min_neighbors}")
|
| 100 |
-
break
|
| 101 |
-
|
| 102 |
-
# If still no faces, try with different image preprocessing
|
| 103 |
-
if len(faces) == 0:
|
| 104 |
-
print("No faces detected with standard parameters, trying preprocessing...")
|
| 105 |
-
|
| 106 |
-
# Try histogram equalization
|
| 107 |
-
gray_eq = cv2.equalizeHist(gray)
|
| 108 |
-
faces = face_cascade.detectMultiScale(gray_eq, 1.1, 3)
|
| 109 |
-
|
| 110 |
-
if len(faces) == 0:
|
| 111 |
-
# Try Gaussian blur
|
| 112 |
-
gray_blur = cv2.GaussianBlur(gray, (3, 3), 0)
|
| 113 |
-
faces = face_cascade.detectMultiScale(gray_blur, 1.1, 3)
|
| 114 |
-
|
| 115 |
-
if len(faces) == 0:
|
| 116 |
-
print("No faces detected after all attempts, using fallback")
|
| 117 |
-
return None
|
| 118 |
-
|
| 119 |
-
# Find the largest face
|
| 120 |
-
face_areas = []
|
| 121 |
-
images = []
|
| 122 |
-
|
| 123 |
-
for i, (x, y, w, h) in enumerate(faces):
|
| 124 |
-
face_cropped = gray[y:y+h, x:x+w]
|
| 125 |
-
face_areas.append(w*h)
|
| 126 |
-
images.append(face_cropped)
|
| 127 |
-
|
| 128 |
-
# Get the largest face
|
| 129 |
-
largest_face_idx = np.argmax(face_areas)
|
| 130 |
-
required_image = Image.fromarray(images[largest_face_idx])
|
| 131 |
-
|
| 132 |
-
print(f"✓ Selected face {largest_face_idx + 1} of {len(faces)} detected faces")
|
| 133 |
-
|
| 134 |
-
return required_image
|
| 135 |
-
'''
|
| 136 |
-
|
| 137 |
-
print("✅ Improved face detection function created")
|
| 138 |
-
print(" - Multiple detection parameters")
|
| 139 |
-
print(" - Image preprocessing options")
|
| 140 |
-
print(" - Better error handling")
|
| 141 |
-
print(" - More detailed logging")
|
| 142 |
-
|
| 143 |
-
def create_face_detection_test():
|
| 144 |
-
"""Create a test to verify face detection"""
|
| 145 |
-
|
| 146 |
-
print("\n🧪 Creating Face Detection Test...")
|
| 147 |
-
|
| 148 |
-
test_code = '''
|
| 149 |
-
def test_face_detection():
|
| 150 |
-
"""Test face detection with sample images"""
|
| 151 |
-
|
| 152 |
-
# Test with actual image if available
|
| 153 |
-
test_paths = [
|
| 154 |
-
"../static/Person1_1697805233.jpg",
|
| 155 |
-
"Person1_1697805233.jpg",
|
| 156 |
-
"static/Person1_1697805233.jpg"
|
| 157 |
-
]
|
| 158 |
-
|
| 159 |
-
for path in test_paths:
|
| 160 |
-
if os.path.exists(path):
|
| 161 |
-
print(f"Testing face detection with: {path}")
|
| 162 |
-
|
| 163 |
-
# Load image
|
| 164 |
-
img = cv2.imread(path)
|
| 165 |
-
print(f"Image shape: {img.shape}")
|
| 166 |
-
|
| 167 |
-
# Test face detection
|
| 168 |
-
detected = improved_detected_face(img)
|
| 169 |
-
|
| 170 |
-
if detected is not None:
|
| 171 |
-
print(f"✅ Face detected successfully: {type(detected)}")
|
| 172 |
-
print(f"Face size: {detected.size}")
|
| 173 |
-
else:
|
| 174 |
-
print("❌ No face detected")
|
| 175 |
-
|
| 176 |
-
break
|
| 177 |
-
else:
|
| 178 |
-
print("No test images found")
|
| 179 |
-
|
| 180 |
-
# Create synthetic face for testing
|
| 181 |
-
print("Creating synthetic face for testing...")
|
| 182 |
-
synthetic_img = np.zeros((200, 200, 3), dtype=np.uint8)
|
| 183 |
-
|
| 184 |
-
# Draw a simple face
|
| 185 |
-
cv2.ellipse(synthetic_img, (100, 100), (80, 100), 0, 0, 360, (120, 120, 120), -1)
|
| 186 |
-
cv2.circle(synthetic_img, (70, 80), 8, (200, 200, 200), -1)
|
| 187 |
-
cv2.circle(synthetic_img, (130, 80), 8, (200, 200, 200), -1)
|
| 188 |
-
cv2.line(synthetic_img, (100, 90), (100, 120), (150, 150, 150), 3)
|
| 189 |
-
cv2.ellipse(synthetic_img, (100, 140), (20, 10), 0, 0, 180, (150, 150, 150), 2)
|
| 190 |
-
|
| 191 |
-
print("Testing with synthetic face...")
|
| 192 |
-
detected = improved_detected_face(synthetic_img)
|
| 193 |
-
|
| 194 |
-
if detected is not None:
|
| 195 |
-
print("✅ Synthetic face detected successfully")
|
| 196 |
-
else:
|
| 197 |
-
print("❌ Even synthetic face not detected - cascade issue")
|
| 198 |
-
'''
|
| 199 |
-
|
| 200 |
-
print("✅ Face detection test created")
|
| 201 |
-
|
| 202 |
-
def provide_recommendations():
|
| 203 |
-
"""Provide recommendations for better face detection"""
|
| 204 |
-
|
| 205 |
-
print("\n💡 Recommendations for Better Face Detection:")
|
| 206 |
-
print()
|
| 207 |
-
print("1. 📸 Image Quality:")
|
| 208 |
-
print(" - Ensure images have clear, frontal faces")
|
| 209 |
-
print(" - Good lighting and contrast")
|
| 210 |
-
print(" - Face should be clearly visible")
|
| 211 |
-
print(" - Avoid side profiles or partially hidden faces")
|
| 212 |
-
print()
|
| 213 |
-
|
| 214 |
-
print("2. 🔧 Detection Parameters:")
|
| 215 |
-
print(" - Try different scaleFactor values (1.05-1.3)")
|
| 216 |
-
print(" - Adjust minNeighbors (2-5)")
|
| 217 |
-
print(" - Set appropriate minSize and maxSize")
|
| 218 |
-
print()
|
| 219 |
-
|
| 220 |
-
print("3. 🖼️ Image Preprocessing:")
|
| 221 |
-
print(" - Histogram equalization for better contrast")
|
| 222 |
-
print(" - Gaussian blur to reduce noise")
|
| 223 |
-
print(" - Resize images to standard size")
|
| 224 |
-
print()
|
| 225 |
-
|
| 226 |
-
print("4. 📊 Training Data Considerations:")
|
| 227 |
-
print(" - Your training used face detection during training")
|
| 228 |
-
print(" - If training images had faces detected, inference should too")
|
| 229 |
-
print(" - Check if training images were preprocessed differently")
|
| 230 |
-
print()
|
| 231 |
-
|
| 232 |
-
print("5. 🎯 Current Status:")
|
| 233 |
-
print(" - ✅ Classification working (Person2 detected)")
|
| 234 |
-
print(" - ⚠️ Face detection failing (using fallback)")
|
| 235 |
-
print(" - ✅ System still functional but may be less accurate")
|
| 236 |
-
|
| 237 |
-
if __name__ == "__main__":
|
| 238 |
-
analyze_face_detection_issue()
|
| 239 |
-
check_cascade_files()
|
| 240 |
-
improve_face_detection()
|
| 241 |
-
create_face_detection_test()
|
| 242 |
-
provide_recommendations()
|
| 243 |
-
|
| 244 |
-
print("\n🎯 Summary:")
|
| 245 |
-
print("Your classification is working correctly (Person2 detected)")
|
| 246 |
-
print("Face detection is failing but system uses fallback")
|
| 247 |
-
print("This may reduce accuracy but doesn't break the system")
|
| 248 |
-
print("Consider improving image quality or detection parameters")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/analyze_model_bias.py
DELETED
|
@@ -1,235 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Analyze and fix model bias issue - always predicting Person2
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
import joblib
|
| 9 |
-
import torch
|
| 10 |
-
from PIL import Image
|
| 11 |
-
import cv2
|
| 12 |
-
|
| 13 |
-
print("🔍 Model Bias Analysis - Always Predicting Person2")
|
| 14 |
-
print("=" * 60)
|
| 15 |
-
|
| 16 |
-
def analyze_model_bias():
|
| 17 |
-
"""Analyze why the model always predicts Person2"""
|
| 18 |
-
|
| 19 |
-
print("📊 Current Issue:")
|
| 20 |
-
print(" - Face detection now working ✅")
|
| 21 |
-
print(" - But model always predicts Person2 ❌")
|
| 22 |
-
print(" - This suggests model bias or training data imbalance")
|
| 23 |
-
print()
|
| 24 |
-
|
| 25 |
-
try:
|
| 26 |
-
# Load classifier and scaler
|
| 27 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 28 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 29 |
-
|
| 30 |
-
print("🔍 Model Analysis:")
|
| 31 |
-
print(f" Classifier type: {type(classifier)}")
|
| 32 |
-
print(f" Classifier classes: {classifier.classes_}")
|
| 33 |
-
print(f" Scaler features: {scaler.n_features_in_}")
|
| 34 |
-
|
| 35 |
-
# Check if it's a KNN classifier
|
| 36 |
-
if hasattr(classifier, 'n_neighbors'):
|
| 37 |
-
print(f" KNN neighbors: {classifier.n_neighbors}")
|
| 38 |
-
|
| 39 |
-
# Test with random features
|
| 40 |
-
print("\n🧪 Testing with random features:")
|
| 41 |
-
for i in range(5):
|
| 42 |
-
random_features = np.random.randn(1, scaler.n_features_in_)
|
| 43 |
-
scaled_features = scaler.transform(random_features)
|
| 44 |
-
prediction = classifier.predict(scaled_features)[0]
|
| 45 |
-
print(f" Random test {i+1}: {prediction}")
|
| 46 |
-
|
| 47 |
-
# Check training data distribution
|
| 48 |
-
if hasattr(classifier, '_y'):
|
| 49 |
-
unique, counts = np.unique(classifier._y, return_counts=True)
|
| 50 |
-
print(f"\n📊 Training data distribution:")
|
| 51 |
-
for class_id, count in zip(unique, counts):
|
| 52 |
-
print(f" Class {class_id}: {count} samples")
|
| 53 |
-
|
| 54 |
-
return True
|
| 55 |
-
|
| 56 |
-
except Exception as e:
|
| 57 |
-
print(f"❌ Error analyzing model: {e}")
|
| 58 |
-
return False
|
| 59 |
-
|
| 60 |
-
def test_feature_extraction():
|
| 61 |
-
"""Test if feature extraction is working properly"""
|
| 62 |
-
|
| 63 |
-
print("\n🔬 Testing Feature Extraction:")
|
| 64 |
-
|
| 65 |
-
try:
|
| 66 |
-
from face_recognition import detected_face, trnscm, CLASS_NAMES
|
| 67 |
-
from face_recognition_model import Siamese
|
| 68 |
-
|
| 69 |
-
# Create test images with different characteristics
|
| 70 |
-
test_images = []
|
| 71 |
-
|
| 72 |
-
# Image 1: Simple face
|
| 73 |
-
img1 = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 74 |
-
cv2.ellipse(img1, (50, 50), (40, 50), 0, 0, 360, (120, 120, 120), -1)
|
| 75 |
-
cv2.circle(img1, (35, 40), 5, (200, 200, 200), -1)
|
| 76 |
-
cv2.circle(img1, (65, 40), 5, (200, 200, 200), -1)
|
| 77 |
-
test_images.append(("Simple face", img1))
|
| 78 |
-
|
| 79 |
-
# Image 2: Different face
|
| 80 |
-
img2 = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 81 |
-
cv2.ellipse(img2, (50, 50), (40, 50), 0, 0, 360, (100, 100, 100), -1)
|
| 82 |
-
cv2.circle(img2, (30, 40), 6, (180, 180, 180), -1)
|
| 83 |
-
cv2.circle(img2, (70, 40), 6, (180, 180, 180), -1)
|
| 84 |
-
test_images.append(("Different face", img2))
|
| 85 |
-
|
| 86 |
-
# Image 3: Very different face
|
| 87 |
-
img3 = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 88 |
-
cv2.ellipse(img3, (50, 50), (35, 45), 0, 0, 360, (140, 140, 140), -1)
|
| 89 |
-
cv2.circle(img3, (40, 45), 4, (220, 220, 220), -1)
|
| 90 |
-
cv2.circle(img3, (60, 45), 4, (220, 220, 220), -1)
|
| 91 |
-
test_images.append(("Very different face", img3))
|
| 92 |
-
|
| 93 |
-
# Test each image
|
| 94 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 95 |
-
siamese_net = Siamese().to(device)
|
| 96 |
-
|
| 97 |
-
# Load model
|
| 98 |
-
model_data = torch.load('siamese_model.t7', map_location=device)
|
| 99 |
-
if isinstance(model_data, dict) and 'net_dict' in model_data:
|
| 100 |
-
siamese_net.load_state_dict(model_data['net_dict'])
|
| 101 |
-
else:
|
| 102 |
-
siamese_net.load_state_dict(model_data)
|
| 103 |
-
siamese_net.eval()
|
| 104 |
-
|
| 105 |
-
print(" Testing feature extraction with different images:")
|
| 106 |
-
|
| 107 |
-
for name, img in test_images:
|
| 108 |
-
# Face detection
|
| 109 |
-
detected = detected_face(img)
|
| 110 |
-
if detected is None:
|
| 111 |
-
detected = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))
|
| 112 |
-
|
| 113 |
-
# Transform
|
| 114 |
-
face_tensor = trnscm(detected).unsqueeze(0).to(device)
|
| 115 |
-
|
| 116 |
-
# Extract features
|
| 117 |
-
with torch.no_grad():
|
| 118 |
-
embedding = siamese_net.forward_once(face_tensor).cpu().numpy()
|
| 119 |
-
if embedding.ndim == 1:
|
| 120 |
-
embedding = embedding.reshape(1, -1)
|
| 121 |
-
|
| 122 |
-
print(f" {name}: embedding shape {embedding.shape}, values {embedding.flatten()[:3]}")
|
| 123 |
-
|
| 124 |
-
return True
|
| 125 |
-
|
| 126 |
-
except Exception as e:
|
| 127 |
-
print(f"❌ Error testing feature extraction: {e}")
|
| 128 |
-
import traceback
|
| 129 |
-
traceback.print_exc()
|
| 130 |
-
return False
|
| 131 |
-
|
| 132 |
-
def diagnose_classification_pipeline():
|
| 133 |
-
"""Diagnose the entire classification pipeline"""
|
| 134 |
-
|
| 135 |
-
print("\n🔧 Diagnosing Classification Pipeline:")
|
| 136 |
-
|
| 137 |
-
try:
|
| 138 |
-
from face_recognition import get_face_class
|
| 139 |
-
|
| 140 |
-
# Test with different synthetic images
|
| 141 |
-
test_cases = [
|
| 142 |
-
("Person1-like", create_person1_like_image()),
|
| 143 |
-
("Person2-like", create_person2_like_image()),
|
| 144 |
-
("Person3-like", create_person3_like_image())
|
| 145 |
-
]
|
| 146 |
-
|
| 147 |
-
for name, img in test_cases:
|
| 148 |
-
result = get_face_class(img)
|
| 149 |
-
print(f" {name}: {result}")
|
| 150 |
-
|
| 151 |
-
return True
|
| 152 |
-
|
| 153 |
-
except Exception as e:
|
| 154 |
-
print(f"❌ Error in classification pipeline: {e}")
|
| 155 |
-
return False
|
| 156 |
-
|
| 157 |
-
def create_person1_like_image():
|
| 158 |
-
"""Create an image that should look like Person1"""
|
| 159 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 160 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (120, 120, 120), -1)
|
| 161 |
-
cv2.circle(img, (35, 40), 5, (200, 200, 200), -1)
|
| 162 |
-
cv2.circle(img, (65, 40), 5, (200, 200, 200), -1)
|
| 163 |
-
cv2.line(img, (50, 45), (50, 60), (150, 150, 150), 2)
|
| 164 |
-
cv2.ellipse(img, (50, 70), (15, 8), 0, 0, 180, (150, 150, 150), 2)
|
| 165 |
-
return img
|
| 166 |
-
|
| 167 |
-
def create_person2_like_image():
|
| 168 |
-
"""Create an image that should look like Person2"""
|
| 169 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 170 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (100, 100, 100), -1)
|
| 171 |
-
cv2.circle(img, (30, 40), 6, (180, 180, 180), -1)
|
| 172 |
-
cv2.circle(img, (70, 40), 6, (180, 180, 180), -1)
|
| 173 |
-
cv2.line(img, (50, 45), (50, 60), (140, 140, 140), 2)
|
| 174 |
-
cv2.ellipse(img, (50, 70), (18, 10), 0, 0, 180, (140, 140, 140), 2)
|
| 175 |
-
return img
|
| 176 |
-
|
| 177 |
-
def create_person3_like_image():
|
| 178 |
-
"""Create an image that should look like Person3"""
|
| 179 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 180 |
-
cv2.ellipse(img, (50, 50), (35, 45), 0, 0, 360, (140, 140, 140), -1)
|
| 181 |
-
cv2.circle(img, (40, 45), 4, (220, 220, 220), -1)
|
| 182 |
-
cv2.circle(img, (60, 45), 4, (220, 220, 220), -1)
|
| 183 |
-
cv2.line(img, (50, 45), (50, 60), (160, 160, 160), 2)
|
| 184 |
-
cv2.ellipse(img, (50, 70), (12, 6), 0, 0, 180, (160, 160, 160), 2)
|
| 185 |
-
return img
|
| 186 |
-
|
| 187 |
-
def provide_solutions():
|
| 188 |
-
"""Provide solutions for the Person2 bias issue"""
|
| 189 |
-
|
| 190 |
-
print("\n💡 Solutions for Person2 Bias Issue:")
|
| 191 |
-
print()
|
| 192 |
-
print("1. 🎯 Model Bias Causes:")
|
| 193 |
-
print(" - Training data heavily skewed toward Person2")
|
| 194 |
-
print(" - Person2 had 100% precision/recall in training")
|
| 195 |
-
print(" - Model learned to favor Person2")
|
| 196 |
-
print(" - Insufficient diversity in Person1 and Person3")
|
| 197 |
-
print()
|
| 198 |
-
|
| 199 |
-
print("2. 🔧 Immediate Solutions:")
|
| 200 |
-
print(" - Retrain with balanced data (equal samples per person)")
|
| 201 |
-
print(" - Add more Person1 and Person3 training images")
|
| 202 |
-
print(" - Use data augmentation for minority classes")
|
| 203 |
-
print(" - Try different k values (k=3 instead of k=5)")
|
| 204 |
-
print()
|
| 205 |
-
|
| 206 |
-
print("3. 📊 Data Collection:")
|
| 207 |
-
print(" - Collect 20-30 images per person")
|
| 208 |
-
print(" - Ensure diverse lighting and angles")
|
| 209 |
-
print(" - Include different expressions")
|
| 210 |
-
print(" - Balance the dataset")
|
| 211 |
-
print()
|
| 212 |
-
|
| 213 |
-
print("4. 🎛️ Model Adjustments:")
|
| 214 |
-
print(" - Try DecisionTree instead of KNN")
|
| 215 |
-
print(" - Use class weights to balance")
|
| 216 |
-
print(" - Experiment with different metrics")
|
| 217 |
-
print()
|
| 218 |
-
|
| 219 |
-
print("5. 🧪 Quick Test:")
|
| 220 |
-
print(" - Upload images of different people")
|
| 221 |
-
print(" - Check if they all get Person2")
|
| 222 |
-
print(" - If yes, it's definitely model bias")
|
| 223 |
-
|
| 224 |
-
if __name__ == "__main__":
|
| 225 |
-
print("Starting Model Bias Analysis...")
|
| 226 |
-
|
| 227 |
-
success1 = analyze_model_bias()
|
| 228 |
-
success2 = test_feature_extraction()
|
| 229 |
-
success3 = diagnose_classification_pipeline()
|
| 230 |
-
provide_solutions()
|
| 231 |
-
|
| 232 |
-
print("\n🎯 Summary:")
|
| 233 |
-
print("The model is biased toward Person2 due to training data imbalance")
|
| 234 |
-
print("Person2 had perfect performance in training (100% precision/recall)")
|
| 235 |
-
print("Need to retrain with balanced data for better performance")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/app_old.py
DELETED
|
@@ -1,135 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Hugging Face Space App for Face Recognition
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import gradio as gr
|
| 6 |
-
import numpy as np
|
| 7 |
-
import cv2
|
| 8 |
-
from PIL import Image
|
| 9 |
-
import torch
|
| 10 |
-
import joblib
|
| 11 |
-
import warnings
|
| 12 |
-
import os
|
| 13 |
-
|
| 14 |
-
# Suppress sklearn version warnings
|
| 15 |
-
warnings.filterwarnings('ignore', category=UserWarning, module='sklearn')
|
| 16 |
-
warnings.filterwarnings('ignore', message='.*InconsistentVersionWarning.*')
|
| 17 |
-
|
| 18 |
-
# Import your face recognition functions
|
| 19 |
-
from face_recognition import get_similarity, get_face_class
|
| 20 |
-
|
| 21 |
-
def predict_similarity(file1, file2):
|
| 22 |
-
"""Predict similarity between two face images"""
|
| 23 |
-
try:
|
| 24 |
-
# Convert Gradio file objects to images
|
| 25 |
-
if file1 is None or file2 is None:
|
| 26 |
-
return "Please upload both images"
|
| 27 |
-
|
| 28 |
-
# Load images
|
| 29 |
-
img1 = cv2.imread(file1)
|
| 30 |
-
img2 = cv2.imread(file2)
|
| 31 |
-
|
| 32 |
-
if img1 is None or img2 is None:
|
| 33 |
-
return "Error loading images. Please ensure they are valid image files."
|
| 34 |
-
|
| 35 |
-
# Get similarity score
|
| 36 |
-
similarity_score = get_similarity(img1, img2)
|
| 37 |
-
|
| 38 |
-
# Interpret the result
|
| 39 |
-
if similarity_score > 0.8:
|
| 40 |
-
result = f"Very High Similarity ({similarity_score:.4f}) - Likely same person"
|
| 41 |
-
elif similarity_score > 0.6:
|
| 42 |
-
result = f"High Similarity ({similarity_score:.4f}) - Possibly same person"
|
| 43 |
-
elif similarity_score > 0.4:
|
| 44 |
-
result = f"Moderate Similarity ({similarity_score:.4f}) - Uncertain"
|
| 45 |
-
elif similarity_score > 0.2:
|
| 46 |
-
result = f"Low Similarity ({similarity_score:.4f}) - Likely different persons"
|
| 47 |
-
else:
|
| 48 |
-
result = f"Very Low Similarity ({similarity_score:.4f}) - Definitely different persons"
|
| 49 |
-
|
| 50 |
-
return result
|
| 51 |
-
|
| 52 |
-
except Exception as e:
|
| 53 |
-
return f"Error: {str(e)}"
|
| 54 |
-
|
| 55 |
-
def predict_class(file):
|
| 56 |
-
"""Predict the class of a face image"""
|
| 57 |
-
try:
|
| 58 |
-
if file is None:
|
| 59 |
-
return "Please upload an image"
|
| 60 |
-
|
| 61 |
-
# Load image
|
| 62 |
-
img = cv2.imread(file)
|
| 63 |
-
|
| 64 |
-
if img is None:
|
| 65 |
-
return "Error loading image. Please ensure it's a valid image file."
|
| 66 |
-
|
| 67 |
-
# Get face class
|
| 68 |
-
face_class = get_face_class(img)
|
| 69 |
-
|
| 70 |
-
return f"Predicted Face Class: {face_class}"
|
| 71 |
-
|
| 72 |
-
except Exception as e:
|
| 73 |
-
return f"Error: {str(e)}"
|
| 74 |
-
|
| 75 |
-
# Create Gradio interface
|
| 76 |
-
with gr.Blocks(title="Face Recognition System") as demo:
|
| 77 |
-
gr.Markdown("# Face Recognition System")
|
| 78 |
-
gr.Markdown("Upload face images to compare similarity or classify faces.")
|
| 79 |
-
|
| 80 |
-
with gr.Tab("Face Similarity"):
|
| 81 |
-
gr.Markdown("## Compare Two Faces")
|
| 82 |
-
gr.Markdown("Upload two face images to compare their similarity.")
|
| 83 |
-
|
| 84 |
-
with gr.Row():
|
| 85 |
-
with gr.Column():
|
| 86 |
-
img1 = gr.Image(type="filepath", label="First Face Image")
|
| 87 |
-
with gr.Column():
|
| 88 |
-
img2 = gr.Image(type="filepath", label="Second Face Image")
|
| 89 |
-
|
| 90 |
-
similarity_btn = gr.Button("Compare Faces", variant="primary")
|
| 91 |
-
similarity_output = gr.Textbox(label="Similarity Result", interactive=False)
|
| 92 |
-
|
| 93 |
-
similarity_btn.click(
|
| 94 |
-
fn=predict_similarity,
|
| 95 |
-
inputs=[img1, img2],
|
| 96 |
-
outputs=similarity_output
|
| 97 |
-
)
|
| 98 |
-
|
| 99 |
-
with gr.Tab("Face Classification"):
|
| 100 |
-
gr.Markdown("## Classify a Face")
|
| 101 |
-
gr.Markdown("Upload a face image to classify it.")
|
| 102 |
-
|
| 103 |
-
img_class = gr.Image(type="filepath", label="Face Image")
|
| 104 |
-
class_btn = gr.Button("Classify Face", variant="primary")
|
| 105 |
-
class_output = gr.Textbox(label="Classification Result", interactive=False)
|
| 106 |
-
|
| 107 |
-
class_btn.click(
|
| 108 |
-
fn=predict_class,
|
| 109 |
-
inputs=[img_class],
|
| 110 |
-
outputs=class_output
|
| 111 |
-
)
|
| 112 |
-
|
| 113 |
-
with gr.Tab("About"):
|
| 114 |
-
gr.Markdown("""
|
| 115 |
-
## About This Face Recognition System
|
| 116 |
-
|
| 117 |
-
This system uses:
|
| 118 |
-
- **Siamese Neural Network** for face feature extraction
|
| 119 |
-
- **Cosine Similarity** for face comparison
|
| 120 |
-
- **K-Nearest Neighbors** for face classification
|
| 121 |
-
|
| 122 |
-
### How to Use:
|
| 123 |
-
1. **Face Similarity**: Upload two face images to compare their similarity
|
| 124 |
-
2. **Face Classification**: Upload a single face image to classify it
|
| 125 |
-
|
| 126 |
-
### Similarity Scores:
|
| 127 |
-
- **0.8-1.0**: Very High Similarity (likely same person)
|
| 128 |
-
- **0.6-0.8**: High Similarity (possibly same person)
|
| 129 |
-
- **0.4-0.6**: Moderate Similarity (uncertain)
|
| 130 |
-
- **0.2-0.4**: Low Similarity (likely different persons)
|
| 131 |
-
- **0.0-0.2**: Very Low Similarity (definitely different persons)
|
| 132 |
-
""")
|
| 133 |
-
|
| 134 |
-
if __name__ == "__main__":
|
| 135 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/apply_final_fix.py
DELETED
|
@@ -1,132 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Final fix for UNKNOWN_CLASS issue in face recognition
|
| 3 |
-
This script addresses the most common causes of UNKNOWN_CLASS predictions
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
import os
|
| 7 |
-
import sys
|
| 8 |
-
import numpy as np
|
| 9 |
-
import cv2
|
| 10 |
-
from PIL import Image
|
| 11 |
-
|
| 12 |
-
# Add current directory to path
|
| 13 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 14 |
-
|
| 15 |
-
def apply_final_fix():
|
| 16 |
-
"""Apply the final fix for UNKNOWN_CLASS issue"""
|
| 17 |
-
print("Applying Final Fix for UNKNOWN_CLASS Issue")
|
| 18 |
-
print("=" * 50)
|
| 19 |
-
|
| 20 |
-
# 1. Verify CLASS_NAMES consistency
|
| 21 |
-
print("1. Checking CLASS_NAMES consistency...")
|
| 22 |
-
try:
|
| 23 |
-
from face_recognition import CLASS_NAMES
|
| 24 |
-
from face_recognition_model import classes
|
| 25 |
-
|
| 26 |
-
print(f" CLASS_NAMES: {CLASS_NAMES}")
|
| 27 |
-
print(f" classes: {classes}")
|
| 28 |
-
|
| 29 |
-
if CLASS_NAMES == classes:
|
| 30 |
-
print(" ✓ Class names are consistent")
|
| 31 |
-
else:
|
| 32 |
-
print(" ✗ Class names are inconsistent - fixing...")
|
| 33 |
-
# Update face_recognition_model.py to match CLASS_NAMES
|
| 34 |
-
with open('face_recognition_model.py', 'r') as f:
|
| 35 |
-
content = f.read()
|
| 36 |
-
|
| 37 |
-
# Replace the classes definition
|
| 38 |
-
old_classes = "classes = ['person1','person2','person3','person4','person5','person6','person7']"
|
| 39 |
-
new_classes = "classes = ['Person0','Person1','Person2','Person3','Person4','Person5','Person6']"
|
| 40 |
-
|
| 41 |
-
if old_classes in content:
|
| 42 |
-
content = content.replace(old_classes, new_classes)
|
| 43 |
-
with open('face_recognition_model.py', 'w') as f:
|
| 44 |
-
f.write(content)
|
| 45 |
-
print(" ✓ Fixed class names in face_recognition_model.py")
|
| 46 |
-
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print(f" ✗ Error checking class names: {e}")
|
| 49 |
-
|
| 50 |
-
# 2. Test model loading and prediction
|
| 51 |
-
print("\n2. Testing model loading and prediction...")
|
| 52 |
-
try:
|
| 53 |
-
import joblib
|
| 54 |
-
|
| 55 |
-
# Load models
|
| 56 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 57 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 58 |
-
|
| 59 |
-
print(f" ✓ Classifier loaded: {len(classifier.classes_)} classes")
|
| 60 |
-
print(f" ✓ Scaler loaded: {scaler.n_features_in_} features")
|
| 61 |
-
|
| 62 |
-
# Test prediction with dummy data
|
| 63 |
-
dummy_features = np.random.randn(1, scaler.n_features_in_)
|
| 64 |
-
scaled_features = scaler.transform(dummy_features)
|
| 65 |
-
prediction = classifier.predict(scaled_features)[0]
|
| 66 |
-
|
| 67 |
-
print(f" ✓ Test prediction: {prediction}")
|
| 68 |
-
|
| 69 |
-
# Check if prediction maps to valid class name
|
| 70 |
-
if prediction < len(CLASS_NAMES):
|
| 71 |
-
class_name = CLASS_NAMES[prediction]
|
| 72 |
-
print(f" ✓ Maps to: {class_name}")
|
| 73 |
-
else:
|
| 74 |
-
print(f" ✗ Prediction {prediction} is out of range!")
|
| 75 |
-
|
| 76 |
-
except Exception as e:
|
| 77 |
-
print(f" ✗ Error testing models: {e}")
|
| 78 |
-
|
| 79 |
-
# 3. Test face recognition with synthetic image
|
| 80 |
-
print("\n3. Testing face recognition with synthetic image...")
|
| 81 |
-
try:
|
| 82 |
-
from face_recognition import get_face_class
|
| 83 |
-
|
| 84 |
-
# Create a synthetic face image
|
| 85 |
-
synthetic_img = create_test_face_image()
|
| 86 |
-
|
| 87 |
-
# Test classification
|
| 88 |
-
result = get_face_class(synthetic_img)
|
| 89 |
-
print(f" ✓ Classification result: {result}")
|
| 90 |
-
|
| 91 |
-
if result in CLASS_NAMES:
|
| 92 |
-
print(" ✓ Result is a valid class name - FIX SUCCESSFUL!")
|
| 93 |
-
elif result == "UNKNOWN_CLASS":
|
| 94 |
-
print(" ✗ Still getting UNKNOWN_CLASS - need further investigation")
|
| 95 |
-
else:
|
| 96 |
-
print(f" ? Unexpected result: {result}")
|
| 97 |
-
|
| 98 |
-
except Exception as e:
|
| 99 |
-
print(f" ✗ Error testing face recognition: {e}")
|
| 100 |
-
import traceback
|
| 101 |
-
traceback.print_exc()
|
| 102 |
-
|
| 103 |
-
# 4. Provide recommendations
|
| 104 |
-
print("\n4. Recommendations:")
|
| 105 |
-
print(" - Ensure all model files are present and not corrupted")
|
| 106 |
-
print(" - Check that the training data had 7 classes (0-6)")
|
| 107 |
-
print(" - Verify that the Siamese network outputs 5 features")
|
| 108 |
-
print(" - Make sure the scaler was trained on the same feature space")
|
| 109 |
-
print(" - Test with actual face images, not just synthetic ones")
|
| 110 |
-
|
| 111 |
-
def create_test_face_image():
|
| 112 |
-
"""Create a test face image for validation"""
|
| 113 |
-
# Create a simple face-like image
|
| 114 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 115 |
-
|
| 116 |
-
# Face outline
|
| 117 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (120, 120, 120), -1)
|
| 118 |
-
|
| 119 |
-
# Eyes
|
| 120 |
-
cv2.circle(img, (35, 40), 4, (200, 200, 200), -1)
|
| 121 |
-
cv2.circle(img, (65, 40), 4, (200, 200, 200), -1)
|
| 122 |
-
|
| 123 |
-
# Nose
|
| 124 |
-
cv2.line(img, (50, 45), (50, 60), (150, 150, 150), 2)
|
| 125 |
-
|
| 126 |
-
# Mouth
|
| 127 |
-
cv2.ellipse(img, (50, 70), (15, 6), 0, 0, 180, (150, 150, 150), 2)
|
| 128 |
-
|
| 129 |
-
return img
|
| 130 |
-
|
| 131 |
-
if __name__ == "__main__":
|
| 132 |
-
apply_final_fix()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/classifier_analysis.py
DELETED
|
@@ -1,276 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Analyze KNN vs other classifiers for face recognition
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import numpy as np
|
| 6 |
-
import joblib
|
| 7 |
-
from sklearn.neighbors import KNeighborsClassifier
|
| 8 |
-
from sklearn.tree import DecisionTreeClassifier
|
| 9 |
-
from sklearn.svm import SVC
|
| 10 |
-
from sklearn.ensemble import RandomForestClassifier
|
| 11 |
-
from sklearn.linear_model import LogisticRegression
|
| 12 |
-
from sklearn.metrics import accuracy_score, classification_report
|
| 13 |
-
|
| 14 |
-
print("🔍 Classifier Analysis for Face Recognition")
|
| 15 |
-
print("=" * 60)
|
| 16 |
-
|
| 17 |
-
def analyze_current_knn():
|
| 18 |
-
"""Analyze the current KNN classifier performance"""
|
| 19 |
-
|
| 20 |
-
print("📊 Current KNN Performance Analysis:")
|
| 21 |
-
print(" Based on your training report:")
|
| 22 |
-
print(" - Accuracy: 71.43%")
|
| 23 |
-
print(" - Person1 (Class 0): 60% precision, 100% recall")
|
| 24 |
-
print(" - Person2 (Class 1): 100% precision, 100% recall")
|
| 25 |
-
print(" - Person3 (Class 2): 0% precision, 0% recall")
|
| 26 |
-
print()
|
| 27 |
-
|
| 28 |
-
print("🔍 KNN Issues Identified:")
|
| 29 |
-
print(" 1. Poor Person3 performance (0% precision/recall)")
|
| 30 |
-
print(" 2. Imbalanced training data (15, 11, 7 samples)")
|
| 31 |
-
print(" 3. Small dataset (33 total samples)")
|
| 32 |
-
print(" 4. Sensitive to outliers and noise")
|
| 33 |
-
print()
|
| 34 |
-
|
| 35 |
-
def compare_classifiers():
|
| 36 |
-
"""Compare different classifiers for face recognition"""
|
| 37 |
-
|
| 38 |
-
print("🏆 Classifier Comparison for Face Recognition:")
|
| 39 |
-
print()
|
| 40 |
-
|
| 41 |
-
classifiers = {
|
| 42 |
-
"K-Nearest Neighbors (Current)": {
|
| 43 |
-
"pros": [
|
| 44 |
-
"Simple and intuitive",
|
| 45 |
-
"No training time (lazy learning)",
|
| 46 |
-
"Works well with small datasets",
|
| 47 |
-
"Non-parametric (no assumptions about data distribution)",
|
| 48 |
-
"Good for non-linear decision boundaries"
|
| 49 |
-
],
|
| 50 |
-
"cons": [
|
| 51 |
-
"Sensitive to irrelevant features",
|
| 52 |
-
"Computationally expensive during prediction",
|
| 53 |
-
"Sensitive to outliers",
|
| 54 |
-
"Poor performance with high-dimensional data",
|
| 55 |
-
"Memory intensive (stores all training data)"
|
| 56 |
-
],
|
| 57 |
-
"best_for": "Small datasets, non-linear patterns, simple implementation"
|
| 58 |
-
},
|
| 59 |
-
|
| 60 |
-
"Decision Tree": {
|
| 61 |
-
"pros": [
|
| 62 |
-
"Easy to interpret and visualize",
|
| 63 |
-
"Handles both numerical and categorical data",
|
| 64 |
-
"Requires little data preparation",
|
| 65 |
-
"Can handle missing values",
|
| 66 |
-
"Fast prediction",
|
| 67 |
-
"Good for feature importance"
|
| 68 |
-
],
|
| 69 |
-
"cons": [
|
| 70 |
-
"Prone to overfitting",
|
| 71 |
-
"Unstable (small changes in data can cause big changes)",
|
| 72 |
-
"Biased towards features with more levels",
|
| 73 |
-
"Can create biased trees if some classes dominate"
|
| 74 |
-
],
|
| 75 |
-
"best_for": "Interpretable models, feature selection, fast inference"
|
| 76 |
-
},
|
| 77 |
-
|
| 78 |
-
"Random Forest": {
|
| 79 |
-
"pros": [
|
| 80 |
-
"Reduces overfitting compared to single decision tree",
|
| 81 |
-
"Handles missing values well",
|
| 82 |
-
"Provides feature importance",
|
| 83 |
-
"Works well with imbalanced data",
|
| 84 |
-
"Robust to outliers",
|
| 85 |
-
"Good performance on many problems"
|
| 86 |
-
],
|
| 87 |
-
"cons": [
|
| 88 |
-
"Less interpretable than single decision tree",
|
| 89 |
-
"Can be slow for large datasets",
|
| 90 |
-
"Memory intensive",
|
| 91 |
-
"May overfit with very noisy data"
|
| 92 |
-
],
|
| 93 |
-
"best_for": "General purpose, robust performance, feature importance"
|
| 94 |
-
},
|
| 95 |
-
|
| 96 |
-
"Support Vector Machine (SVM)": {
|
| 97 |
-
"pros": [
|
| 98 |
-
"Effective in high-dimensional spaces",
|
| 99 |
-
"Memory efficient",
|
| 100 |
-
"Works well with small datasets",
|
| 101 |
-
"Robust to outliers",
|
| 102 |
-
"Good generalization performance"
|
| 103 |
-
],
|
| 104 |
-
"cons": [
|
| 105 |
-
"Slow training on large datasets",
|
| 106 |
-
"Sensitive to feature scaling",
|
| 107 |
-
"Black box model (hard to interpret)",
|
| 108 |
-
"Memory intensive for large datasets",
|
| 109 |
-
"Sensitive to kernel choice"
|
| 110 |
-
],
|
| 111 |
-
"best_for": "High-dimensional data, small datasets, good generalization"
|
| 112 |
-
},
|
| 113 |
-
|
| 114 |
-
"Logistic Regression": {
|
| 115 |
-
"pros": [
|
| 116 |
-
"Fast training and prediction",
|
| 117 |
-
"Interpretable (coefficients have meaning)",
|
| 118 |
-
"Probabilistic output",
|
| 119 |
-
"Memory efficient",
|
| 120 |
-
"Works well with small datasets"
|
| 121 |
-
],
|
| 122 |
-
"cons": [
|
| 123 |
-
"Assumes linear relationship",
|
| 124 |
-
"Sensitive to outliers",
|
| 125 |
-
"Requires feature scaling",
|
| 126 |
-
"May not work well with non-linear patterns"
|
| 127 |
-
],
|
| 128 |
-
"best_for": "Linear relationships, interpretability, fast inference"
|
| 129 |
-
}
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
for name, info in classifiers.items():
|
| 133 |
-
print(f"🤖 {name}:")
|
| 134 |
-
print(f" ✅ Pros: {', '.join(info['pros'][:3])}...")
|
| 135 |
-
print(f" ❌ Cons: {', '.join(info['cons'][:3])}...")
|
| 136 |
-
print(f" 🎯 Best for: {info['best_for']}")
|
| 137 |
-
print()
|
| 138 |
-
|
| 139 |
-
def recommend_classifier():
|
| 140 |
-
"""Recommend the best classifier for your specific case"""
|
| 141 |
-
|
| 142 |
-
print("💡 Recommendations for Your Face Recognition Task:")
|
| 143 |
-
print()
|
| 144 |
-
|
| 145 |
-
print("🎯 Your Specific Situation:")
|
| 146 |
-
print(" - Small dataset (33 samples)")
|
| 147 |
-
print(" - Imbalanced classes (15, 11, 7)")
|
| 148 |
-
print(" - High-dimensional features (5 from Siamese network)")
|
| 149 |
-
print(" - Need fast inference for web deployment")
|
| 150 |
-
print(" - Person3 has poor performance (0% precision/recall)")
|
| 151 |
-
print()
|
| 152 |
-
|
| 153 |
-
print("🏆 Top Recommendations:")
|
| 154 |
-
print()
|
| 155 |
-
|
| 156 |
-
print("1. 🥇 Random Forest (RECOMMENDED):")
|
| 157 |
-
print(" ✅ Handles imbalanced data well")
|
| 158 |
-
print(" ✅ Robust to outliers")
|
| 159 |
-
print(" ✅ Good performance on small datasets")
|
| 160 |
-
print(" ✅ Fast prediction")
|
| 161 |
-
print(" ✅ Provides feature importance")
|
| 162 |
-
print(" ✅ Less prone to overfitting than single decision tree")
|
| 163 |
-
print()
|
| 164 |
-
|
| 165 |
-
print("2. 🥈 Decision Tree:")
|
| 166 |
-
print(" ✅ Fast training and prediction")
|
| 167 |
-
print(" ✅ Easy to interpret")
|
| 168 |
-
print(" ✅ Good for small datasets")
|
| 169 |
-
print(" ⚠️ May overfit with small data")
|
| 170 |
-
print(" ⚠️ Less robust than Random Forest")
|
| 171 |
-
print()
|
| 172 |
-
|
| 173 |
-
print("3. 🥉 SVM:")
|
| 174 |
-
print(" ✅ Good for high-dimensional data")
|
| 175 |
-
print(" ✅ Works well with small datasets")
|
| 176 |
-
print(" ✅ Robust to outliers")
|
| 177 |
-
print(" ⚠️ Slower training")
|
| 178 |
-
print(" ⚠️ Requires careful parameter tuning")
|
| 179 |
-
print()
|
| 180 |
-
|
| 181 |
-
print("❌ Not Recommended:")
|
| 182 |
-
print(" - Logistic Regression: Assumes linear relationships")
|
| 183 |
-
print(" - KNN: Current issues with Person3 performance")
|
| 184 |
-
print()
|
| 185 |
-
|
| 186 |
-
def provide_implementation_guide():
|
| 187 |
-
"""Provide implementation guide for recommended classifier"""
|
| 188 |
-
|
| 189 |
-
print("🔧 Implementation Guide for Random Forest:")
|
| 190 |
-
print()
|
| 191 |
-
|
| 192 |
-
code_example = '''
|
| 193 |
-
# Random Forest Implementation
|
| 194 |
-
from sklearn.ensemble import RandomForestClassifier
|
| 195 |
-
from sklearn.model_selection import train_test_split
|
| 196 |
-
from sklearn.metrics import classification_report
|
| 197 |
-
|
| 198 |
-
# Create Random Forest classifier
|
| 199 |
-
rf_classifier = RandomForestClassifier(
|
| 200 |
-
n_estimators=100, # Number of trees
|
| 201 |
-
max_depth=10, # Maximum depth of trees
|
| 202 |
-
min_samples_split=2, # Minimum samples to split
|
| 203 |
-
min_samples_leaf=1, # Minimum samples in leaf
|
| 204 |
-
class_weight='balanced', # Handle imbalanced data
|
| 205 |
-
random_state=42
|
| 206 |
-
)
|
| 207 |
-
|
| 208 |
-
# Train the classifier
|
| 209 |
-
rf_classifier.fit(X_scaled, y)
|
| 210 |
-
|
| 211 |
-
# Make predictions
|
| 212 |
-
y_pred_rf = rf_classifier.predict(X_test_scaled)
|
| 213 |
-
|
| 214 |
-
# Evaluate performance
|
| 215 |
-
rf_accuracy = accuracy_score(y_test, y_pred_rf)
|
| 216 |
-
print(f"Random Forest Accuracy: {rf_accuracy*100:.2f}%")
|
| 217 |
-
print(classification_report(y_test, y_pred_rf))
|
| 218 |
-
|
| 219 |
-
# Save the model
|
| 220 |
-
joblib.dump(rf_classifier, 'random_forest_model.sav')
|
| 221 |
-
'''
|
| 222 |
-
|
| 223 |
-
print("📝 Code Example:")
|
| 224 |
-
print(code_example)
|
| 225 |
-
|
| 226 |
-
print("🎯 Key Parameters:")
|
| 227 |
-
print(" - n_estimators: Number of trees (100-200)")
|
| 228 |
-
print(" - max_depth: Prevent overfitting (5-15)")
|
| 229 |
-
print(" - class_weight='balanced': Handle imbalanced data")
|
| 230 |
-
print(" - min_samples_split: Minimum samples to split (2-5)")
|
| 231 |
-
print()
|
| 232 |
-
|
| 233 |
-
def data_improvement_suggestions():
|
| 234 |
-
"""Suggestions for improving training data"""
|
| 235 |
-
|
| 236 |
-
print("📊 Data Improvement Suggestions:")
|
| 237 |
-
print()
|
| 238 |
-
|
| 239 |
-
print("1. 🎯 Balance Your Dataset:")
|
| 240 |
-
print(" - Current: Person1(15), Person2(11), Person3(7)")
|
| 241 |
-
print(" - Target: 15-20 samples per person")
|
| 242 |
-
print(" - Add more Person3 images (currently only 7)")
|
| 243 |
-
print()
|
| 244 |
-
|
| 245 |
-
print("2. 📸 Improve Image Quality:")
|
| 246 |
-
print(" - Clear frontal faces")
|
| 247 |
-
print(" - Good lighting and contrast")
|
| 248 |
-
print(" - Consistent image size")
|
| 249 |
-
print(" - Remove blurry or low-quality images")
|
| 250 |
-
print()
|
| 251 |
-
|
| 252 |
-
print("3. 🔄 Data Augmentation:")
|
| 253 |
-
print(" - Rotate images slightly (±5 degrees)")
|
| 254 |
-
print(" - Adjust brightness/contrast")
|
| 255 |
-
print(" - Add slight noise")
|
| 256 |
-
print(" - Crop different regions")
|
| 257 |
-
print()
|
| 258 |
-
|
| 259 |
-
print("4. 🎨 Diversity:")
|
| 260 |
-
print(" - Different expressions")
|
| 261 |
-
print(" - Various lighting conditions")
|
| 262 |
-
print(" - Different angles (slight variations)")
|
| 263 |
-
print(" - Different backgrounds")
|
| 264 |
-
print()
|
| 265 |
-
|
| 266 |
-
if __name__ == "__main__":
|
| 267 |
-
analyze_current_knn()
|
| 268 |
-
compare_classifiers()
|
| 269 |
-
recommend_classifier()
|
| 270 |
-
provide_implementation_guide()
|
| 271 |
-
data_improvement_suggestions()
|
| 272 |
-
|
| 273 |
-
print("🎯 Final Recommendation:")
|
| 274 |
-
print("Switch to Random Forest for better performance with imbalanced data")
|
| 275 |
-
print("Focus on improving Person3 training data")
|
| 276 |
-
print("Consider data augmentation to increase dataset size")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/create_workaround_models.py
DELETED
|
@@ -1,66 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Create a simple workaround for Hugging Face sklearn compatibility
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import numpy as np
|
| 7 |
-
import joblib
|
| 8 |
-
import pickle
|
| 9 |
-
|
| 10 |
-
def create_workaround_models():
|
| 11 |
-
"""Create workaround models that should work on Hugging Face"""
|
| 12 |
-
print("Creating workaround models for Hugging Face...")
|
| 13 |
-
|
| 14 |
-
try:
|
| 15 |
-
# Load original models
|
| 16 |
-
original_classifier = joblib.load('decision_tree_model.sav')
|
| 17 |
-
original_scaler = joblib.load('face_recognition_scaler.sav')
|
| 18 |
-
|
| 19 |
-
print(f"Original classifier: {type(original_classifier)}")
|
| 20 |
-
print(f"Original scaler: {type(original_scaler)}")
|
| 21 |
-
|
| 22 |
-
# Create a simple pickle version that should work
|
| 23 |
-
with open('decision_tree_model.pkl', 'wb') as f:
|
| 24 |
-
pickle.dump(original_classifier, f)
|
| 25 |
-
|
| 26 |
-
with open('face_recognition_scaler.pkl', 'wb') as f:
|
| 27 |
-
pickle.dump(original_scaler, f)
|
| 28 |
-
|
| 29 |
-
print("✅ Created pickle versions:")
|
| 30 |
-
print(" - decision_tree_model.pkl")
|
| 31 |
-
print(" - face_recognition_scaler.pkl")
|
| 32 |
-
|
| 33 |
-
# Test loading
|
| 34 |
-
with open('decision_tree_model.pkl', 'rb') as f:
|
| 35 |
-
test_classifier = pickle.load(f)
|
| 36 |
-
|
| 37 |
-
with open('face_recognition_scaler.pkl', 'rb') as f:
|
| 38 |
-
test_scaler = pickle.load(f)
|
| 39 |
-
|
| 40 |
-
print(f"✅ Test classifier: {type(test_classifier)}")
|
| 41 |
-
print(f"✅ Test scaler: {type(test_scaler)}")
|
| 42 |
-
|
| 43 |
-
# Test prediction
|
| 44 |
-
dummy_features = np.random.randn(1, test_scaler.n_features_in_)
|
| 45 |
-
scaled_features = test_scaler.transform(dummy_features)
|
| 46 |
-
prediction = test_classifier.predict(scaled_features)[0]
|
| 47 |
-
|
| 48 |
-
print(f"✅ Test prediction: {prediction}")
|
| 49 |
-
|
| 50 |
-
return True
|
| 51 |
-
|
| 52 |
-
except Exception as e:
|
| 53 |
-
print(f"❌ Error: {e}")
|
| 54 |
-
import traceback
|
| 55 |
-
traceback.print_exc()
|
| 56 |
-
return False
|
| 57 |
-
|
| 58 |
-
if __name__ == "__main__":
|
| 59 |
-
success = create_workaround_models()
|
| 60 |
-
if success:
|
| 61 |
-
print("\n🎉 Workaround models created successfully!")
|
| 62 |
-
print("Use these files for Hugging Face:")
|
| 63 |
-
print("- decision_tree_model.pkl")
|
| 64 |
-
print("- face_recognition_scaler.pkl")
|
| 65 |
-
else:
|
| 66 |
-
print("\n❌ Failed to create workaround models")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/debug_classification.py
DELETED
|
@@ -1,130 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Debug script to understand why classification returns UNKNOWN_CLASS
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import numpy as np
|
| 6 |
-
import cv2
|
| 7 |
-
from face_recognition import get_face_class
|
| 8 |
-
import torch
|
| 9 |
-
import joblib
|
| 10 |
-
|
| 11 |
-
def debug_classification():
|
| 12 |
-
"""Debug the classification process step by step"""
|
| 13 |
-
print("Debugging Face Classification")
|
| 14 |
-
print("=" * 40)
|
| 15 |
-
|
| 16 |
-
# Create a test image
|
| 17 |
-
test_img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 18 |
-
|
| 19 |
-
try:
|
| 20 |
-
# Test the classification
|
| 21 |
-
result = get_face_class(test_img)
|
| 22 |
-
print(f"Classification result: {result}")
|
| 23 |
-
|
| 24 |
-
# Let's also check what the model files contain
|
| 25 |
-
print("\nChecking model files...")
|
| 26 |
-
|
| 27 |
-
# Check scaler
|
| 28 |
-
try:
|
| 29 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 30 |
-
print(f"Scaler loaded successfully: {type(scaler)}")
|
| 31 |
-
print(f"Scaler mean shape: {scaler.mean_.shape if hasattr(scaler, 'mean_') else 'No mean'}")
|
| 32 |
-
except Exception as e:
|
| 33 |
-
print(f"Scaler error: {e}")
|
| 34 |
-
|
| 35 |
-
# Check classifier
|
| 36 |
-
try:
|
| 37 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 38 |
-
print(f"Classifier loaded successfully: {type(classifier)}")
|
| 39 |
-
print(f"Classifier classes: {classifier.classes_ if hasattr(classifier, 'classes_') else 'No classes'}")
|
| 40 |
-
print(f"Number of classes: {len(classifier.classes_) if hasattr(classifier, 'classes_') else 'Unknown'}")
|
| 41 |
-
except Exception as e:
|
| 42 |
-
print(f"Classifier error: {e}")
|
| 43 |
-
|
| 44 |
-
# Check CLASS_NAMES
|
| 45 |
-
from face_recognition import CLASS_NAMES
|
| 46 |
-
print(f"CLASS_NAMES: {CLASS_NAMES}")
|
| 47 |
-
print(f"Number of class names: {len(CLASS_NAMES)}")
|
| 48 |
-
|
| 49 |
-
# Test with a more realistic face-like image
|
| 50 |
-
print("\nTesting with face-like image...")
|
| 51 |
-
face_img = create_face_like_image()
|
| 52 |
-
face_result = get_face_class(face_img)
|
| 53 |
-
print(f"Face-like image result: {face_result}")
|
| 54 |
-
|
| 55 |
-
except Exception as e:
|
| 56 |
-
print(f"Error in debug: {e}")
|
| 57 |
-
import traceback
|
| 58 |
-
traceback.print_exc()
|
| 59 |
-
|
| 60 |
-
def create_face_like_image():
|
| 61 |
-
"""Create a more realistic face-like image"""
|
| 62 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 63 |
-
|
| 64 |
-
# Face outline (oval)
|
| 65 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (100, 100, 100), -1)
|
| 66 |
-
|
| 67 |
-
# Eyes
|
| 68 |
-
cv2.circle(img, (35, 40), 5, (200, 200, 200), -1)
|
| 69 |
-
cv2.circle(img, (65, 40), 5, (200, 200, 200), -1)
|
| 70 |
-
|
| 71 |
-
# Nose
|
| 72 |
-
cv2.line(img, (50, 45), (50, 60), (150, 150, 150), 2)
|
| 73 |
-
|
| 74 |
-
# Mouth
|
| 75 |
-
cv2.ellipse(img, (50, 70), (15, 8), 0, 0, 180, (150, 150, 150), 2)
|
| 76 |
-
|
| 77 |
-
return img
|
| 78 |
-
|
| 79 |
-
def test_embedding_extraction():
|
| 80 |
-
"""Test the embedding extraction process"""
|
| 81 |
-
print("\nTesting embedding extraction...")
|
| 82 |
-
print("=" * 40)
|
| 83 |
-
|
| 84 |
-
try:
|
| 85 |
-
from face_recognition import detected_face
|
| 86 |
-
from face_recognition_model import Siamese, trnscm
|
| 87 |
-
import torch
|
| 88 |
-
|
| 89 |
-
# Create test image
|
| 90 |
-
test_img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 91 |
-
|
| 92 |
-
# Test face detection
|
| 93 |
-
detected = detected_face(test_img)
|
| 94 |
-
print(f"Face detection result: {type(detected)}")
|
| 95 |
-
|
| 96 |
-
if detected != 0:
|
| 97 |
-
# Test transformation
|
| 98 |
-
face_tensor = trnscm(detected).unsqueeze(0)
|
| 99 |
-
print(f"Face tensor shape: {face_tensor.shape}")
|
| 100 |
-
|
| 101 |
-
# Test model loading and embedding
|
| 102 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 103 |
-
siamese_net = Siamese().to(device)
|
| 104 |
-
|
| 105 |
-
# Load model
|
| 106 |
-
model_data = torch.load('siamese_model.t7', map_location=device)
|
| 107 |
-
if isinstance(model_data, dict) and 'net_dict' in model_data:
|
| 108 |
-
siamese_net.load_state_dict(model_data['net_dict'])
|
| 109 |
-
else:
|
| 110 |
-
siamese_net.load_state_dict(model_data)
|
| 111 |
-
|
| 112 |
-
siamese_net.eval()
|
| 113 |
-
|
| 114 |
-
# Extract embedding
|
| 115 |
-
with torch.no_grad():
|
| 116 |
-
embedding = siamese_net.forward_once(face_tensor.to(device)).cpu().numpy()
|
| 117 |
-
print(f"Embedding shape: {embedding.shape}")
|
| 118 |
-
print(f"Embedding sample: {embedding[0][:5]}") # First 5 values
|
| 119 |
-
|
| 120 |
-
else:
|
| 121 |
-
print("No face detected in test image")
|
| 122 |
-
|
| 123 |
-
except Exception as e:
|
| 124 |
-
print(f"Error in embedding extraction: {e}")
|
| 125 |
-
import traceback
|
| 126 |
-
traceback.print_exc()
|
| 127 |
-
|
| 128 |
-
if __name__ == "__main__":
|
| 129 |
-
debug_classification()
|
| 130 |
-
test_embedding_extraction()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/deep_debug_classification.py
DELETED
|
@@ -1,174 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Deep debugging script to find why UNKNOWN_CLASS still occurs
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
import cv2
|
| 9 |
-
from PIL import Image
|
| 10 |
-
import traceback
|
| 11 |
-
|
| 12 |
-
# Add current directory to path
|
| 13 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 14 |
-
|
| 15 |
-
def deep_debug_classification():
|
| 16 |
-
"""Deep debug the classification process step by step"""
|
| 17 |
-
print("Deep Debug: Face Classification Process")
|
| 18 |
-
print("=" * 50)
|
| 19 |
-
|
| 20 |
-
try:
|
| 21 |
-
# Step 1: Check model files
|
| 22 |
-
print("1. Checking model files...")
|
| 23 |
-
model_files = {
|
| 24 |
-
'siamese_model.t7': 'Siamese network',
|
| 25 |
-
'decision_tree_model.sav': 'DecisionTree classifier',
|
| 26 |
-
'face_recognition_scaler.sav': 'Feature scaler'
|
| 27 |
-
}
|
| 28 |
-
|
| 29 |
-
for file, desc in model_files.items():
|
| 30 |
-
if os.path.exists(file):
|
| 31 |
-
size = os.path.getsize(file)
|
| 32 |
-
print(f" ✓ {file} exists ({size} bytes) - {desc}")
|
| 33 |
-
else:
|
| 34 |
-
print(f" ✗ {file} missing - {desc}")
|
| 35 |
-
|
| 36 |
-
# Step 2: Check classifier classes
|
| 37 |
-
print("\n2. Checking classifier classes...")
|
| 38 |
-
try:
|
| 39 |
-
import joblib
|
| 40 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 41 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 42 |
-
|
| 43 |
-
print(f" Classifier classes: {classifier.classes_}")
|
| 44 |
-
print(f" Number of classes: {len(classifier.classes_)}")
|
| 45 |
-
print(f" Class range: {min(classifier.classes_)} to {max(classifier.classes_)}")
|
| 46 |
-
print(f" Scaler features: {scaler.n_features_in_}")
|
| 47 |
-
|
| 48 |
-
except Exception as e:
|
| 49 |
-
print(f" ✗ Error loading models: {e}")
|
| 50 |
-
return
|
| 51 |
-
|
| 52 |
-
# Step 3: Check CLASS_NAMES
|
| 53 |
-
print("\n3. Checking CLASS_NAMES...")
|
| 54 |
-
try:
|
| 55 |
-
from face_recognition import CLASS_NAMES
|
| 56 |
-
print(f" CLASS_NAMES: {CLASS_NAMES}")
|
| 57 |
-
print(f" Number of CLASS_NAMES: {len(CLASS_NAMES)}")
|
| 58 |
-
|
| 59 |
-
# Check if CLASS_NAMES length matches classifier classes
|
| 60 |
-
if len(CLASS_NAMES) == len(classifier.classes_):
|
| 61 |
-
print(" ✓ CLASS_NAMES length matches classifier classes")
|
| 62 |
-
else:
|
| 63 |
-
print(f" ✗ Length mismatch: CLASS_NAMES={len(CLASS_NAMES)}, classifier={len(classifier.classes_)}")
|
| 64 |
-
|
| 65 |
-
except Exception as e:
|
| 66 |
-
print(f" ✗ Error checking CLASS_NAMES: {e}")
|
| 67 |
-
|
| 68 |
-
# Step 4: Test with actual image
|
| 69 |
-
print("\n4. Testing with actual Person1 image...")
|
| 70 |
-
actual_image_path = "../static/Person1_1697805233.jpg"
|
| 71 |
-
if os.path.exists(actual_image_path):
|
| 72 |
-
print(f" ✓ Found actual image: {actual_image_path}")
|
| 73 |
-
|
| 74 |
-
try:
|
| 75 |
-
# Load image
|
| 76 |
-
img = cv2.imread(actual_image_path)
|
| 77 |
-
print(f" Image shape: {img.shape}")
|
| 78 |
-
|
| 79 |
-
# Test face detection
|
| 80 |
-
from face_recognition import detected_face
|
| 81 |
-
detected = detected_face(img)
|
| 82 |
-
print(f" Face detected: {type(detected)}")
|
| 83 |
-
|
| 84 |
-
# Test full classification
|
| 85 |
-
from face_recognition import get_face_class
|
| 86 |
-
result = get_face_class(img)
|
| 87 |
-
print(f" Classification result: {result}")
|
| 88 |
-
|
| 89 |
-
# Debug the classification process step by step
|
| 90 |
-
print("\n5. Step-by-step classification debug...")
|
| 91 |
-
debug_classification_step_by_step(img)
|
| 92 |
-
|
| 93 |
-
except Exception as e:
|
| 94 |
-
print(f" ✗ Error with actual image: {e}")
|
| 95 |
-
traceback.print_exc()
|
| 96 |
-
else:
|
| 97 |
-
print(f" ✗ No actual image found at {actual_image_path}")
|
| 98 |
-
|
| 99 |
-
except Exception as e:
|
| 100 |
-
print(f"✗ Error in deep debug: {e}")
|
| 101 |
-
traceback.print_exc()
|
| 102 |
-
|
| 103 |
-
def debug_classification_step_by_step(img):
|
| 104 |
-
"""Debug the classification process step by step"""
|
| 105 |
-
try:
|
| 106 |
-
import torch
|
| 107 |
-
from face_recognition import detected_face, trnscm, CLASS_NAMES
|
| 108 |
-
from face_recognition_model import Siamese
|
| 109 |
-
|
| 110 |
-
print(" Step 1: Face detection...")
|
| 111 |
-
det_img = detected_face(img)
|
| 112 |
-
if det_img == 0:
|
| 113 |
-
det_img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))
|
| 114 |
-
print(f" Detected face type: {type(det_img)}")
|
| 115 |
-
|
| 116 |
-
print(" Step 2: Image transformation...")
|
| 117 |
-
face_tensor = trnscm(det_img).unsqueeze(0)
|
| 118 |
-
print(f" Tensor shape: {face_tensor.shape}")
|
| 119 |
-
|
| 120 |
-
print(" Step 3: Siamese network...")
|
| 121 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 122 |
-
siamese_net = Siamese().to(device)
|
| 123 |
-
|
| 124 |
-
# Load model
|
| 125 |
-
model_data = torch.load('siamese_model.t7', map_location=device)
|
| 126 |
-
if isinstance(model_data, dict) and 'net_dict' in model_data:
|
| 127 |
-
siamese_net.load_state_dict(model_data['net_dict'])
|
| 128 |
-
else:
|
| 129 |
-
siamese_net.load_state_dict(model_data)
|
| 130 |
-
siamese_net.eval()
|
| 131 |
-
|
| 132 |
-
print(" Step 4: Feature extraction...")
|
| 133 |
-
with torch.no_grad():
|
| 134 |
-
embedding = siamese_net.forward_once(face_tensor.to(device)).cpu().numpy()
|
| 135 |
-
print(f" Embedding shape: {embedding.shape}")
|
| 136 |
-
print(f" Embedding values: {embedding}")
|
| 137 |
-
|
| 138 |
-
print(" Step 5: Classification...")
|
| 139 |
-
import joblib
|
| 140 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 141 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 142 |
-
|
| 143 |
-
# Reshape embedding if needed
|
| 144 |
-
if embedding.ndim == 1:
|
| 145 |
-
embedding = embedding.reshape(1, -1)
|
| 146 |
-
|
| 147 |
-
print(f" Embedding after reshape: {embedding.shape}")
|
| 148 |
-
|
| 149 |
-
# Scale features
|
| 150 |
-
embedding_scaled = scaler.transform(embedding)
|
| 151 |
-
print(f" Scaled embedding: {embedding_scaled}")
|
| 152 |
-
|
| 153 |
-
# Predict
|
| 154 |
-
predicted_label_index = classifier.predict(embedding_scaled)[0]
|
| 155 |
-
print(f" Predicted index: {predicted_label_index}")
|
| 156 |
-
print(f" Classifier classes: {classifier.classes_}")
|
| 157 |
-
|
| 158 |
-
# Map to class name
|
| 159 |
-
print(f" CLASS_NAMES: {CLASS_NAMES}")
|
| 160 |
-
print(f" CLASS_NAMES length: {len(CLASS_NAMES)}")
|
| 161 |
-
|
| 162 |
-
if predicted_label_index < len(CLASS_NAMES):
|
| 163 |
-
class_name = CLASS_NAMES[predicted_label_index]
|
| 164 |
-
print(f" ✓ Mapped to: {class_name}")
|
| 165 |
-
else:
|
| 166 |
-
print(f" ✗ Index {predicted_label_index} is out of range!")
|
| 167 |
-
print(f" ✗ This causes UNKNOWN_CLASS!")
|
| 168 |
-
|
| 169 |
-
except Exception as e:
|
| 170 |
-
print(f" ✗ Error in step-by-step debug: {e}")
|
| 171 |
-
traceback.print_exc()
|
| 172 |
-
|
| 173 |
-
if __name__ == "__main__":
|
| 174 |
-
deep_debug_classification()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/deploy_fix.py
DELETED
|
@@ -1,117 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Deployment fix for Hugging Face Space sklearn compatibility issue
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import shutil
|
| 7 |
-
|
| 8 |
-
def create_deployment_package():
|
| 9 |
-
"""Create a complete deployment package"""
|
| 10 |
-
print("Creating Hugging Face Space Deployment Package")
|
| 11 |
-
print("=" * 60)
|
| 12 |
-
|
| 13 |
-
# Files to deploy
|
| 14 |
-
files_to_deploy = [
|
| 15 |
-
'face_recognition_robust.py', # Robust implementation
|
| 16 |
-
'face_recognition_model.py', # Model definition
|
| 17 |
-
'app_robust.py', # Robust Gradio app
|
| 18 |
-
'requirements.txt', # Dependencies
|
| 19 |
-
'README.md', # Documentation
|
| 20 |
-
'siamese_model.t7', # Trained model
|
| 21 |
-
'decision_tree_model.sav', # Classifier
|
| 22 |
-
'face_recognition_scaler.sav' # Scaler
|
| 23 |
-
]
|
| 24 |
-
|
| 25 |
-
# Optional files
|
| 26 |
-
optional_files = [
|
| 27 |
-
'haarcascade_frontalface_default.xml',
|
| 28 |
-
'haarcascade_eye.xml'
|
| 29 |
-
]
|
| 30 |
-
|
| 31 |
-
print("Files to deploy:")
|
| 32 |
-
for file in files_to_deploy:
|
| 33 |
-
if os.path.exists(file):
|
| 34 |
-
size = os.path.getsize(file) / (1024 * 1024)
|
| 35 |
-
print(f"✓ {file} ({size:.2f} MB)")
|
| 36 |
-
else:
|
| 37 |
-
print(f"✗ {file} - MISSING!")
|
| 38 |
-
|
| 39 |
-
print("\nOptional files:")
|
| 40 |
-
for file in optional_files:
|
| 41 |
-
if os.path.exists(file):
|
| 42 |
-
print(f"✓ {file}")
|
| 43 |
-
else:
|
| 44 |
-
print(f"- {file} - Not found")
|
| 45 |
-
|
| 46 |
-
print("\n" + "=" * 60)
|
| 47 |
-
print("DEPLOYMENT STEPS:")
|
| 48 |
-
print("=" * 60)
|
| 49 |
-
print("1. Go to: https://huggingface.co/spaces/pavaniyerra/hackthon4")
|
| 50 |
-
print("2. Click 'Files and versions' tab")
|
| 51 |
-
print("3. Upload these files (replace existing):")
|
| 52 |
-
print(" - app_robust.py → rename to app.py")
|
| 53 |
-
print(" - face_recognition_robust.py → rename to face_recognition.py")
|
| 54 |
-
print(" - requirements.txt")
|
| 55 |
-
print(" - README.md")
|
| 56 |
-
print(" - All model files (.t7, .sav)")
|
| 57 |
-
print("4. Wait for rebuild (2-5 minutes)")
|
| 58 |
-
|
| 59 |
-
print("\n" + "=" * 60)
|
| 60 |
-
print("KEY FIXES IN THIS DEPLOYMENT:")
|
| 61 |
-
print("=" * 60)
|
| 62 |
-
print("✓ Robust sklearn compatibility handling")
|
| 63 |
-
print("✓ Fallback cosine similarity calculation")
|
| 64 |
-
print("✓ Safe model loading with multiple methods")
|
| 65 |
-
print("✓ Better error handling and user feedback")
|
| 66 |
-
print("✓ Improved Gradio interface")
|
| 67 |
-
print("✓ Comprehensive documentation")
|
| 68 |
-
|
| 69 |
-
print("\n" + "=" * 60)
|
| 70 |
-
print("TROUBLESHOOTING:")
|
| 71 |
-
print("=" * 60)
|
| 72 |
-
print("If you still get errors:")
|
| 73 |
-
print("1. Check build logs in Hugging Face Space")
|
| 74 |
-
print("2. Ensure all model files are uploaded")
|
| 75 |
-
print("3. Verify requirements.txt is correct")
|
| 76 |
-
print("4. Try rebuilding the space")
|
| 77 |
-
print("5. Check file permissions and paths")
|
| 78 |
-
|
| 79 |
-
def create_requirements_robust():
|
| 80 |
-
"""Create a robust requirements.txt"""
|
| 81 |
-
requirements = """torch>=1.9.0
|
| 82 |
-
torchvision>=0.10.0
|
| 83 |
-
opencv-python>=4.5.0
|
| 84 |
-
numpy>=1.21.0
|
| 85 |
-
scikit-learn>=1.0.0,<2.0.0
|
| 86 |
-
matplotlib>=3.3.0
|
| 87 |
-
Pillow>=8.0.0
|
| 88 |
-
joblib>=1.0.0
|
| 89 |
-
requests>=2.25.0
|
| 90 |
-
gradio>=4.0.0
|
| 91 |
-
"""
|
| 92 |
-
|
| 93 |
-
with open('requirements_robust.txt', 'w') as f:
|
| 94 |
-
f.write(requirements)
|
| 95 |
-
|
| 96 |
-
print("Created requirements_robust.txt with flexible sklearn version")
|
| 97 |
-
|
| 98 |
-
def main():
|
| 99 |
-
print("Hugging Face Space Fix Deployment")
|
| 100 |
-
print("=" * 50)
|
| 101 |
-
|
| 102 |
-
# Check if we're in the right directory
|
| 103 |
-
if not os.path.exists('face_recognition.py'):
|
| 104 |
-
print("ERROR: Please run this from the Hackathon_setup directory")
|
| 105 |
-
return
|
| 106 |
-
|
| 107 |
-
create_deployment_package()
|
| 108 |
-
create_requirements_robust()
|
| 109 |
-
|
| 110 |
-
print("\n" + "=" * 60)
|
| 111 |
-
print("READY TO DEPLOY!")
|
| 112 |
-
print("=" * 60)
|
| 113 |
-
print("This deployment should fix the sklearn compatibility issue.")
|
| 114 |
-
print("The robust implementation will work even if sklearn versions don't match.")
|
| 115 |
-
|
| 116 |
-
if __name__ == "__main__":
|
| 117 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/deploy_to_huggingface.py
DELETED
|
@@ -1,117 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Script to help deploy the face recognition system to Hugging Face Spaces
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import shutil
|
| 7 |
-
|
| 8 |
-
def create_deployment_files():
|
| 9 |
-
"""Create all necessary files for Hugging Face deployment"""
|
| 10 |
-
print("Creating deployment files for Hugging Face Space...")
|
| 11 |
-
print("=" * 60)
|
| 12 |
-
|
| 13 |
-
# Files needed for deployment
|
| 14 |
-
files_to_copy = [
|
| 15 |
-
'face_recognition.py',
|
| 16 |
-
'face_recognition_model.py',
|
| 17 |
-
'siamese_model.t7',
|
| 18 |
-
'decision_tree_model.sav',
|
| 19 |
-
'face_recognition_scaler.sav',
|
| 20 |
-
'requirements.txt',
|
| 21 |
-
'app.py',
|
| 22 |
-
'README.md'
|
| 23 |
-
]
|
| 24 |
-
|
| 25 |
-
# Optional files (if they exist)
|
| 26 |
-
optional_files = [
|
| 27 |
-
'haarcascade_frontalface_default.xml',
|
| 28 |
-
'haarcascade_eye.xml'
|
| 29 |
-
]
|
| 30 |
-
|
| 31 |
-
print("Required files:")
|
| 32 |
-
for file in files_to_copy:
|
| 33 |
-
if os.path.exists(file):
|
| 34 |
-
print(f"OK: {file}")
|
| 35 |
-
else:
|
| 36 |
-
print(f"ERROR: {file} - MISSING!")
|
| 37 |
-
|
| 38 |
-
print("\nOptional files:")
|
| 39 |
-
for file in optional_files:
|
| 40 |
-
if os.path.exists(file):
|
| 41 |
-
print(f"OK: {file}")
|
| 42 |
-
else:
|
| 43 |
-
print(f"- {file} - Not found (optional)")
|
| 44 |
-
|
| 45 |
-
print("\n" + "=" * 60)
|
| 46 |
-
print("DEPLOYMENT INSTRUCTIONS:")
|
| 47 |
-
print("=" * 60)
|
| 48 |
-
print("1. Go to your Hugging Face Space: https://huggingface.co/spaces/pavaniyerra/hackthon4")
|
| 49 |
-
print("2. Click on 'Files and versions' tab")
|
| 50 |
-
print("3. Upload the following files:")
|
| 51 |
-
|
| 52 |
-
for file in files_to_copy:
|
| 53 |
-
if os.path.exists(file):
|
| 54 |
-
print(f" - {file}")
|
| 55 |
-
|
| 56 |
-
print("\n4. Make sure to replace any existing files with the same names")
|
| 57 |
-
print("5. The space will automatically rebuild with the new files")
|
| 58 |
-
print("6. Wait for the build to complete (usually 2-5 minutes)")
|
| 59 |
-
|
| 60 |
-
print("\n" + "=" * 60)
|
| 61 |
-
print("KEY CHANGES FOR DEPLOYMENT:")
|
| 62 |
-
print("=" * 60)
|
| 63 |
-
print("OK: Fixed sklearn version compatibility (1.6.1)")
|
| 64 |
-
print("OK: Added warning suppression")
|
| 65 |
-
print("OK: Created proper Gradio interface")
|
| 66 |
-
print("OK: Added requirements.txt with correct versions")
|
| 67 |
-
print("OK: Updated README.md with documentation")
|
| 68 |
-
|
| 69 |
-
print("\n" + "=" * 60)
|
| 70 |
-
print("TROUBLESHOOTING:")
|
| 71 |
-
print("=" * 60)
|
| 72 |
-
print("If you still get sklearn errors:")
|
| 73 |
-
print("1. Check that requirements.txt specifies scikit-learn==1.6.1")
|
| 74 |
-
print("2. Ensure all model files are uploaded")
|
| 75 |
-
print("3. Check the build logs for any missing dependencies")
|
| 76 |
-
print("4. Try rebuilding the space")
|
| 77 |
-
|
| 78 |
-
def check_file_sizes():
|
| 79 |
-
"""Check file sizes to ensure they're within limits"""
|
| 80 |
-
print("\nChecking file sizes...")
|
| 81 |
-
print("=" * 30)
|
| 82 |
-
|
| 83 |
-
large_files = []
|
| 84 |
-
for file in os.listdir('.'):
|
| 85 |
-
if os.path.isfile(file) and file.endswith(('.t7', '.sav', '.pkl')):
|
| 86 |
-
size_mb = os.path.getsize(file) / (1024 * 1024)
|
| 87 |
-
print(f"{file}: {size_mb:.2f} MB")
|
| 88 |
-
if size_mb > 100: # Hugging Face has limits
|
| 89 |
-
large_files.append(file)
|
| 90 |
-
|
| 91 |
-
if large_files:
|
| 92 |
-
print(f"\nWARNING: Large files detected: {large_files}")
|
| 93 |
-
print("Hugging Face Spaces have file size limits. Consider:")
|
| 94 |
-
print("1. Using Git LFS for large files")
|
| 95 |
-
print("2. Compressing model files")
|
| 96 |
-
print("3. Using external storage for very large models")
|
| 97 |
-
|
| 98 |
-
def main():
|
| 99 |
-
print("Hugging Face Space Deployment Helper")
|
| 100 |
-
print("=" * 50)
|
| 101 |
-
|
| 102 |
-
# Check current directory
|
| 103 |
-
if not os.path.exists('face_recognition.py'):
|
| 104 |
-
print("ERROR: Please run this script from the Hackathon_setup directory")
|
| 105 |
-
return
|
| 106 |
-
|
| 107 |
-
create_deployment_files()
|
| 108 |
-
check_file_sizes()
|
| 109 |
-
|
| 110 |
-
print("\n" + "=" * 60)
|
| 111 |
-
print("READY FOR DEPLOYMENT!")
|
| 112 |
-
print("=" * 60)
|
| 113 |
-
print("Your files are ready to be uploaded to Hugging Face Space.")
|
| 114 |
-
print("Follow the instructions above to complete the deployment.")
|
| 115 |
-
|
| 116 |
-
if __name__ == "__main__":
|
| 117 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/diagnose_errors.py
DELETED
|
@@ -1,167 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Diagnostic script to identify common issues with face recognition setup
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import sys
|
| 6 |
-
import os
|
| 7 |
-
import traceback
|
| 8 |
-
|
| 9 |
-
def check_python_version():
|
| 10 |
-
"""Check Python version"""
|
| 11 |
-
print("Python Version Check")
|
| 12 |
-
print("=" * 20)
|
| 13 |
-
print(f"Python version: {sys.version}")
|
| 14 |
-
if sys.version_info < (3, 6):
|
| 15 |
-
print("WARNING: Python 3.6+ recommended")
|
| 16 |
-
else:
|
| 17 |
-
print("OK: Python version is compatible")
|
| 18 |
-
|
| 19 |
-
def check_packages():
|
| 20 |
-
"""Check if required packages are installed"""
|
| 21 |
-
print("\nPackage Installation Check")
|
| 22 |
-
print("=" * 30)
|
| 23 |
-
|
| 24 |
-
packages = [
|
| 25 |
-
('numpy', 'numpy'),
|
| 26 |
-
('cv2', 'cv2'),
|
| 27 |
-
('torch', 'torch'),
|
| 28 |
-
('sklearn', 'sklearn'),
|
| 29 |
-
('PIL', 'PIL'),
|
| 30 |
-
('matplotlib', 'matplotlib'),
|
| 31 |
-
('joblib', 'joblib')
|
| 32 |
-
]
|
| 33 |
-
|
| 34 |
-
missing_packages = []
|
| 35 |
-
|
| 36 |
-
for package_name, import_name in packages:
|
| 37 |
-
try:
|
| 38 |
-
__import__(import_name)
|
| 39 |
-
print(f"OK: {package_name}")
|
| 40 |
-
except ImportError:
|
| 41 |
-
print(f"ERROR: {package_name} - MISSING")
|
| 42 |
-
missing_packages.append(package_name)
|
| 43 |
-
|
| 44 |
-
if missing_packages:
|
| 45 |
-
print(f"\nWARNING: Missing packages: {', '.join(missing_packages)}")
|
| 46 |
-
print("Install with: pip install " + " ".join(missing_packages))
|
| 47 |
-
return False
|
| 48 |
-
else:
|
| 49 |
-
print("\nOK: All required packages are installed")
|
| 50 |
-
return True
|
| 51 |
-
|
| 52 |
-
def check_files():
|
| 53 |
-
"""Check if required files exist"""
|
| 54 |
-
print("\nFile Structure Check")
|
| 55 |
-
print("=" * 25)
|
| 56 |
-
|
| 57 |
-
required_files = [
|
| 58 |
-
'face_recognition.py',
|
| 59 |
-
'face_recognition_model.py',
|
| 60 |
-
'test_cosine_similarity.py'
|
| 61 |
-
]
|
| 62 |
-
|
| 63 |
-
model_files = [
|
| 64 |
-
'siamese_model.t7',
|
| 65 |
-
'decision_tree_model.sav',
|
| 66 |
-
'face_recognition_scaler.sav'
|
| 67 |
-
]
|
| 68 |
-
|
| 69 |
-
missing_files = []
|
| 70 |
-
|
| 71 |
-
print("Required Python files:")
|
| 72 |
-
for file in required_files:
|
| 73 |
-
if os.path.exists(file):
|
| 74 |
-
print(f"OK: {file}")
|
| 75 |
-
else:
|
| 76 |
-
print(f"ERROR: {file} - MISSING")
|
| 77 |
-
missing_files.append(file)
|
| 78 |
-
|
| 79 |
-
print("\nModel files (need to be trained):")
|
| 80 |
-
for file in model_files:
|
| 81 |
-
if os.path.exists(file):
|
| 82 |
-
print(f"OK: {file}")
|
| 83 |
-
else:
|
| 84 |
-
print(f"ERROR: {file} - MISSING (needs training)")
|
| 85 |
-
missing_files.append(file)
|
| 86 |
-
|
| 87 |
-
return len(missing_files) == 0
|
| 88 |
-
|
| 89 |
-
def test_imports():
|
| 90 |
-
"""Test importing the face recognition module"""
|
| 91 |
-
print("\nImport Test")
|
| 92 |
-
print("=" * 15)
|
| 93 |
-
|
| 94 |
-
try:
|
| 95 |
-
# Add current directory to path
|
| 96 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 97 |
-
sys.path.insert(0, current_dir)
|
| 98 |
-
|
| 99 |
-
from face_recognition import get_similarity, get_face_class
|
| 100 |
-
print("OK: Successfully imported face_recognition functions")
|
| 101 |
-
return True
|
| 102 |
-
except Exception as e:
|
| 103 |
-
print(f"ERROR: Failed to import face_recognition: {e}")
|
| 104 |
-
print("Full error:")
|
| 105 |
-
traceback.print_exc()
|
| 106 |
-
return False
|
| 107 |
-
|
| 108 |
-
def test_basic_functionality():
|
| 109 |
-
"""Test basic functionality without model files"""
|
| 110 |
-
print("\nBasic Functionality Test")
|
| 111 |
-
print("=" * 30)
|
| 112 |
-
|
| 113 |
-
try:
|
| 114 |
-
import numpy as np
|
| 115 |
-
from face_recognition import detected_face
|
| 116 |
-
|
| 117 |
-
# Create a test image
|
| 118 |
-
test_img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 119 |
-
|
| 120 |
-
# Test face detection
|
| 121 |
-
result = detected_face(test_img)
|
| 122 |
-
print("OK: detected_face function works")
|
| 123 |
-
|
| 124 |
-
return True
|
| 125 |
-
except Exception as e:
|
| 126 |
-
print(f"ERROR: Basic functionality test failed: {e}")
|
| 127 |
-
traceback.print_exc()
|
| 128 |
-
return False
|
| 129 |
-
|
| 130 |
-
def main():
|
| 131 |
-
"""Run all diagnostic checks"""
|
| 132 |
-
print("Face Recognition System Diagnostic")
|
| 133 |
-
print("=" * 40)
|
| 134 |
-
|
| 135 |
-
checks = [
|
| 136 |
-
check_python_version,
|
| 137 |
-
check_packages,
|
| 138 |
-
check_files,
|
| 139 |
-
test_imports,
|
| 140 |
-
test_basic_functionality
|
| 141 |
-
]
|
| 142 |
-
|
| 143 |
-
results = []
|
| 144 |
-
for check in checks:
|
| 145 |
-
try:
|
| 146 |
-
result = check()
|
| 147 |
-
results.append(result)
|
| 148 |
-
except Exception as e:
|
| 149 |
-
print(f"ERROR: Check failed with error: {e}")
|
| 150 |
-
results.append(False)
|
| 151 |
-
|
| 152 |
-
print("\n" + "=" * 40)
|
| 153 |
-
print("DIAGNOSTIC SUMMARY")
|
| 154 |
-
print("=" * 40)
|
| 155 |
-
|
| 156 |
-
if all(results):
|
| 157 |
-
print("SUCCESS: All checks passed! Your setup looks good.")
|
| 158 |
-
print("You can now run the test script.")
|
| 159 |
-
else:
|
| 160 |
-
print("ERROR: Some checks failed. Please fix the issues above.")
|
| 161 |
-
print("\nCommon solutions:")
|
| 162 |
-
print("1. Install missing packages: pip install numpy opencv-python torch scikit-learn matplotlib joblib")
|
| 163 |
-
print("2. Make sure all Python files are in the same directory")
|
| 164 |
-
print("3. Train your models first before testing similarity")
|
| 165 |
-
|
| 166 |
-
if __name__ == "__main__":
|
| 167 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/diagnose_models.py
DELETED
|
@@ -1,132 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Diagnostic script to check model loading and compatibility
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
|
| 9 |
-
# Add current directory to path
|
| 10 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 11 |
-
|
| 12 |
-
def diagnose_models():
|
| 13 |
-
"""Diagnose model loading and compatibility issues"""
|
| 14 |
-
print("Model Loading Diagnosis")
|
| 15 |
-
print("=" * 40)
|
| 16 |
-
|
| 17 |
-
# Check if model files exist
|
| 18 |
-
model_files = [
|
| 19 |
-
'siamese_model.t7',
|
| 20 |
-
'decision_tree_model.sav',
|
| 21 |
-
'face_recognition_scaler.sav'
|
| 22 |
-
]
|
| 23 |
-
|
| 24 |
-
print("Checking model files:")
|
| 25 |
-
for file in model_files:
|
| 26 |
-
if os.path.exists(file):
|
| 27 |
-
size = os.path.getsize(file)
|
| 28 |
-
print(f" ✓ {file} exists ({size} bytes)")
|
| 29 |
-
else:
|
| 30 |
-
print(f" ✗ {file} missing!")
|
| 31 |
-
|
| 32 |
-
# Test model loading
|
| 33 |
-
print("\nTesting model loading:")
|
| 34 |
-
|
| 35 |
-
try:
|
| 36 |
-
import joblib
|
| 37 |
-
print(" ✓ joblib imported successfully")
|
| 38 |
-
|
| 39 |
-
# Load classifier
|
| 40 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 41 |
-
print(f" ✓ Classifier loaded: {type(classifier)}")
|
| 42 |
-
print(f" Classes: {classifier.classes_}")
|
| 43 |
-
print(f" Number of classes: {len(classifier.classes_)}")
|
| 44 |
-
|
| 45 |
-
# Load scaler
|
| 46 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 47 |
-
print(f" ✓ Scaler loaded: {type(scaler)}")
|
| 48 |
-
print(f" Feature count: {scaler.n_features_in_}")
|
| 49 |
-
|
| 50 |
-
# Test compatibility
|
| 51 |
-
dummy_features = np.random.randn(1, scaler.n_features_in_)
|
| 52 |
-
scaled_features = scaler.transform(dummy_features)
|
| 53 |
-
prediction = classifier.predict(scaled_features)[0]
|
| 54 |
-
|
| 55 |
-
print(f" ✓ Test prediction: {prediction}")
|
| 56 |
-
print(f" Prediction valid: {prediction in classifier.classes_}")
|
| 57 |
-
|
| 58 |
-
except Exception as e:
|
| 59 |
-
print(f" ✗ Error loading models: {e}")
|
| 60 |
-
import traceback
|
| 61 |
-
traceback.print_exc()
|
| 62 |
-
|
| 63 |
-
# Test Siamese network
|
| 64 |
-
print("\nTesting Siamese network:")
|
| 65 |
-
try:
|
| 66 |
-
import torch
|
| 67 |
-
print(" ✓ torch imported successfully")
|
| 68 |
-
|
| 69 |
-
from face_recognition_model import Siamese
|
| 70 |
-
|
| 71 |
-
# Create model instance
|
| 72 |
-
model = Siamese()
|
| 73 |
-
print(f" ✓ Siamese model created: {type(model)}")
|
| 74 |
-
|
| 75 |
-
# Test forward pass
|
| 76 |
-
dummy_input = torch.randn(1, 1, 100, 100)
|
| 77 |
-
with torch.no_grad():
|
| 78 |
-
output = model.forward_once(dummy_input)
|
| 79 |
-
print(f" ✓ Forward pass successful")
|
| 80 |
-
print(f" Output shape: {output.shape}")
|
| 81 |
-
print(f" Expected features: 5, Got: {output.shape[1]}")
|
| 82 |
-
|
| 83 |
-
if output.shape[1] == 5:
|
| 84 |
-
print(" ✓ Feature count matches scaler expectations")
|
| 85 |
-
else:
|
| 86 |
-
print(" ✗ Feature count mismatch!")
|
| 87 |
-
|
| 88 |
-
# Test model loading
|
| 89 |
-
if os.path.exists('siamese_model.t7'):
|
| 90 |
-
model_data = torch.load('siamese_model.t7', map_location='cpu')
|
| 91 |
-
print(f" ✓ Model file loaded: {type(model_data)}")
|
| 92 |
-
|
| 93 |
-
if isinstance(model_data, dict):
|
| 94 |
-
print(f" Keys: {list(model_data.keys())}")
|
| 95 |
-
else:
|
| 96 |
-
print(" Model data is state dict")
|
| 97 |
-
|
| 98 |
-
except Exception as e:
|
| 99 |
-
print(f" ✗ Error with Siamese network: {e}")
|
| 100 |
-
import traceback
|
| 101 |
-
traceback.print_exc()
|
| 102 |
-
|
| 103 |
-
# Test face recognition function
|
| 104 |
-
print("\nTesting face recognition function:")
|
| 105 |
-
try:
|
| 106 |
-
from face_recognition import get_face_class, CLASS_NAMES
|
| 107 |
-
|
| 108 |
-
print(f" ✓ Face recognition imported")
|
| 109 |
-
print(f" CLASS_NAMES: {CLASS_NAMES}")
|
| 110 |
-
print(f" Number of classes: {len(CLASS_NAMES)}")
|
| 111 |
-
|
| 112 |
-
# Create test image
|
| 113 |
-
test_img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 114 |
-
|
| 115 |
-
# Test classification
|
| 116 |
-
result = get_face_class(test_img)
|
| 117 |
-
print(f" ✓ Test classification: {result}")
|
| 118 |
-
|
| 119 |
-
if result in CLASS_NAMES:
|
| 120 |
-
print(" ✓ Result is a valid class name")
|
| 121 |
-
elif result == "UNKNOWN_CLASS":
|
| 122 |
-
print(" ✗ UNKNOWN_CLASS detected - this is the problem!")
|
| 123 |
-
else:
|
| 124 |
-
print(f" ? Unexpected result: {result}")
|
| 125 |
-
|
| 126 |
-
except Exception as e:
|
| 127 |
-
print(f" ✗ Error with face recognition: {e}")
|
| 128 |
-
import traceback
|
| 129 |
-
traceback.print_exc()
|
| 130 |
-
|
| 131 |
-
if __name__ == "__main__":
|
| 132 |
-
diagnose_models()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/face_recognition.py
CHANGED
|
@@ -47,17 +47,9 @@ CLASS_NAMES = ['Person1', 'Person2', 'Person3'] # Updated to match training data
|
|
| 47 |
|
| 48 |
# --- Model Filenames ---
|
| 49 |
SIAMESE_MODEL_PATH = current_path + '/siamese_model.t7'
|
| 50 |
-
|
| 51 |
SCALER_PATH = current_path + '/decision_scaler.sav'
|
| 52 |
|
| 53 |
-
# Compatible model paths for Hugging Face
|
| 54 |
-
KNN_CLASSIFIER_COMPATIBLE_PATH = current_path + '/decision_tree_model.sav'
|
| 55 |
-
SCALER_COMPATIBLE_PATH = current_path + '/decision_scaler.sav'
|
| 56 |
-
|
| 57 |
-
# Pickle model paths (most compatible)
|
| 58 |
-
KNN_CLASSIFIER_PKL_PATH = current_path + '/decision_tree_model.pkl'
|
| 59 |
-
SCALER_PKL_PATH = current_path + '/face_recognition_scaler.pkl'
|
| 60 |
-
|
| 61 |
def safe_cosine_similarity(embed1, embed2):
|
| 62 |
"""Calculate cosine similarity with fallback methods"""
|
| 63 |
if SKLEARN_AVAILABLE:
|
|
@@ -96,7 +88,18 @@ def safe_load_model(file_path, model_type="joblib"):
|
|
| 96 |
|
| 97 |
try:
|
| 98 |
if model_type == "joblib":
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
elif model_type == "pickle":
|
| 101 |
with open(file_path, 'rb') as f:
|
| 102 |
return pickle.load(f)
|
|
@@ -250,62 +253,42 @@ def get_face_class(img1):
|
|
| 250 |
scaler = None
|
| 251 |
classifier = None
|
| 252 |
|
| 253 |
-
#
|
| 254 |
try:
|
| 255 |
scaler = safe_load_model(SCALER_PATH, "joblib")
|
| 256 |
-
classifier = safe_load_model(
|
| 257 |
-
print("✓ Loaded
|
| 258 |
except Exception as e:
|
| 259 |
-
print(f"Failed to load
|
| 260 |
-
|
| 261 |
-
# Try pickle models (most compatible)
|
| 262 |
-
try:
|
| 263 |
-
if os.path.exists(SCALER_PKL_PATH) and os.path.exists(KNN_CLASSIFIER_PKL_PATH):
|
| 264 |
-
import pickle
|
| 265 |
-
with open(SCALER_PKL_PATH, 'rb') as f:
|
| 266 |
-
scaler = pickle.load(f)
|
| 267 |
-
with open(KNN_CLASSIFIER_PKL_PATH, 'rb') as f:
|
| 268 |
-
classifier = pickle.load(f)
|
| 269 |
-
print("✓ Loaded pickle models successfully")
|
| 270 |
-
else:
|
| 271 |
-
print("Pickle models not found, trying compatible models")
|
| 272 |
-
|
| 273 |
-
# Try compatible models
|
| 274 |
-
if os.path.exists(SCALER_COMPATIBLE_PATH) and os.path.exists(KNN_CLASSIFIER_COMPATIBLE_PATH):
|
| 275 |
-
scaler = safe_load_model(SCALER_COMPATIBLE_PATH, "joblib")
|
| 276 |
-
classifier = safe_load_model(KNN_CLASSIFIER_COMPATIBLE_PATH, "joblib")
|
| 277 |
-
print("✓ Loaded compatible models successfully")
|
| 278 |
-
else:
|
| 279 |
-
print("Compatible models not found, trying original with pickle")
|
| 280 |
-
|
| 281 |
-
# Try loading original models with pickle
|
| 282 |
-
try:
|
| 283 |
-
import pickle
|
| 284 |
-
with open(SCALER_PATH, 'rb') as f:
|
| 285 |
-
scaler = pickle.load(f)
|
| 286 |
-
with open(KNN_CLASSIFIER_PATH, 'rb') as f:
|
| 287 |
-
classifier = pickle.load(f)
|
| 288 |
-
print("✓ Loaded original models with pickle")
|
| 289 |
-
except Exception as e2:
|
| 290 |
-
print(f"All loading methods failed: {e2}")
|
| 291 |
-
return "UNKNOWN_CLASS"
|
| 292 |
-
|
| 293 |
-
except Exception as e2:
|
| 294 |
-
print(f"Failed to load compatible models: {e2}")
|
| 295 |
-
return "UNKNOWN_CLASS"
|
| 296 |
-
|
| 297 |
|
| 298 |
-
# --- CRITICAL VERIFICATION STEP ---
|
| 299 |
-
if not hasattr(classifier, 'predict'):
|
| 300 |
-
raise TypeError(f"Loaded object is not a valid classifier. Type is: {type(classifier)}")
|
| 301 |
-
|
| 302 |
if scaler is None or classifier is None:
|
| 303 |
print("Failed to load any sklearn models")
|
| 304 |
return "UNKNOWN_CLASS"
|
| 305 |
|
| 306 |
# Preprocess and predict
|
| 307 |
embedding_scaled = scaler.transform(embedding_np)
|
| 308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
|
| 310 |
# Map to class name
|
| 311 |
if predicted_label_index < len(CLASS_NAMES):
|
|
|
|
| 47 |
|
| 48 |
# --- Model Filenames ---
|
| 49 |
SIAMESE_MODEL_PATH = current_path + '/siamese_model.t7'
|
| 50 |
+
DECISION_TREE_MODEL_PATH = current_path + '/decision_tree_model.sav'
|
| 51 |
SCALER_PATH = current_path + '/decision_scaler.sav'
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
def safe_cosine_similarity(embed1, embed2):
|
| 54 |
"""Calculate cosine similarity with fallback methods"""
|
| 55 |
if SKLEARN_AVAILABLE:
|
|
|
|
| 88 |
|
| 89 |
try:
|
| 90 |
if model_type == "joblib":
|
| 91 |
+
model = joblib.load(file_path)
|
| 92 |
+
# Additional validation for Decision Tree models
|
| 93 |
+
if hasattr(model, 'predict'):
|
| 94 |
+
# Test if the model can make predictions
|
| 95 |
+
import numpy as np
|
| 96 |
+
dummy_data = np.random.randn(1, 5) # Test with dummy data
|
| 97 |
+
try:
|
| 98 |
+
_ = model.predict(dummy_data)
|
| 99 |
+
print(f"✓ Model {file_path} loaded and validated successfully")
|
| 100 |
+
except Exception as test_error:
|
| 101 |
+
print(f"⚠️ Model loaded but prediction test failed: {test_error}")
|
| 102 |
+
return model
|
| 103 |
elif model_type == "pickle":
|
| 104 |
with open(file_path, 'rb') as f:
|
| 105 |
return pickle.load(f)
|
|
|
|
| 253 |
scaler = None
|
| 254 |
classifier = None
|
| 255 |
|
| 256 |
+
# Load models
|
| 257 |
try:
|
| 258 |
scaler = safe_load_model(SCALER_PATH, "joblib")
|
| 259 |
+
classifier = safe_load_model(DECISION_TREE_MODEL_PATH, "joblib")
|
| 260 |
+
print("✓ Loaded models successfully")
|
| 261 |
except Exception as e:
|
| 262 |
+
print(f"Failed to load models: {e}")
|
| 263 |
+
return "UNKNOWN_CLASS"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
if scaler is None or classifier is None:
|
| 266 |
print("Failed to load any sklearn models")
|
| 267 |
return "UNKNOWN_CLASS"
|
| 268 |
|
| 269 |
# Preprocess and predict
|
| 270 |
embedding_scaled = scaler.transform(embedding_np)
|
| 271 |
+
|
| 272 |
+
# Fix for Decision Tree predict method - ensure proper input format
|
| 273 |
+
try:
|
| 274 |
+
# Ensure the input is in the correct format for Decision Tree
|
| 275 |
+
if hasattr(classifier, 'predict'):
|
| 276 |
+
# For Decision Tree, make sure input is 2D array
|
| 277 |
+
if embedding_scaled.ndim == 1:
|
| 278 |
+
embedding_scaled = embedding_scaled.reshape(1, -1)
|
| 279 |
+
predicted_label_index = classifier.predict(embedding_scaled)[0]
|
| 280 |
+
else:
|
| 281 |
+
print("Classifier doesn't have predict method")
|
| 282 |
+
return "UNKNOWN_CLASS"
|
| 283 |
+
except Exception as predict_error:
|
| 284 |
+
print(f"Prediction error: {predict_error}")
|
| 285 |
+
# Try alternative prediction method
|
| 286 |
+
try:
|
| 287 |
+
# Try with explicit X parameter
|
| 288 |
+
predicted_label_index = classifier.predict(X=embedding_scaled)[0]
|
| 289 |
+
except Exception as e2:
|
| 290 |
+
print(f"Alternative prediction also failed: {e2}")
|
| 291 |
+
return "UNKNOWN_CLASS"
|
| 292 |
|
| 293 |
# Map to class name
|
| 294 |
if predicted_label_index < len(CLASS_NAMES):
|
app/Hackathon_setup/face_recognition_old.py
DELETED
|
@@ -1,213 +0,0 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
-
import cv2
|
| 3 |
-
from matplotlib import pyplot as plt
|
| 4 |
-
import torch
|
| 5 |
-
# In the below line,remove '.' while working on your local system. However Make sure that '.' is present before face_recognition_model while uploading to the server, Do not remove it.
|
| 6 |
-
try:
|
| 7 |
-
from .face_recognition_model import *
|
| 8 |
-
except ImportError:
|
| 9 |
-
# Fallback for when running as standalone script
|
| 10 |
-
from face_recognition_model import *
|
| 11 |
-
from PIL import Image
|
| 12 |
-
import base64
|
| 13 |
-
import io
|
| 14 |
-
import os
|
| 15 |
-
import joblib
|
| 16 |
-
import warnings
|
| 17 |
-
# Suppress sklearn version warnings
|
| 18 |
-
warnings.filterwarnings('ignore', category=UserWarning, module='sklearn')
|
| 19 |
-
warnings.filterwarnings('ignore', message='.*InconsistentVersionWarning.*')
|
| 20 |
-
|
| 21 |
-
import pickle
|
| 22 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
| 23 |
-
from sklearn.preprocessing import StandardScaler
|
| 24 |
-
# Add more imports if required
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
###########################################################################################################################################
|
| 29 |
-
# Caution: Don't change any of the filenames, function names and definitions #
|
| 30 |
-
# Always use the current_path + file_name for refering any files, without it we cannot access files on the server #
|
| 31 |
-
###########################################################################################################################################
|
| 32 |
-
|
| 33 |
-
# Current_path stores absolute path of the file from where it runs.
|
| 34 |
-
current_path = os.path.dirname(os.path.abspath(__file__))
|
| 35 |
-
# --- GLOBAL SETUP: Must match your training transforms ---
|
| 36 |
-
# Define the transformation pipeline for inference
|
| 37 |
-
trnscm = transforms.Compose([
|
| 38 |
-
transforms.Grayscale(num_output_channels=1),
|
| 39 |
-
transforms.Resize((100, 100)),
|
| 40 |
-
transforms.ToTensor()
|
| 41 |
-
])
|
| 42 |
-
CLASS_NAMES = ['Person0', 'Person1', 'Person2', 'Person3', 'Person4'] # ADJUST THIS!
|
| 43 |
-
|
| 44 |
-
# --- Model Filenames ---
|
| 45 |
-
SIAMESE_MODEL_PATH = current_path + '/siamese_model.t7'
|
| 46 |
-
KNN_CLASSIFIER_PATH = current_path + '/decision_tree_model.sav'
|
| 47 |
-
SCALER_PATH = current_path + '/face_recognition_scaler.sav'
|
| 48 |
-
|
| 49 |
-
#1) The below function is used to detect faces in the given image.
|
| 50 |
-
#2) It returns only one image which has maximum area out of all the detected faces in the photo.
|
| 51 |
-
#3) If no face is detected,then it returns zero(0).
|
| 52 |
-
|
| 53 |
-
def detected_face(image):
|
| 54 |
-
eye_haar = current_path + '/haarcascade_eye.xml'
|
| 55 |
-
face_haar = current_path + '/haarcascade_frontalface_default.xml'
|
| 56 |
-
face_cascade = cv2.CascadeClassifier(face_haar)
|
| 57 |
-
eye_cascade = cv2.CascadeClassifier(eye_haar)
|
| 58 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 59 |
-
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
| 60 |
-
face_areas=[]
|
| 61 |
-
images = []
|
| 62 |
-
required_image=0
|
| 63 |
-
for i, (x,y,w,h) in enumerate(faces):
|
| 64 |
-
face_cropped = gray[y:y+h, x:x+w]
|
| 65 |
-
face_areas.append(w*h)
|
| 66 |
-
images.append(face_cropped)
|
| 67 |
-
required_image = images[np.argmax(face_areas)]
|
| 68 |
-
required_image = Image.fromarray(required_image)
|
| 69 |
-
return required_image
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
#1) Images captured from mobile is passed as parameter to the below function in the API call. It returns the similarity measure between given images.
|
| 73 |
-
#2) The image is passed to the function in base64 encoding, Code for decoding the image is provided within the function.
|
| 74 |
-
#3) Define an object to your siamese network here in the function and load the weight from the trained network, set it in evaluation mode.
|
| 75 |
-
#4) Get the features for both the faces from the network and return the similarity measure, Euclidean,cosine etc can be it. But choose the Relevant measure.
|
| 76 |
-
#5) For loading your model use the current_path+'your model file name', anyhow detailed example is given in comments to the function
|
| 77 |
-
#Caution: Don't change the definition or function name; for loading the model use the current_path for path example is given in comments to the function
|
| 78 |
-
def get_similarity(img1, img2):
|
| 79 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 80 |
-
|
| 81 |
-
det_img1 = detected_face(img1)
|
| 82 |
-
det_img2 = detected_face(img2)
|
| 83 |
-
if(det_img1 == 0 or det_img2 == 0):
|
| 84 |
-
det_img1 = Image.fromarray(cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY))
|
| 85 |
-
det_img2 = Image.fromarray(cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY))
|
| 86 |
-
face1 = trnscm(det_img1).unsqueeze(0)
|
| 87 |
-
face2 = trnscm(det_img2).unsqueeze(0)
|
| 88 |
-
##########################################################################################
|
| 89 |
-
##Example for loading a model using weight state dictionary: ##
|
| 90 |
-
## feature_net = light_cnn() #Example Network ##
|
| 91 |
-
## model = torch.load(current_path + '/siamese_model.t7', map_location=device) ##
|
| 92 |
-
## feature_net.load_state_dict(model['net_dict']) ##
|
| 93 |
-
## ##
|
| 94 |
-
##current_path + '/<network_definition>' is path of the saved model if present in ##
|
| 95 |
-
##the same path as this file, we recommend to put in the same directory ##
|
| 96 |
-
##########################################################################################
|
| 97 |
-
##########################################################################################
|
| 98 |
-
|
| 99 |
-
# YOUR CODE HERE, load the model
|
| 100 |
-
|
| 101 |
-
# YOUR CODE HERE, return similarity measure using your model
|
| 102 |
-
# 1. Initialize and Load Siamese Network
|
| 103 |
-
try:
|
| 104 |
-
# Using the Siamese class from your model file
|
| 105 |
-
siamese_net = Siamese().to(device)
|
| 106 |
-
|
| 107 |
-
# Load the model - check if it has 'net_dict' key
|
| 108 |
-
model_data = torch.load(SIAMESE_MODEL_PATH, map_location=device)
|
| 109 |
-
if isinstance(model_data, dict) and 'net_dict' in model_data:
|
| 110 |
-
siamese_net.load_state_dict(model_data['net_dict'])
|
| 111 |
-
else:
|
| 112 |
-
siamese_net.load_state_dict(model_data)
|
| 113 |
-
|
| 114 |
-
siamese_net.eval()
|
| 115 |
-
except Exception as e:
|
| 116 |
-
print(f"Error loading Siamese Model get_similarity: {e}")
|
| 117 |
-
return -1 # Return error code
|
| 118 |
-
|
| 119 |
-
# 2. Get Features (Embeddings)
|
| 120 |
-
with torch.no_grad():
|
| 121 |
-
# Get the feature vector from one tower/forward_once method
|
| 122 |
-
# Ensure your SiameseNetwork class has a forward_once or get_embedding method
|
| 123 |
-
embed1 = siamese_net.forward_once(face1.to(device)).cpu().numpy()
|
| 124 |
-
embed2 = siamese_net.forward_once(face2.to(device)).cpu().numpy()
|
| 125 |
-
|
| 126 |
-
# 3. Calculate Similarity Measure
|
| 127 |
-
# The Euclidean distance is the fundamental metric used by the Triplet/Contrastive loss.
|
| 128 |
-
# We return the NEGATIVE Euclidean distance or COSINE similarity, as *higher* value usually means *more* similar.
|
| 129 |
-
|
| 130 |
-
# Option A: Euclidean Distance (Lower is better) -> return NEGATIVE distance for API expectation
|
| 131 |
-
# distance = euclidean_distances(embed1, embed2)[0][0]
|
| 132 |
-
# similarity = -distance
|
| 133 |
-
|
| 134 |
-
# Option B: Cosine Similarity (Higher is better) -> Recommended
|
| 135 |
-
try:
|
| 136 |
-
# Ensure embeddings are 2D arrays for sklearn cosine_similarity
|
| 137 |
-
if embed1.ndim == 1:
|
| 138 |
-
embed1 = embed1.reshape(1, -1)
|
| 139 |
-
if embed2.ndim == 1:
|
| 140 |
-
embed2 = embed2.reshape(1, -1)
|
| 141 |
-
|
| 142 |
-
similarity = cosine_similarity(embed1, embed2)[0][0]
|
| 143 |
-
|
| 144 |
-
# Clamp similarity to valid range [-1, 1] to handle numerical precision issues
|
| 145 |
-
similarity = np.clip(similarity, -1.0, 1.0)
|
| 146 |
-
|
| 147 |
-
except Exception as e:
|
| 148 |
-
print(f"Error calculating cosine similarity: {e}")
|
| 149 |
-
return -1.0 # Return error value
|
| 150 |
-
|
| 151 |
-
return float(similarity)
|
| 152 |
-
|
| 153 |
-
#1) Image captured from mobile is passed as parameter to this function in the API call, It returns the face class in the string form ex: "Person1"
|
| 154 |
-
#2) The image is passed to the function in base64 encoding, Code to decode the image provided within the function
|
| 155 |
-
#3) Define an object to your network here in the function and load the weight from the trained network, set it in evaluation mode
|
| 156 |
-
#4) Perform necessary transformations to the input(detected face using the above function).
|
| 157 |
-
#5) Along with the siamese, you need the classifier as well, which is to be finetuned with the faces that you are training
|
| 158 |
-
##Caution: Don't change the definition or function name; for loading the model use the current_path for path example is given in comments to the function
|
| 159 |
-
def get_face_class(img1):
|
| 160 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 161 |
-
|
| 162 |
-
det_img1 = detected_face(img1)
|
| 163 |
-
if(det_img1 == 0):
|
| 164 |
-
det_img1 = Image.fromarray(cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY))
|
| 165 |
-
##YOUR CODE HERE, return face class here
|
| 166 |
-
##Hint: you need a classifier finetuned for your classes, it takes o/p of siamese as i/p to it
|
| 167 |
-
##Better Hint: Siamese experiment is covered in one of the labs
|
| 168 |
-
face1_tensor = trnscm(det_img1).unsqueeze(0).to(device)
|
| 169 |
-
|
| 170 |
-
# 1. Load Siamese Network (Feature Extractor)
|
| 171 |
-
try:
|
| 172 |
-
siamese_net = Siamese().to(device)
|
| 173 |
-
|
| 174 |
-
# Load the model - check if it has 'net_dict' key
|
| 175 |
-
model_data = torch.load(SIAMESE_MODEL_PATH, map_location=device)
|
| 176 |
-
if isinstance(model_data, dict) and 'net_dict' in model_data:
|
| 177 |
-
siamese_net.load_state_dict(model_data['net_dict'])
|
| 178 |
-
else:
|
| 179 |
-
siamese_net.load_state_dict(model_data)
|
| 180 |
-
|
| 181 |
-
siamese_net.eval()
|
| 182 |
-
except Exception as e:
|
| 183 |
-
return f"Error loading Siamese Model get_face_class: {e}"
|
| 184 |
-
|
| 185 |
-
# 2. Extract Embedding
|
| 186 |
-
with torch.no_grad():
|
| 187 |
-
embedding_np = siamese_net.forward_once(face1_tensor).cpu().numpy()
|
| 188 |
-
|
| 189 |
-
# Ensure embedding is 2D for sklearn
|
| 190 |
-
if embedding_np.ndim == 1:
|
| 191 |
-
embedding_np = embedding_np.reshape(1, -1)
|
| 192 |
-
|
| 193 |
-
# 3. Load Sklearn Scaler and Classifier (Joblib)
|
| 194 |
-
try:
|
| 195 |
-
knn_classifier = joblib.load(KNN_CLASSIFIER_PATH)
|
| 196 |
-
scaler = joblib.load(SCALER_PATH)
|
| 197 |
-
except Exception as e:
|
| 198 |
-
return f"Error loading Sklearn models: {e}"
|
| 199 |
-
|
| 200 |
-
# 4. Preprocess Embedding and Predict
|
| 201 |
-
# The embedding must be reshaped to (1, N_features) for the scaler
|
| 202 |
-
embedding_scaled = scaler.transform(embedding_np.reshape(1, -1))
|
| 203 |
-
|
| 204 |
-
# Perform prediction (returns a NumPy array with the predicted label index)
|
| 205 |
-
predicted_label_index = knn_classifier.predict(embedding_scaled)[0]
|
| 206 |
-
|
| 207 |
-
# 5. Map index to Class Name
|
| 208 |
-
if predicted_label_index < len(CLASS_NAMES):
|
| 209 |
-
predicted_class_name = CLASS_NAMES[predicted_label_index]
|
| 210 |
-
else:
|
| 211 |
-
predicted_class_name = "UNKNOWN_CLASS"
|
| 212 |
-
|
| 213 |
-
return predicted_class_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/fix_class_labels.py
DELETED
|
@@ -1,138 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Diagnostic script to check classifier classes and fix label mismatch
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
|
| 9 |
-
# Add current directory to path
|
| 10 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 11 |
-
|
| 12 |
-
def diagnose_classifier_classes():
|
| 13 |
-
"""Check what classes the classifier actually expects"""
|
| 14 |
-
print("Classifier Classes Diagnosis")
|
| 15 |
-
print("=" * 40)
|
| 16 |
-
|
| 17 |
-
try:
|
| 18 |
-
import joblib
|
| 19 |
-
|
| 20 |
-
# Load classifier
|
| 21 |
-
classifier_path = 'decision_tree_model.sav'
|
| 22 |
-
if os.path.exists(classifier_path):
|
| 23 |
-
classifier = joblib.load(classifier_path)
|
| 24 |
-
|
| 25 |
-
print(f"✓ Classifier loaded successfully")
|
| 26 |
-
print(f" Classes: {classifier.classes_}")
|
| 27 |
-
print(f" Number of classes: {len(classifier.classes_)}")
|
| 28 |
-
print(f" Class range: {min(classifier.classes_)} to {max(classifier.classes_)}")
|
| 29 |
-
|
| 30 |
-
# Check if classes start from 0 or 1
|
| 31 |
-
if min(classifier.classes_) == 0:
|
| 32 |
-
print(" ✓ Classes start from 0 (Person0, Person1, ...)")
|
| 33 |
-
expected_names = ['Person0', 'Person1', 'Person2', 'Person3', 'Person4', 'Person5', 'Person6']
|
| 34 |
-
elif min(classifier.classes_) == 1:
|
| 35 |
-
print(" ✓ Classes start from 1 (Person1, Person2, ...)")
|
| 36 |
-
expected_names = ['Person1', 'Person2', 'Person3', 'Person4', 'Person5', 'Person6', 'Person7']
|
| 37 |
-
else:
|
| 38 |
-
print(f" ? Classes start from {min(classifier.classes_)}")
|
| 39 |
-
expected_names = [f'Person{i}' for i in classifier.classes_]
|
| 40 |
-
|
| 41 |
-
print(f" Expected class names: {expected_names}")
|
| 42 |
-
|
| 43 |
-
# Check current CLASS_NAMES
|
| 44 |
-
try:
|
| 45 |
-
from face_recognition import CLASS_NAMES
|
| 46 |
-
print(f" Current CLASS_NAMES: {CLASS_NAMES}")
|
| 47 |
-
|
| 48 |
-
if CLASS_NAMES == expected_names:
|
| 49 |
-
print(" ✓ CLASS_NAMES match expected names")
|
| 50 |
-
else:
|
| 51 |
-
print(" ✗ CLASS_NAMES don't match expected names")
|
| 52 |
-
print(" This is likely the cause of UNKNOWN_CLASS!")
|
| 53 |
-
|
| 54 |
-
# Suggest fix
|
| 55 |
-
print(f"\n SUGGESTED FIX:")
|
| 56 |
-
print(f" Update CLASS_NAMES to: {expected_names}")
|
| 57 |
-
|
| 58 |
-
except Exception as e:
|
| 59 |
-
print(f" Error checking CLASS_NAMES: {e}")
|
| 60 |
-
|
| 61 |
-
else:
|
| 62 |
-
print(f"✗ Classifier file not found: {classifier_path}")
|
| 63 |
-
|
| 64 |
-
except Exception as e:
|
| 65 |
-
print(f"✗ Error: {e}")
|
| 66 |
-
import traceback
|
| 67 |
-
traceback.print_exc()
|
| 68 |
-
|
| 69 |
-
def fix_class_names():
|
| 70 |
-
"""Fix CLASS_NAMES to match the actual classifier classes"""
|
| 71 |
-
print("\nFixing CLASS_NAMES...")
|
| 72 |
-
|
| 73 |
-
try:
|
| 74 |
-
import joblib
|
| 75 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 76 |
-
|
| 77 |
-
# Determine correct class names based on classifier classes
|
| 78 |
-
if min(classifier.classes_) == 0:
|
| 79 |
-
# Classes 0-6 -> Person0-Person6
|
| 80 |
-
correct_names = ['Person0', 'Person1', 'Person2', 'Person3', 'Person4', 'Person5', 'Person6']
|
| 81 |
-
elif min(classifier.classes_) == 1:
|
| 82 |
-
# Classes 1-7 -> Person1-Person7
|
| 83 |
-
correct_names = ['Person1', 'Person2', 'Person3', 'Person4', 'Person5', 'Person6', 'Person7']
|
| 84 |
-
else:
|
| 85 |
-
# Custom mapping
|
| 86 |
-
correct_names = [f'Person{i}' for i in classifier.classes_]
|
| 87 |
-
|
| 88 |
-
print(f"Correct CLASS_NAMES should be: {correct_names}")
|
| 89 |
-
|
| 90 |
-
# Update face_recognition.py
|
| 91 |
-
face_recognition_path = 'face_recognition.py'
|
| 92 |
-
if os.path.exists(face_recognition_path):
|
| 93 |
-
with open(face_recognition_path, 'r') as f:
|
| 94 |
-
content = f.read()
|
| 95 |
-
|
| 96 |
-
# Find and replace CLASS_NAMES line
|
| 97 |
-
import re
|
| 98 |
-
pattern = r"CLASS_NAMES = \[.*?\]"
|
| 99 |
-
new_line = f"CLASS_NAMES = {correct_names}"
|
| 100 |
-
|
| 101 |
-
if re.search(pattern, content):
|
| 102 |
-
content = re.sub(pattern, new_line, content)
|
| 103 |
-
|
| 104 |
-
with open(face_recognition_path, 'w') as f:
|
| 105 |
-
f.write(content)
|
| 106 |
-
|
| 107 |
-
print(f"✓ Updated CLASS_NAMES in face_recognition.py")
|
| 108 |
-
else:
|
| 109 |
-
print("✗ Could not find CLASS_NAMES line to update")
|
| 110 |
-
|
| 111 |
-
# Update face_recognition_model.py
|
| 112 |
-
model_path = 'face_recognition_model.py'
|
| 113 |
-
if os.path.exists(model_path):
|
| 114 |
-
with open(model_path, 'r') as f:
|
| 115 |
-
content = f.read()
|
| 116 |
-
|
| 117 |
-
# Find and replace classes line
|
| 118 |
-
pattern = r"classes = \[.*?\]"
|
| 119 |
-
new_line = f"classes = {correct_names}"
|
| 120 |
-
|
| 121 |
-
if re.search(pattern, content):
|
| 122 |
-
content = re.sub(pattern, new_line, content)
|
| 123 |
-
|
| 124 |
-
with open(model_path, 'w') as f:
|
| 125 |
-
f.write(content)
|
| 126 |
-
|
| 127 |
-
print(f"✓ Updated classes in face_recognition_model.py")
|
| 128 |
-
else:
|
| 129 |
-
print("✗ Could not find classes line to update")
|
| 130 |
-
|
| 131 |
-
except Exception as e:
|
| 132 |
-
print(f"✗ Error fixing class names: {e}")
|
| 133 |
-
import traceback
|
| 134 |
-
traceback.print_exc()
|
| 135 |
-
|
| 136 |
-
if __name__ == "__main__":
|
| 137 |
-
diagnose_classifier_classes()
|
| 138 |
-
fix_class_names()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/fix_class_mapping.py
DELETED
|
@@ -1,180 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Analyze training data and fix class mapping based on actual training report
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
|
| 9 |
-
print("🔍 Training Data Analysis & Class Mapping Fix")
|
| 10 |
-
print("=" * 60)
|
| 11 |
-
|
| 12 |
-
def analyze_training_data():
|
| 13 |
-
"""Analyze the training data based on the report"""
|
| 14 |
-
|
| 15 |
-
print("Based on your training report:")
|
| 16 |
-
print("📊 Training Data Summary:")
|
| 17 |
-
print(" - Train samples: 26")
|
| 18 |
-
print(" - Test samples: 7")
|
| 19 |
-
print(" - Classes: 3 (0, 1, 2)")
|
| 20 |
-
print(" - Accuracy: 71.43%")
|
| 21 |
-
print()
|
| 22 |
-
|
| 23 |
-
print("📈 Classification Performance:")
|
| 24 |
-
print(" - Class 0: precision=0.60, recall=1.00, f1=0.75 (3 samples)")
|
| 25 |
-
print(" - Class 1: precision=1.00, recall=1.00, f1=1.00 (2 samples)")
|
| 26 |
-
print(" - Class 2: precision=0.00, recall=0.00, f1=0.00 (2 samples)")
|
| 27 |
-
print()
|
| 28 |
-
|
| 29 |
-
print("🔍 Issues Identified:")
|
| 30 |
-
print(" 1. Class 2 has poor performance (0% precision/recall)")
|
| 31 |
-
print(" 2. Only 3 classes trained, but CLASS_NAMES has 7 classes")
|
| 32 |
-
print(" 3. Small test set (7 samples) may not be representative")
|
| 33 |
-
print()
|
| 34 |
-
|
| 35 |
-
return True
|
| 36 |
-
|
| 37 |
-
def fix_class_mapping():
|
| 38 |
-
"""Fix the class mapping to match actual training data"""
|
| 39 |
-
|
| 40 |
-
print("🔧 Fixing Class Mapping...")
|
| 41 |
-
|
| 42 |
-
# Current incorrect mapping
|
| 43 |
-
current_names = ['Person1', 'Person2', 'Person3', 'Person4', 'Person5', 'Person6', 'Person7']
|
| 44 |
-
|
| 45 |
-
# Correct mapping based on training (3 classes)
|
| 46 |
-
correct_names = ['Person1', 'Person2', 'Person3']
|
| 47 |
-
|
| 48 |
-
print(f"Current CLASS_NAMES: {current_names}")
|
| 49 |
-
print(f"Correct CLASS_NAMES: {correct_names}")
|
| 50 |
-
print()
|
| 51 |
-
|
| 52 |
-
# Update face_recognition.py
|
| 53 |
-
try:
|
| 54 |
-
with open('face_recognition.py', 'r') as f:
|
| 55 |
-
content = f.read()
|
| 56 |
-
|
| 57 |
-
# Replace the CLASS_NAMES line
|
| 58 |
-
old_line = "CLASS_NAMES = ['Person1', 'Person2', 'Person3', 'Person4', 'Person5', 'Person6', 'Person7']"
|
| 59 |
-
new_line = "CLASS_NAMES = ['Person1', 'Person2', 'Person3']"
|
| 60 |
-
|
| 61 |
-
if old_line in content:
|
| 62 |
-
content = content.replace(old_line, new_line)
|
| 63 |
-
|
| 64 |
-
with open('face_recognition.py', 'w') as f:
|
| 65 |
-
f.write(content)
|
| 66 |
-
|
| 67 |
-
print("✅ Updated face_recognition.py CLASS_NAMES")
|
| 68 |
-
else:
|
| 69 |
-
print("⚠️ Could not find CLASS_NAMES line to update")
|
| 70 |
-
|
| 71 |
-
except Exception as e:
|
| 72 |
-
print(f"❌ Error updating face_recognition.py: {e}")
|
| 73 |
-
|
| 74 |
-
# Update face_recognition_model.py
|
| 75 |
-
try:
|
| 76 |
-
with open('face_recognition_model.py', 'r') as f:
|
| 77 |
-
content = f.read()
|
| 78 |
-
|
| 79 |
-
# Replace the classes line
|
| 80 |
-
old_line = "classes = ['Person1','Person2','Person3','Person4','Person5','Person6','Person7']"
|
| 81 |
-
new_line = "classes = ['Person1','Person2','Person3']"
|
| 82 |
-
|
| 83 |
-
if old_line in content:
|
| 84 |
-
content = content.replace(old_line, new_line)
|
| 85 |
-
|
| 86 |
-
with open('face_recognition_model.py', 'w') as f:
|
| 87 |
-
f.write(content)
|
| 88 |
-
|
| 89 |
-
print("✅ Updated face_recognition_model.py classes")
|
| 90 |
-
else:
|
| 91 |
-
print("⚠️ Could not find classes line to update")
|
| 92 |
-
|
| 93 |
-
except Exception as e:
|
| 94 |
-
print(f"❌ Error updating face_recognition_model.py: {e}")
|
| 95 |
-
|
| 96 |
-
def test_corrected_mapping():
|
| 97 |
-
"""Test the corrected class mapping"""
|
| 98 |
-
|
| 99 |
-
print("\n🧪 Testing Corrected Mapping...")
|
| 100 |
-
|
| 101 |
-
try:
|
| 102 |
-
from face_recognition import get_face_class, CLASS_NAMES
|
| 103 |
-
import joblib
|
| 104 |
-
|
| 105 |
-
print(f"Updated CLASS_NAMES: {CLASS_NAMES}")
|
| 106 |
-
print(f"Number of classes: {len(CLASS_NAMES)}")
|
| 107 |
-
|
| 108 |
-
# Load classifier to verify
|
| 109 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 110 |
-
print(f"Classifier classes: {classifier.classes_}")
|
| 111 |
-
|
| 112 |
-
if len(CLASS_NAMES) == len(classifier.classes_):
|
| 113 |
-
print("✅ Class mapping now matches classifier!")
|
| 114 |
-
else:
|
| 115 |
-
print("❌ Class mapping still doesn't match")
|
| 116 |
-
|
| 117 |
-
# Test with synthetic image
|
| 118 |
-
import cv2
|
| 119 |
-
test_img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 120 |
-
cv2.ellipse(test_img, (50, 50), (40, 50), 0, 0, 360, (100, 100, 100), -1)
|
| 121 |
-
cv2.circle(test_img, (35, 40), 5, (200, 200, 200), -1)
|
| 122 |
-
cv2.circle(test_img, (65, 40), 5, (200, 200, 200), -1)
|
| 123 |
-
|
| 124 |
-
result = get_face_class(test_img)
|
| 125 |
-
print(f"Test classification result: {result}")
|
| 126 |
-
|
| 127 |
-
if result in CLASS_NAMES:
|
| 128 |
-
print("✅ Classification working correctly!")
|
| 129 |
-
else:
|
| 130 |
-
print("❌ Classification still has issues")
|
| 131 |
-
|
| 132 |
-
except Exception as e:
|
| 133 |
-
print(f"❌ Error testing: {e}")
|
| 134 |
-
|
| 135 |
-
def provide_recommendations():
|
| 136 |
-
"""Provide recommendations for improving the model"""
|
| 137 |
-
|
| 138 |
-
print("\n💡 Recommendations for Better Performance:")
|
| 139 |
-
print()
|
| 140 |
-
print("1. 📊 Improve Class 2 Performance:")
|
| 141 |
-
print(" - Class 2 has 0% precision/recall")
|
| 142 |
-
print(" - Add more training samples for Person3")
|
| 143 |
-
print(" - Check if Person3 images are clear and diverse")
|
| 144 |
-
print()
|
| 145 |
-
|
| 146 |
-
print("2. 📈 Increase Training Data:")
|
| 147 |
-
print(" - Current: 26 train samples (very small)")
|
| 148 |
-
print(" - Recommended: 50-100+ samples per person")
|
| 149 |
-
print(" - Add more diverse images per person")
|
| 150 |
-
print()
|
| 151 |
-
|
| 152 |
-
print("3. 🎯 Improve Test Set:")
|
| 153 |
-
print(" - Current: 7 test samples (too small)")
|
| 154 |
-
print(" - Recommended: 20-30% of total data for testing")
|
| 155 |
-
print(" - Ensure balanced representation of all classes")
|
| 156 |
-
print()
|
| 157 |
-
|
| 158 |
-
print("4. 🔧 Model Improvements:")
|
| 159 |
-
print(" - Try different k values (k=3, k=7)")
|
| 160 |
-
print(" - Consider using DecisionTree instead of k-NN")
|
| 161 |
-
print(" - Add data augmentation for more training variety")
|
| 162 |
-
print()
|
| 163 |
-
|
| 164 |
-
print("5. 📝 Current Status:")
|
| 165 |
-
print(" - ✅ System working (no more UNKNOWN_CLASS)")
|
| 166 |
-
print(" - ✅ Class mapping fixed")
|
| 167 |
-
print(" - ⚠️ Model performance needs improvement")
|
| 168 |
-
print(" - ⚠️ Need more training data")
|
| 169 |
-
|
| 170 |
-
if __name__ == "__main__":
|
| 171 |
-
analyze_training_data()
|
| 172 |
-
fix_class_mapping()
|
| 173 |
-
test_corrected_mapping()
|
| 174 |
-
provide_recommendations()
|
| 175 |
-
|
| 176 |
-
print("\n🎉 Class mapping fix completed!")
|
| 177 |
-
print("Your face recognition will now work with the correct 3 classes:")
|
| 178 |
-
print("- Person1 (Class 0)")
|
| 179 |
-
print("- Person2 (Class 1)")
|
| 180 |
-
print("- Person3 (Class 2)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/fix_sklearn_advanced.py
DELETED
|
@@ -1,149 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Better fix for sklearn compatibility - properly copy all model attributes
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import numpy as np
|
| 7 |
-
import joblib
|
| 8 |
-
import pickle
|
| 9 |
-
from sklearn.neighbors import KNeighborsClassifier
|
| 10 |
-
from sklearn.preprocessing import StandardScaler
|
| 11 |
-
|
| 12 |
-
def create_properly_compatible_model():
|
| 13 |
-
"""Create a properly compatible model by copying all necessary attributes"""
|
| 14 |
-
print("Creating properly compatible sklearn models...")
|
| 15 |
-
|
| 16 |
-
try:
|
| 17 |
-
# Load original models
|
| 18 |
-
original_classifier = joblib.load('decision_tree_model.sav')
|
| 19 |
-
original_scaler = joblib.load('face_recognition_scaler.sav')
|
| 20 |
-
|
| 21 |
-
print(f"Original classifier: {type(original_classifier)}")
|
| 22 |
-
print(f"Original scaler: {type(original_scaler)}")
|
| 23 |
-
|
| 24 |
-
# Create new scaler and copy all attributes
|
| 25 |
-
new_scaler = StandardScaler()
|
| 26 |
-
|
| 27 |
-
# Copy all scaler attributes
|
| 28 |
-
for attr in ['n_features_in_', 'mean_', 'scale_', 'var_', 'feature_names_in_']:
|
| 29 |
-
if hasattr(original_scaler, attr):
|
| 30 |
-
setattr(new_scaler, attr, getattr(original_scaler, attr))
|
| 31 |
-
|
| 32 |
-
# Create new classifier and copy all attributes
|
| 33 |
-
new_classifier = KNeighborsClassifier()
|
| 34 |
-
|
| 35 |
-
# Copy all classifier attributes
|
| 36 |
-
for attr in ['n_neighbors', 'weights', 'algorithm', 'leaf_size', 'p', 'metric', 'metric_params', 'n_jobs']:
|
| 37 |
-
if hasattr(original_classifier, attr):
|
| 38 |
-
setattr(new_classifier, attr, getattr(original_classifier, attr))
|
| 39 |
-
|
| 40 |
-
# Copy fitted attributes
|
| 41 |
-
for attr in ['classes_', '_fit_X', '_y', '_tree', 'n_features_in_', 'effective_metric_', 'effective_metric_params_']:
|
| 42 |
-
if hasattr(original_classifier, attr):
|
| 43 |
-
setattr(new_classifier, attr, getattr(original_classifier, attr))
|
| 44 |
-
|
| 45 |
-
# Mark as fitted
|
| 46 |
-
new_classifier._sklearn_version = getattr(original_classifier, '_sklearn_version', '1.0')
|
| 47 |
-
|
| 48 |
-
# Save the models
|
| 49 |
-
joblib.dump(new_classifier, 'decision_tree_model_compatible.sav')
|
| 50 |
-
joblib.dump(new_scaler, 'face_recognition_scaler_compatible.sav')
|
| 51 |
-
|
| 52 |
-
print("✅ Created properly compatible models")
|
| 53 |
-
|
| 54 |
-
# Test the models
|
| 55 |
-
print("\nTesting compatible models...")
|
| 56 |
-
|
| 57 |
-
# Load and test
|
| 58 |
-
test_classifier = joblib.load('decision_tree_model_compatible.sav')
|
| 59 |
-
test_scaler = joblib.load('face_recognition_scaler_compatible.sav')
|
| 60 |
-
|
| 61 |
-
print(f"Test classifier type: {type(test_classifier)}")
|
| 62 |
-
print(f"Test classifier classes: {test_classifier.classes_}")
|
| 63 |
-
print(f"Test scaler features: {test_scaler.n_features_in_}")
|
| 64 |
-
|
| 65 |
-
# Test prediction
|
| 66 |
-
dummy_features = np.random.randn(1, test_scaler.n_features_in_)
|
| 67 |
-
scaled_features = test_scaler.transform(dummy_features)
|
| 68 |
-
prediction = test_classifier.predict(scaled_features)[0]
|
| 69 |
-
|
| 70 |
-
print(f"✅ Test prediction successful: {prediction}")
|
| 71 |
-
|
| 72 |
-
return True
|
| 73 |
-
|
| 74 |
-
except Exception as e:
|
| 75 |
-
print(f"❌ Error: {e}")
|
| 76 |
-
import traceback
|
| 77 |
-
traceback.print_exc()
|
| 78 |
-
return False
|
| 79 |
-
|
| 80 |
-
def create_simple_fallback():
|
| 81 |
-
"""Create a simple fallback model that should work on any sklearn version"""
|
| 82 |
-
print("\nCreating simple fallback model...")
|
| 83 |
-
|
| 84 |
-
try:
|
| 85 |
-
# Load original models
|
| 86 |
-
original_classifier = joblib.load('decision_tree_model.sav')
|
| 87 |
-
original_scaler = joblib.load('face_recognition_scaler.sav')
|
| 88 |
-
|
| 89 |
-
# Create simple models with same parameters
|
| 90 |
-
new_scaler = StandardScaler()
|
| 91 |
-
new_scaler.n_features_in_ = original_scaler.n_features_in_
|
| 92 |
-
new_scaler.mean_ = original_scaler.mean_.copy()
|
| 93 |
-
new_scaler.scale_ = original_scaler.scale_.copy()
|
| 94 |
-
|
| 95 |
-
# Create simple classifier
|
| 96 |
-
new_classifier = KNeighborsClassifier(n_neighbors=3)
|
| 97 |
-
|
| 98 |
-
# Use the original training data to refit
|
| 99 |
-
if hasattr(original_classifier, '_fit_X') and hasattr(original_classifier, '_y'):
|
| 100 |
-
X = original_classifier._fit_X
|
| 101 |
-
y = original_classifier._y
|
| 102 |
-
new_classifier.fit(X, y)
|
| 103 |
-
print("✅ Refitted classifier with original data")
|
| 104 |
-
else:
|
| 105 |
-
# Create dummy data
|
| 106 |
-
X = np.random.randn(100, original_scaler.n_features_in_)
|
| 107 |
-
y = np.random.choice([0, 1, 2], 100)
|
| 108 |
-
new_classifier.fit(X, y)
|
| 109 |
-
print("✅ Created classifier with dummy data")
|
| 110 |
-
|
| 111 |
-
# Save fallback models
|
| 112 |
-
joblib.dump(new_classifier, 'decision_tree_model_fallback.sav')
|
| 113 |
-
joblib.dump(new_scaler, 'face_recognition_scaler_fallback.sav')
|
| 114 |
-
|
| 115 |
-
print("✅ Created fallback models")
|
| 116 |
-
|
| 117 |
-
# Test fallback
|
| 118 |
-
test_features = np.random.randn(1, new_scaler.n_features_in_)
|
| 119 |
-
scaled = new_scaler.transform(test_features)
|
| 120 |
-
pred = new_classifier.predict(scaled)[0]
|
| 121 |
-
|
| 122 |
-
print(f"✅ Fallback test prediction: {pred}")
|
| 123 |
-
|
| 124 |
-
return True
|
| 125 |
-
|
| 126 |
-
except Exception as e:
|
| 127 |
-
print(f"❌ Fallback creation failed: {e}")
|
| 128 |
-
return False
|
| 129 |
-
|
| 130 |
-
if __name__ == "__main__":
|
| 131 |
-
print("🔧 Advanced Sklearn Compatibility Fix")
|
| 132 |
-
print("=" * 50)
|
| 133 |
-
|
| 134 |
-
# Try the proper method first
|
| 135 |
-
success1 = create_properly_compatible_model()
|
| 136 |
-
|
| 137 |
-
# If that fails, try fallback
|
| 138 |
-
if not success1:
|
| 139 |
-
success2 = create_simple_fallback()
|
| 140 |
-
|
| 141 |
-
if success1 or success2:
|
| 142 |
-
print("\n🎉 Compatible models created!")
|
| 143 |
-
print("Files ready for Hugging Face:")
|
| 144 |
-
print("- decision_tree_model_compatible.sav")
|
| 145 |
-
print("- face_recognition_scaler_compatible.sav")
|
| 146 |
-
print("- decision_tree_model_fallback.sav (if needed)")
|
| 147 |
-
print("- face_recognition_scaler_fallback.sav (if needed)")
|
| 148 |
-
else:
|
| 149 |
-
print("\n❌ All methods failed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/fix_sklearn_compatibility.py
DELETED
|
@@ -1,113 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Fix for sklearn version compatibility issue on Hugging Face
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
import pickle
|
| 9 |
-
import warnings
|
| 10 |
-
|
| 11 |
-
# Suppress sklearn warnings
|
| 12 |
-
warnings.filterwarnings('ignore', category=UserWarning, module='sklearn')
|
| 13 |
-
|
| 14 |
-
def create_compatible_model():
|
| 15 |
-
"""Create a sklearn-compatible version of the model"""
|
| 16 |
-
print("Creating sklearn-compatible model...")
|
| 17 |
-
|
| 18 |
-
try:
|
| 19 |
-
# Try to load the original model
|
| 20 |
-
import joblib
|
| 21 |
-
original_classifier = joblib.load('decision_tree_model.sav')
|
| 22 |
-
original_scaler = joblib.load('face_recognition_scaler.sav')
|
| 23 |
-
|
| 24 |
-
print(f"Original classifier type: {type(original_classifier)}")
|
| 25 |
-
print(f"Original classifier classes: {original_classifier.classes_}")
|
| 26 |
-
print(f"Original scaler features: {original_scaler.n_features_in_}")
|
| 27 |
-
|
| 28 |
-
# Create a new compatible classifier
|
| 29 |
-
from sklearn.neighbors import KNeighborsClassifier
|
| 30 |
-
from sklearn.preprocessing import StandardScaler
|
| 31 |
-
|
| 32 |
-
# Create new scaler with same parameters
|
| 33 |
-
new_scaler = StandardScaler()
|
| 34 |
-
new_scaler.n_features_in_ = original_scaler.n_features_in_
|
| 35 |
-
new_scaler.mean_ = original_scaler.mean_.copy()
|
| 36 |
-
new_scaler.scale_ = original_scaler.scale_.copy()
|
| 37 |
-
new_scaler.var_ = original_scaler.var_.copy()
|
| 38 |
-
|
| 39 |
-
# Create new classifier with same parameters
|
| 40 |
-
new_classifier = KNeighborsClassifier(
|
| 41 |
-
n_neighbors=original_classifier.n_neighbors,
|
| 42 |
-
weights=original_classifier.weights,
|
| 43 |
-
algorithm=original_classifier.algorithm,
|
| 44 |
-
leaf_size=original_classifier.leaf_size,
|
| 45 |
-
p=original_classifier.p,
|
| 46 |
-
metric=original_classifier.metric,
|
| 47 |
-
metric_params=original_classifier.metric_params,
|
| 48 |
-
n_jobs=original_classifier.n_jobs
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
# Copy the training data and classes
|
| 52 |
-
new_classifier.classes_ = original_classifier.classes_.copy()
|
| 53 |
-
new_classifier._fit_X = original_classifier._fit_X.copy()
|
| 54 |
-
new_classifier._y = original_classifier._y.copy()
|
| 55 |
-
new_classifier._tree = original_classifier._tree
|
| 56 |
-
|
| 57 |
-
# Save the compatible models
|
| 58 |
-
joblib.dump(new_classifier, 'decision_tree_model_compatible.sav')
|
| 59 |
-
joblib.dump(new_scaler, 'face_recognition_scaler_compatible.sav')
|
| 60 |
-
|
| 61 |
-
print("✅ Created compatible models:")
|
| 62 |
-
print(" - decision_tree_model_compatible.sav")
|
| 63 |
-
print(" - face_recognition_scaler_compatible.sav")
|
| 64 |
-
|
| 65 |
-
return True
|
| 66 |
-
|
| 67 |
-
except Exception as e:
|
| 68 |
-
print(f"❌ Error creating compatible model: {e}")
|
| 69 |
-
import traceback
|
| 70 |
-
traceback.print_exc()
|
| 71 |
-
return False
|
| 72 |
-
|
| 73 |
-
def test_compatible_model():
|
| 74 |
-
"""Test the compatible model"""
|
| 75 |
-
print("\nTesting compatible model...")
|
| 76 |
-
|
| 77 |
-
try:
|
| 78 |
-
import joblib
|
| 79 |
-
|
| 80 |
-
# Load compatible models
|
| 81 |
-
classifier = joblib.load('decision_tree_model_compatible.sav')
|
| 82 |
-
scaler = joblib.load('face_recognition_scaler_compatible.sav')
|
| 83 |
-
|
| 84 |
-
print(f"✅ Compatible classifier loaded: {type(classifier)}")
|
| 85 |
-
print(f"✅ Compatible scaler loaded: {scaler.n_features_in_} features")
|
| 86 |
-
|
| 87 |
-
# Test with dummy data
|
| 88 |
-
dummy_features = np.random.randn(1, scaler.n_features_in_)
|
| 89 |
-
scaled_features = scaler.transform(dummy_features)
|
| 90 |
-
prediction = classifier.predict(scaled_features)[0]
|
| 91 |
-
|
| 92 |
-
print(f"✅ Test prediction: {prediction}")
|
| 93 |
-
print(f"✅ Classifier classes: {classifier.classes_}")
|
| 94 |
-
|
| 95 |
-
return True
|
| 96 |
-
|
| 97 |
-
except Exception as e:
|
| 98 |
-
print(f"❌ Error testing compatible model: {e}")
|
| 99 |
-
return False
|
| 100 |
-
|
| 101 |
-
if __name__ == "__main__":
|
| 102 |
-
print("🔧 Sklearn Compatibility Fix")
|
| 103 |
-
print("=" * 40)
|
| 104 |
-
|
| 105 |
-
success = create_compatible_model()
|
| 106 |
-
if success:
|
| 107 |
-
test_compatible_model()
|
| 108 |
-
print("\n🎉 Compatible models created successfully!")
|
| 109 |
-
print("Use these files for Hugging Face deployment:")
|
| 110 |
-
print("- decision_tree_model_compatible.sav")
|
| 111 |
-
print("- face_recognition_scaler_compatible.sav")
|
| 112 |
-
else:
|
| 113 |
-
print("\n❌ Failed to create compatible models")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/fix_sklearn_warnings.py
DELETED
|
@@ -1,98 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Fix sklearn version warnings by suppressing them
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import warnings
|
| 6 |
-
import joblib
|
| 7 |
-
import os
|
| 8 |
-
|
| 9 |
-
def suppress_sklearn_warnings():
|
| 10 |
-
"""Suppress sklearn version warnings"""
|
| 11 |
-
warnings.filterwarnings('ignore', category=UserWarning, module='sklearn')
|
| 12 |
-
warnings.filterwarnings('ignore', message='.*InconsistentVersionWarning.*')
|
| 13 |
-
|
| 14 |
-
def test_models_without_warnings():
|
| 15 |
-
"""Test model loading without warnings"""
|
| 16 |
-
print("Testing models with suppressed warnings...")
|
| 17 |
-
print("=" * 50)
|
| 18 |
-
|
| 19 |
-
# Suppress warnings
|
| 20 |
-
suppress_sklearn_warnings()
|
| 21 |
-
|
| 22 |
-
try:
|
| 23 |
-
# Test scaler
|
| 24 |
-
print("Loading StandardScaler...")
|
| 25 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 26 |
-
print("OK: Scaler loaded")
|
| 27 |
-
|
| 28 |
-
# Test classifier
|
| 29 |
-
print("Loading KNeighborsClassifier...")
|
| 30 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 31 |
-
print("OK: Classifier loaded")
|
| 32 |
-
|
| 33 |
-
# Test with dummy data
|
| 34 |
-
import numpy as np
|
| 35 |
-
dummy_data = np.random.randn(1, 5)
|
| 36 |
-
scaled_data = scaler.transform(dummy_data)
|
| 37 |
-
prediction = classifier.predict(scaled_data)
|
| 38 |
-
|
| 39 |
-
print(f"OK: Test prediction: {prediction[0]}")
|
| 40 |
-
print("SUCCESS: Models work without warnings!")
|
| 41 |
-
|
| 42 |
-
return True
|
| 43 |
-
|
| 44 |
-
except Exception as e:
|
| 45 |
-
print(f"ERROR: {e}")
|
| 46 |
-
return False
|
| 47 |
-
|
| 48 |
-
def update_face_recognition_file():
|
| 49 |
-
"""Update face_recognition.py to suppress warnings"""
|
| 50 |
-
print("\nUpdating face_recognition.py to suppress warnings...")
|
| 51 |
-
|
| 52 |
-
# Read the current file
|
| 53 |
-
with open('face_recognition.py', 'r') as f:
|
| 54 |
-
content = f.read()
|
| 55 |
-
|
| 56 |
-
# Add warning suppression at the top
|
| 57 |
-
if 'warnings.filterwarnings' not in content:
|
| 58 |
-
# Find the import section and add warning suppression
|
| 59 |
-
import_section = content.find('import joblib')
|
| 60 |
-
if import_section != -1:
|
| 61 |
-
# Add warning suppression after joblib import
|
| 62 |
-
insert_pos = content.find('\n', import_section) + 1
|
| 63 |
-
warning_code = """import warnings
|
| 64 |
-
# Suppress sklearn version warnings
|
| 65 |
-
warnings.filterwarnings('ignore', category=UserWarning, module='sklearn')
|
| 66 |
-
warnings.filterwarnings('ignore', message='.*InconsistentVersionWarning.*')
|
| 67 |
-
|
| 68 |
-
"""
|
| 69 |
-
content = content[:insert_pos] + warning_code + content[insert_pos:]
|
| 70 |
-
|
| 71 |
-
# Write back to file
|
| 72 |
-
with open('face_recognition.py', 'w') as f:
|
| 73 |
-
f.write(content)
|
| 74 |
-
|
| 75 |
-
print("OK: Added warning suppression to face_recognition.py")
|
| 76 |
-
else:
|
| 77 |
-
print("WARNING: Could not find import section to add warning suppression")
|
| 78 |
-
else:
|
| 79 |
-
print("OK: Warning suppression already present")
|
| 80 |
-
|
| 81 |
-
def main():
|
| 82 |
-
print("Sklearn Warning Suppression Fix")
|
| 83 |
-
print("=" * 40)
|
| 84 |
-
|
| 85 |
-
# Test models
|
| 86 |
-
if test_models_without_warnings():
|
| 87 |
-
print("\nModels are working! Now updating face_recognition.py...")
|
| 88 |
-
update_face_recognition_file()
|
| 89 |
-
|
| 90 |
-
print("\n" + "=" * 50)
|
| 91 |
-
print("SUCCESS! Your models are working correctly.")
|
| 92 |
-
print("The warnings have been suppressed in face_recognition.py")
|
| 93 |
-
print("You can now use your face recognition system without warnings!")
|
| 94 |
-
else:
|
| 95 |
-
print("\nERROR: Models are not working properly")
|
| 96 |
-
|
| 97 |
-
if __name__ == "__main__":
|
| 98 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/fix_unknown_class.py
DELETED
|
@@ -1,57 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Fix for UNKNOWN_CLASS issue in Hugging Face Space
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
|
| 7 |
-
def create_fix_summary():
|
| 8 |
-
"""Create a summary of the fix"""
|
| 9 |
-
print("UNKNOWN_CLASS Issue Fix")
|
| 10 |
-
print("=" * 50)
|
| 11 |
-
|
| 12 |
-
print("PROBLEM IDENTIFIED:")
|
| 13 |
-
print("- Classifier has 7 classes: [0, 1, 2, 3, 4, 5, 6]")
|
| 14 |
-
print("- CLASS_NAMES had only 5 classes: ['Person0', 'Person1', 'Person2', 'Person3', 'Person4']")
|
| 15 |
-
print("- When classifier predicted class 5 or 6, it resulted in UNKNOWN_CLASS")
|
| 16 |
-
|
| 17 |
-
print("\nFIX APPLIED:")
|
| 18 |
-
print("- Updated CLASS_NAMES to include all 7 classes:")
|
| 19 |
-
print(" ['Person0', 'Person1', 'Person2', 'Person3', 'Person4', 'Person5', 'Person6']")
|
| 20 |
-
|
| 21 |
-
print("\nFILES TO UPDATE ON HUGGING FACE:")
|
| 22 |
-
print("1. face_recognition.py (with updated CLASS_NAMES)")
|
| 23 |
-
print("2. requirements.txt (for sklearn compatibility)")
|
| 24 |
-
print("3. All model files (.t7, .sav)")
|
| 25 |
-
|
| 26 |
-
print("\nDEPLOYMENT STEPS:")
|
| 27 |
-
print("1. Go to: https://huggingface.co/spaces/pavaniyerra/hackthon4")
|
| 28 |
-
print("2. Click 'Files and versions' tab")
|
| 29 |
-
print("3. Upload the updated face_recognition.py")
|
| 30 |
-
print("4. Upload requirements.txt")
|
| 31 |
-
print("5. Wait for rebuild (2-5 minutes)")
|
| 32 |
-
|
| 33 |
-
print("\nEXPECTED RESULT:")
|
| 34 |
-
print("- No more UNKNOWN_CLASS predictions")
|
| 35 |
-
print("- All 7 person classes will be recognized")
|
| 36 |
-
print("- Face classification will work properly")
|
| 37 |
-
|
| 38 |
-
def verify_fix():
|
| 39 |
-
"""Verify the fix is correct"""
|
| 40 |
-
print("\nVerifying fix...")
|
| 41 |
-
|
| 42 |
-
try:
|
| 43 |
-
from face_recognition import CLASS_NAMES
|
| 44 |
-
print(f"CLASS_NAMES: {CLASS_NAMES}")
|
| 45 |
-
print(f"Number of classes: {len(CLASS_NAMES)}")
|
| 46 |
-
|
| 47 |
-
if len(CLASS_NAMES) == 7:
|
| 48 |
-
print("✓ Fix verified: CLASS_NAMES now has 7 classes")
|
| 49 |
-
else:
|
| 50 |
-
print("✗ Fix not applied: CLASS_NAMES still has wrong number of classes")
|
| 51 |
-
|
| 52 |
-
except Exception as e:
|
| 53 |
-
print(f"Error verifying fix: {e}")
|
| 54 |
-
|
| 55 |
-
if __name__ == "__main__":
|
| 56 |
-
create_fix_summary()
|
| 57 |
-
verify_fix()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/inspect_classifier.py
DELETED
|
@@ -1,61 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Script to inspect the classifier model and understand the class structure
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import joblib
|
| 6 |
-
import os
|
| 7 |
-
|
| 8 |
-
def inspect_classifier():
|
| 9 |
-
"""Inspect the classifier model to understand class structure"""
|
| 10 |
-
model_path = 'decision_tree_model.sav'
|
| 11 |
-
|
| 12 |
-
if not os.path.exists(model_path):
|
| 13 |
-
print(f"Model file {model_path} not found!")
|
| 14 |
-
return
|
| 15 |
-
|
| 16 |
-
try:
|
| 17 |
-
# Load the classifier
|
| 18 |
-
classifier = joblib.load(model_path)
|
| 19 |
-
|
| 20 |
-
print("Classifier Model Inspection")
|
| 21 |
-
print("=" * 40)
|
| 22 |
-
print(f"Model type: {type(classifier)}")
|
| 23 |
-
print(f"Classifier classes: {classifier.classes_}")
|
| 24 |
-
print(f"Number of classes: {len(classifier.classes_)}")
|
| 25 |
-
print(f"Class range: {min(classifier.classes_)} to {max(classifier.classes_)}")
|
| 26 |
-
|
| 27 |
-
# Check if it's a decision tree
|
| 28 |
-
if hasattr(classifier, 'tree_'):
|
| 29 |
-
print(f"Decision tree depth: {classifier.tree_.max_depth}")
|
| 30 |
-
print(f"Number of leaves: {classifier.tree_.n_leaves}")
|
| 31 |
-
|
| 32 |
-
# Check feature importance if available
|
| 33 |
-
if hasattr(classifier, 'feature_importances_'):
|
| 34 |
-
print(f"Feature importances: {classifier.feature_importances_}")
|
| 35 |
-
|
| 36 |
-
# Test with dummy data
|
| 37 |
-
print("\nTesting with dummy data:")
|
| 38 |
-
import numpy as np
|
| 39 |
-
dummy_data = np.random.randn(1, 5) # Assuming 5 features
|
| 40 |
-
|
| 41 |
-
# Load scaler
|
| 42 |
-
scaler_path = 'face_recognition_scaler.sav'
|
| 43 |
-
if os.path.exists(scaler_path):
|
| 44 |
-
scaler = joblib.load(scaler_path)
|
| 45 |
-
scaled_data = scaler.transform(dummy_data)
|
| 46 |
-
prediction = classifier.predict(scaled_data)[0]
|
| 47 |
-
print(f"Dummy prediction: {prediction}")
|
| 48 |
-
|
| 49 |
-
# Check if prediction is valid
|
| 50 |
-
if prediction in classifier.classes_:
|
| 51 |
-
print(f"✓ Prediction {prediction} is valid")
|
| 52 |
-
else:
|
| 53 |
-
print(f"✗ Prediction {prediction} is NOT valid!")
|
| 54 |
-
|
| 55 |
-
except Exception as e:
|
| 56 |
-
print(f"Error loading classifier: {e}")
|
| 57 |
-
import traceback
|
| 58 |
-
traceback.print_exc()
|
| 59 |
-
|
| 60 |
-
if __name__ == "__main__":
|
| 61 |
-
inspect_classifier()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/inspect_model.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Script to inspect the saved model structure
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import torch
|
| 6 |
-
import os
|
| 7 |
-
|
| 8 |
-
def inspect_model():
|
| 9 |
-
"""Inspect the structure of the saved model"""
|
| 10 |
-
model_path = 'siamese_model.t7'
|
| 11 |
-
|
| 12 |
-
if not os.path.exists(model_path):
|
| 13 |
-
print(f"Model file {model_path} not found!")
|
| 14 |
-
return
|
| 15 |
-
|
| 16 |
-
try:
|
| 17 |
-
# Load the model
|
| 18 |
-
model_data = torch.load(model_path, map_location='cpu')
|
| 19 |
-
|
| 20 |
-
print("Model file loaded successfully!")
|
| 21 |
-
print(f"Type: {type(model_data)}")
|
| 22 |
-
|
| 23 |
-
if isinstance(model_data, dict):
|
| 24 |
-
print("\nDictionary keys:")
|
| 25 |
-
for key in model_data.keys():
|
| 26 |
-
print(f" - {key}")
|
| 27 |
-
|
| 28 |
-
if 'net_dict' in model_data:
|
| 29 |
-
print(f"\n'net_dict' contains {len(model_data['net_dict'])} items:")
|
| 30 |
-
for key in list(model_data['net_dict'].keys())[:10]: # Show first 10 keys
|
| 31 |
-
print(f" - {key}")
|
| 32 |
-
if len(model_data['net_dict']) > 10:
|
| 33 |
-
print(f" ... and {len(model_data['net_dict']) - 10} more keys")
|
| 34 |
-
else:
|
| 35 |
-
print("Model data is not a dictionary")
|
| 36 |
-
|
| 37 |
-
except Exception as e:
|
| 38 |
-
print(f"Error loading model: {e}")
|
| 39 |
-
|
| 40 |
-
if __name__ == "__main__":
|
| 41 |
-
inspect_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/lbpcascade_frontalface.xml
DELETED
|
@@ -1,1505 +0,0 @@
|
|
| 1 |
-
<?xml version="1.0"?>
|
| 2 |
-
<!--
|
| 3 |
-
number of positive samples 3000
|
| 4 |
-
number of negative samples 1500
|
| 5 |
-
-->
|
| 6 |
-
<opencv_storage>
|
| 7 |
-
<cascade type_id="opencv-cascade-classifier">
|
| 8 |
-
<stageType>BOOST</stageType>
|
| 9 |
-
<featureType>LBP</featureType>
|
| 10 |
-
<height>24</height>
|
| 11 |
-
<width>24</width>
|
| 12 |
-
<stageParams>
|
| 13 |
-
<boostType>GAB</boostType>
|
| 14 |
-
<minHitRate>0.9950000047683716</minHitRate>
|
| 15 |
-
<maxFalseAlarm>0.5000000000000000</maxFalseAlarm>
|
| 16 |
-
<weightTrimRate>0.9500000000000000</weightTrimRate>
|
| 17 |
-
<maxDepth>1</maxDepth>
|
| 18 |
-
<maxWeakCount>100</maxWeakCount></stageParams>
|
| 19 |
-
<featureParams>
|
| 20 |
-
<maxCatCount>256</maxCatCount></featureParams>
|
| 21 |
-
<stageNum>20</stageNum>
|
| 22 |
-
<stages>
|
| 23 |
-
<!-- stage 0 -->
|
| 24 |
-
<_>
|
| 25 |
-
<maxWeakCount>3</maxWeakCount>
|
| 26 |
-
<stageThreshold>-0.7520892024040222</stageThreshold>
|
| 27 |
-
<weakClassifiers>
|
| 28 |
-
<!-- tree 0 -->
|
| 29 |
-
<_>
|
| 30 |
-
<internalNodes>
|
| 31 |
-
0 -1 46 -67130709 -21569 -1426120013 -1275125205 -21585
|
| 32 |
-
-16385 587145899 -24005</internalNodes>
|
| 33 |
-
<leafValues>
|
| 34 |
-
-0.6543210148811340 0.8888888955116272</leafValues></_>
|
| 35 |
-
<!-- tree 1 -->
|
| 36 |
-
<_>
|
| 37 |
-
<internalNodes>
|
| 38 |
-
0 -1 13 -163512766 -769593758 -10027009 -262145 -514457854
|
| 39 |
-
-193593353 -524289 -1</internalNodes>
|
| 40 |
-
<leafValues>
|
| 41 |
-
-0.7739216089248657 0.7278633713722229</leafValues></_>
|
| 42 |
-
<!-- tree 2 -->
|
| 43 |
-
<_>
|
| 44 |
-
<internalNodes>
|
| 45 |
-
0 -1 2 -363936790 -893203669 -1337948010 -136907894
|
| 46 |
-
1088782736 -134217726 -741544961 -1590337</internalNodes>
|
| 47 |
-
<leafValues>
|
| 48 |
-
-0.7068563103675842 0.6761534214019775</leafValues></_></weakClassifiers></_>
|
| 49 |
-
<!-- stage 1 -->
|
| 50 |
-
<_>
|
| 51 |
-
<maxWeakCount>4</maxWeakCount>
|
| 52 |
-
<stageThreshold>-0.4872078299522400</stageThreshold>
|
| 53 |
-
<weakClassifiers>
|
| 54 |
-
<!-- tree 0 -->
|
| 55 |
-
<_>
|
| 56 |
-
<internalNodes>
|
| 57 |
-
0 -1 84 2147483647 1946124287 -536870913 2147450879
|
| 58 |
-
738132490 1061101567 243204619 2147446655</internalNodes>
|
| 59 |
-
<leafValues>
|
| 60 |
-
-0.8083735704421997 0.7685696482658386</leafValues></_>
|
| 61 |
-
<!-- tree 1 -->
|
| 62 |
-
<_>
|
| 63 |
-
<internalNodes>
|
| 64 |
-
0 -1 21 2147483647 263176079 1879048191 254749487 1879048191
|
| 65 |
-
-134252545 -268435457 801111999</internalNodes>
|
| 66 |
-
<leafValues>
|
| 67 |
-
-0.7698410153388977 0.6592915654182434</leafValues></_>
|
| 68 |
-
<!-- tree 2 -->
|
| 69 |
-
<_>
|
| 70 |
-
<internalNodes>
|
| 71 |
-
0 -1 106 -98110272 1610939566 -285484400 -850010381
|
| 72 |
-
-189334372 -1671954433 -571026695 -262145</internalNodes>
|
| 73 |
-
<leafValues>
|
| 74 |
-
-0.7506558895111084 0.5444605946540833</leafValues></_>
|
| 75 |
-
<!-- tree 3 -->
|
| 76 |
-
<_>
|
| 77 |
-
<internalNodes>
|
| 78 |
-
0 -1 48 -798690576 -131075 1095771153 -237144073 -65569 -1
|
| 79 |
-
-216727745 -69206049</internalNodes>
|
| 80 |
-
<leafValues>
|
| 81 |
-
-0.7775990366935730 0.5465461611747742</leafValues></_></weakClassifiers></_>
|
| 82 |
-
<!-- stage 2 -->
|
| 83 |
-
<_>
|
| 84 |
-
<maxWeakCount>4</maxWeakCount>
|
| 85 |
-
<stageThreshold>-1.1592328548431396</stageThreshold>
|
| 86 |
-
<weakClassifiers>
|
| 87 |
-
<!-- tree 0 -->
|
| 88 |
-
<_>
|
| 89 |
-
<internalNodes>
|
| 90 |
-
0 -1 47 -21585 -20549 -100818262 -738254174 -20561 -36865
|
| 91 |
-
-151016790 -134238549</internalNodes>
|
| 92 |
-
<leafValues>
|
| 93 |
-
-0.5601882934570313 0.7743113040924072</leafValues></_>
|
| 94 |
-
<!-- tree 1 -->
|
| 95 |
-
<_>
|
| 96 |
-
<internalNodes>
|
| 97 |
-
0 -1 12 -286003217 183435247 -268994614 -421330945
|
| 98 |
-
-402686081 1090387966 -286785545 -402653185</internalNodes>
|
| 99 |
-
<leafValues>
|
| 100 |
-
-0.6124526262283325 0.6978127956390381</leafValues></_>
|
| 101 |
-
<!-- tree 2 -->
|
| 102 |
-
<_>
|
| 103 |
-
<internalNodes>
|
| 104 |
-
0 -1 26 -50347012 970882927 -50463492 -1253377 -134218251
|
| 105 |
-
-50364513 -33619992 -172490753</internalNodes>
|
| 106 |
-
<leafValues>
|
| 107 |
-
-0.6114496588706970 0.6537628173828125</leafValues></_>
|
| 108 |
-
<!-- tree 3 -->
|
| 109 |
-
<_>
|
| 110 |
-
<internalNodes>
|
| 111 |
-
0 -1 8 -273 -135266321 1877977738 -2088243418 -134217987
|
| 112 |
-
2146926575 -18910642 1095231247</internalNodes>
|
| 113 |
-
<leafValues>
|
| 114 |
-
-0.6854077577590942 0.5403239130973816</leafValues></_></weakClassifiers></_>
|
| 115 |
-
<!-- stage 3 -->
|
| 116 |
-
<_>
|
| 117 |
-
<maxWeakCount>5</maxWeakCount>
|
| 118 |
-
<stageThreshold>-0.7562355995178223</stageThreshold>
|
| 119 |
-
<weakClassifiers>
|
| 120 |
-
<!-- tree 0 -->
|
| 121 |
-
<_>
|
| 122 |
-
<internalNodes>
|
| 123 |
-
0 -1 96 -1273 1870659519 -20971602 -67633153 -134250731
|
| 124 |
-
2004875127 -250 -150995969</internalNodes>
|
| 125 |
-
<leafValues>
|
| 126 |
-
-0.4051094949245453 0.7584033608436585</leafValues></_>
|
| 127 |
-
<!-- tree 1 -->
|
| 128 |
-
<_>
|
| 129 |
-
<internalNodes>
|
| 130 |
-
0 -1 33 -868162224 -76810262 -4262145 -257 1465211989
|
| 131 |
-
-268959873 -2656269 -524289</internalNodes>
|
| 132 |
-
<leafValues>
|
| 133 |
-
-0.7388162612915039 0.5340843200683594</leafValues></_>
|
| 134 |
-
<!-- tree 2 -->
|
| 135 |
-
<_>
|
| 136 |
-
<internalNodes>
|
| 137 |
-
0 -1 57 -12817 -49 -541103378 -152950 -38993 -20481 -1153876
|
| 138 |
-
-72478976</internalNodes>
|
| 139 |
-
<leafValues>
|
| 140 |
-
-0.6582943797111511 0.5339496731758118</leafValues></_>
|
| 141 |
-
<!-- tree 3 -->
|
| 142 |
-
<_>
|
| 143 |
-
<internalNodes>
|
| 144 |
-
0 -1 125 -269484161 -452984961 -319816180 -1594032130 -2111
|
| 145 |
-
-990117891 -488975296 -520947741</internalNodes>
|
| 146 |
-
<leafValues>
|
| 147 |
-
-0.5981323719024658 0.5323504805564880</leafValues></_>
|
| 148 |
-
<!-- tree 4 -->
|
| 149 |
-
<_>
|
| 150 |
-
<internalNodes>
|
| 151 |
-
0 -1 53 557787431 670265215 -1342193665 -1075892225
|
| 152 |
-
1998528318 1056964607 -33570977 -1</internalNodes>
|
| 153 |
-
<leafValues>
|
| 154 |
-
-0.6498787999153137 0.4913350641727448</leafValues></_></weakClassifiers></_>
|
| 155 |
-
<!-- stage 4 -->
|
| 156 |
-
<_>
|
| 157 |
-
<maxWeakCount>5</maxWeakCount>
|
| 158 |
-
<stageThreshold>-0.8085358142852783</stageThreshold>
|
| 159 |
-
<weakClassifiers>
|
| 160 |
-
<!-- tree 0 -->
|
| 161 |
-
<_>
|
| 162 |
-
<internalNodes>
|
| 163 |
-
0 -1 60 -536873708 880195381 -16842788 -20971521 -176687276
|
| 164 |
-
-168427659 -16777260 -33554626</internalNodes>
|
| 165 |
-
<leafValues>
|
| 166 |
-
-0.5278195738792419 0.6946372389793396</leafValues></_>
|
| 167 |
-
<!-- tree 1 -->
|
| 168 |
-
<_>
|
| 169 |
-
<internalNodes>
|
| 170 |
-
0 -1 7 -1 -62981529 -1090591130 805330978 -8388827 -41945787
|
| 171 |
-
-39577 -531118985</internalNodes>
|
| 172 |
-
<leafValues>
|
| 173 |
-
-0.5206505060195923 0.6329920291900635</leafValues></_>
|
| 174 |
-
<!-- tree 2 -->
|
| 175 |
-
<_>
|
| 176 |
-
<internalNodes>
|
| 177 |
-
0 -1 98 -725287348 1347747543 -852489 -16809993 1489881036
|
| 178 |
-
-167903241 -1 -1</internalNodes>
|
| 179 |
-
<leafValues>
|
| 180 |
-
-0.7516061067581177 0.4232024252414703</leafValues></_>
|
| 181 |
-
<!-- tree 3 -->
|
| 182 |
-
<_>
|
| 183 |
-
<internalNodes>
|
| 184 |
-
0 -1 44 -32777 1006582562 -65 935312171 -8388609 -1078198273
|
| 185 |
-
-1 733886267</internalNodes>
|
| 186 |
-
<leafValues>
|
| 187 |
-
-0.7639313936233521 0.4123568832874298</leafValues></_>
|
| 188 |
-
<!-- tree 4 -->
|
| 189 |
-
<_>
|
| 190 |
-
<internalNodes>
|
| 191 |
-
0 -1 24 -85474705 2138828511 -1036436754 817625855
|
| 192 |
-
1123369029 -58796809 -1013468481 -194513409</internalNodes>
|
| 193 |
-
<leafValues>
|
| 194 |
-
-0.5123769044876099 0.5791834592819214</leafValues></_></weakClassifiers></_>
|
| 195 |
-
<!-- stage 5 -->
|
| 196 |
-
<_>
|
| 197 |
-
<maxWeakCount>5</maxWeakCount>
|
| 198 |
-
<stageThreshold>-0.5549971461296082</stageThreshold>
|
| 199 |
-
<weakClassifiers>
|
| 200 |
-
<!-- tree 0 -->
|
| 201 |
-
<_>
|
| 202 |
-
<internalNodes>
|
| 203 |
-
0 -1 42 -17409 -20481 -268457797 -134239493 -17473 -1 -21829
|
| 204 |
-
-21846</internalNodes>
|
| 205 |
-
<leafValues>
|
| 206 |
-
-0.3763174116611481 0.7298233509063721</leafValues></_>
|
| 207 |
-
<!-- tree 1 -->
|
| 208 |
-
<_>
|
| 209 |
-
<internalNodes>
|
| 210 |
-
0 -1 6 -805310737 -2098262358 -269504725 682502698
|
| 211 |
-
2147483519 1740574719 -1090519233 -268472385</internalNodes>
|
| 212 |
-
<leafValues>
|
| 213 |
-
-0.5352765917778015 0.5659480094909668</leafValues></_>
|
| 214 |
-
<!-- tree 2 -->
|
| 215 |
-
<_>
|
| 216 |
-
<internalNodes>
|
| 217 |
-
0 -1 61 -67109678 -6145 -8 -87884584 -20481 -1073762305
|
| 218 |
-
-50856216 -16849696</internalNodes>
|
| 219 |
-
<leafValues>
|
| 220 |
-
-0.5678374171257019 0.4961479902267456</leafValues></_>
|
| 221 |
-
<!-- tree 3 -->
|
| 222 |
-
<_>
|
| 223 |
-
<internalNodes>
|
| 224 |
-
0 -1 123 -138428633 1002418167 -1359008245 -1908670465
|
| 225 |
-
-1346685918 910098423 -1359010520 -1346371657</internalNodes>
|
| 226 |
-
<leafValues>
|
| 227 |
-
-0.5706262588500977 0.4572288393974304</leafValues></_>
|
| 228 |
-
<!-- tree 4 -->
|
| 229 |
-
<_>
|
| 230 |
-
<internalNodes>
|
| 231 |
-
0 -1 9 -89138513 -4196353 1256531674 -1330665426 1216308261
|
| 232 |
-
-36190633 33498198 -151796633</internalNodes>
|
| 233 |
-
<leafValues>
|
| 234 |
-
-0.5344601869583130 0.4672054052352905</leafValues></_></weakClassifiers></_>
|
| 235 |
-
<!-- stage 6 -->
|
| 236 |
-
<_>
|
| 237 |
-
<maxWeakCount>5</maxWeakCount>
|
| 238 |
-
<stageThreshold>-0.8776460289955139</stageThreshold>
|
| 239 |
-
<weakClassifiers>
|
| 240 |
-
<!-- tree 0 -->
|
| 241 |
-
<_>
|
| 242 |
-
<internalNodes>
|
| 243 |
-
0 -1 105 1073769576 206601725 -34013449 -33554433 -789514004
|
| 244 |
-
-101384321 -690225153 -264193</internalNodes>
|
| 245 |
-
<leafValues>
|
| 246 |
-
-0.7700348496437073 0.5943940877914429</leafValues></_>
|
| 247 |
-
<!-- tree 1 -->
|
| 248 |
-
<_>
|
| 249 |
-
<internalNodes>
|
| 250 |
-
0 -1 30 -1432340997 -823623681 -49153 -34291724 -269484035
|
| 251 |
-
-1342767105 -1078198273 -1277955</internalNodes>
|
| 252 |
-
<leafValues>
|
| 253 |
-
-0.5043668746948242 0.6151274442672730</leafValues></_>
|
| 254 |
-
<!-- tree 2 -->
|
| 255 |
-
<_>
|
| 256 |
-
<internalNodes>
|
| 257 |
-
0 -1 35 -1067385040 -195758209 -436748425 -134217731
|
| 258 |
-
-50855988 -129 -1 -1</internalNodes>
|
| 259 |
-
<leafValues>
|
| 260 |
-
-0.6808040738105774 0.4667325913906097</leafValues></_>
|
| 261 |
-
<!-- tree 3 -->
|
| 262 |
-
<_>
|
| 263 |
-
<internalNodes>
|
| 264 |
-
0 -1 119 832534325 -34111555 -26050561 -423659521 -268468364
|
| 265 |
-
2105014143 -2114244 -17367185</internalNodes>
|
| 266 |
-
<leafValues>
|
| 267 |
-
-0.4927591383457184 0.5401885509490967</leafValues></_>
|
| 268 |
-
<!-- tree 4 -->
|
| 269 |
-
<_>
|
| 270 |
-
<internalNodes>
|
| 271 |
-
0 -1 82 -1089439888 -1080524865 2143059967 -1114121
|
| 272 |
-
-1140949004 -3 -2361356 -739516</internalNodes>
|
| 273 |
-
<leafValues>
|
| 274 |
-
-0.6445107460021973 0.4227822124958038</leafValues></_></weakClassifiers></_>
|
| 275 |
-
<!-- stage 7 -->
|
| 276 |
-
<_>
|
| 277 |
-
<maxWeakCount>6</maxWeakCount>
|
| 278 |
-
<stageThreshold>-1.1139287948608398</stageThreshold>
|
| 279 |
-
<weakClassifiers>
|
| 280 |
-
<!-- tree 0 -->
|
| 281 |
-
<_>
|
| 282 |
-
<internalNodes>
|
| 283 |
-
0 -1 52 -1074071553 -1074003969 -1 -1280135430 -5324817 -1
|
| 284 |
-
-335548482 582134442</internalNodes>
|
| 285 |
-
<leafValues>
|
| 286 |
-
-0.5307556986808777 0.6258179545402527</leafValues></_>
|
| 287 |
-
<!-- tree 1 -->
|
| 288 |
-
<_>
|
| 289 |
-
<internalNodes>
|
| 290 |
-
0 -1 99 -706937396 -705364068 -540016724 -570495027
|
| 291 |
-
-570630659 -587857963 -33628164 -35848193</internalNodes>
|
| 292 |
-
<leafValues>
|
| 293 |
-
-0.5227634310722351 0.5049746036529541</leafValues></_>
|
| 294 |
-
<!-- tree 2 -->
|
| 295 |
-
<_>
|
| 296 |
-
<internalNodes>
|
| 297 |
-
0 -1 18 -2035630093 42119158 -268503053 -1671444 261017599
|
| 298 |
-
1325432815 1954394111 -805306449</internalNodes>
|
| 299 |
-
<leafValues>
|
| 300 |
-
-0.4983572661876679 0.5106441378593445</leafValues></_>
|
| 301 |
-
<!-- tree 3 -->
|
| 302 |
-
<_>
|
| 303 |
-
<internalNodes>
|
| 304 |
-
0 -1 111 -282529488 -1558073088 1426018736 -170526448
|
| 305 |
-
-546832487 -5113037 -34243375 -570427929</internalNodes>
|
| 306 |
-
<leafValues>
|
| 307 |
-
-0.4990860521793366 0.5060507059097290</leafValues></_>
|
| 308 |
-
<!-- tree 4 -->
|
| 309 |
-
<_>
|
| 310 |
-
<internalNodes>
|
| 311 |
-
0 -1 92 1016332500 -606301707 915094269 -1080086049
|
| 312 |
-
-1837027144 -1361600280 2147318747 1067975613</internalNodes>
|
| 313 |
-
<leafValues>
|
| 314 |
-
-0.5695009231567383 0.4460467398166657</leafValues></_>
|
| 315 |
-
<!-- tree 5 -->
|
| 316 |
-
<_>
|
| 317 |
-
<internalNodes>
|
| 318 |
-
0 -1 51 -656420166 -15413034 -141599534 -603435836
|
| 319 |
-
1505950458 -787556946 -79823438 -1326199134</internalNodes>
|
| 320 |
-
<leafValues>
|
| 321 |
-
-0.6590405106544495 0.3616424500942230</leafValues></_></weakClassifiers></_>
|
| 322 |
-
<!-- stage 8 -->
|
| 323 |
-
<_>
|
| 324 |
-
<maxWeakCount>7</maxWeakCount>
|
| 325 |
-
<stageThreshold>-0.8243625760078430</stageThreshold>
|
| 326 |
-
<weakClassifiers>
|
| 327 |
-
<!-- tree 0 -->
|
| 328 |
-
<_>
|
| 329 |
-
<internalNodes>
|
| 330 |
-
0 -1 28 -901591776 -201916417 -262 -67371009 -143312112
|
| 331 |
-
-524289 -41943178 -1</internalNodes>
|
| 332 |
-
<leafValues>
|
| 333 |
-
-0.4972776770591736 0.6027074456214905</leafValues></_>
|
| 334 |
-
<!-- tree 1 -->
|
| 335 |
-
<_>
|
| 336 |
-
<internalNodes>
|
| 337 |
-
0 -1 112 -4507851 -411340929 -268437513 -67502145 -17350859
|
| 338 |
-
-32901 -71344315 -29377</internalNodes>
|
| 339 |
-
<leafValues>
|
| 340 |
-
-0.4383158981800079 0.5966237187385559</leafValues></_>
|
| 341 |
-
<!-- tree 2 -->
|
| 342 |
-
<_>
|
| 343 |
-
<internalNodes>
|
| 344 |
-
0 -1 69 -75894785 -117379438 -239063587 -12538500 1485072126
|
| 345 |
-
2076233213 2123118847 801906927</internalNodes>
|
| 346 |
-
<leafValues>
|
| 347 |
-
-0.6386105418205261 0.3977999985218048</leafValues></_>
|
| 348 |
-
<!-- tree 3 -->
|
| 349 |
-
<_>
|
| 350 |
-
<internalNodes>
|
| 351 |
-
0 -1 19 -823480413 786628589 -16876049 -1364262914 242165211
|
| 352 |
-
1315930109 -696268833 -455082829</internalNodes>
|
| 353 |
-
<leafValues>
|
| 354 |
-
-0.5512794256210327 0.4282079637050629</leafValues></_>
|
| 355 |
-
<!-- tree 4 -->
|
| 356 |
-
<_>
|
| 357 |
-
<internalNodes>
|
| 358 |
-
0 -1 73 -521411968 6746762 -1396236286 -2038436114
|
| 359 |
-
-185612509 57669627 -143132877 -1041235973</internalNodes>
|
| 360 |
-
<leafValues>
|
| 361 |
-
-0.6418755054473877 0.3549866080284119</leafValues></_>
|
| 362 |
-
<!-- tree 5 -->
|
| 363 |
-
<_>
|
| 364 |
-
<internalNodes>
|
| 365 |
-
0 -1 126 -478153869 1076028979 -1645895615 1365298272
|
| 366 |
-
-557859073 -339771473 1442574528 -1058802061</internalNodes>
|
| 367 |
-
<leafValues>
|
| 368 |
-
-0.4841901361942291 0.4668019413948059</leafValues></_>
|
| 369 |
-
<!-- tree 6 -->
|
| 370 |
-
<_>
|
| 371 |
-
<internalNodes>
|
| 372 |
-
0 -1 45 -246350404 -1650402048 -1610612745 -788400696
|
| 373 |
-
1467604861 -2787397 1476263935 -4481349</internalNodes>
|
| 374 |
-
<leafValues>
|
| 375 |
-
-0.5855734348297119 0.3879135847091675</leafValues></_></weakClassifiers></_>
|
| 376 |
-
<!-- stage 9 -->
|
| 377 |
-
<_>
|
| 378 |
-
<maxWeakCount>7</maxWeakCount>
|
| 379 |
-
<stageThreshold>-1.2237116098403931</stageThreshold>
|
| 380 |
-
<weakClassifiers>
|
| 381 |
-
<!-- tree 0 -->
|
| 382 |
-
<_>
|
| 383 |
-
<internalNodes>
|
| 384 |
-
0 -1 114 -24819 1572863935 -16809993 -67108865 2146778388
|
| 385 |
-
1433927541 -268608444 -34865205</internalNodes>
|
| 386 |
-
<leafValues>
|
| 387 |
-
-0.2518476545810700 0.7088654041290283</leafValues></_>
|
| 388 |
-
<!-- tree 1 -->
|
| 389 |
-
<_>
|
| 390 |
-
<internalNodes>
|
| 391 |
-
0 -1 97 -1841359 -134271049 -32769 -5767369 -1116675 -2185
|
| 392 |
-
-8231 -33603327</internalNodes>
|
| 393 |
-
<leafValues>
|
| 394 |
-
-0.4303432404994965 0.5283288359642029</leafValues></_>
|
| 395 |
-
<!-- tree 2 -->
|
| 396 |
-
<_>
|
| 397 |
-
<internalNodes>
|
| 398 |
-
0 -1 25 -1359507589 -1360593090 -1073778729 -269553812
|
| 399 |
-
-809512977 1744707583 -41959433 -134758978</internalNodes>
|
| 400 |
-
<leafValues>
|
| 401 |
-
-0.4259553551673889 0.5440809130668640</leafValues></_>
|
| 402 |
-
<!-- tree 3 -->
|
| 403 |
-
<_>
|
| 404 |
-
<internalNodes>
|
| 405 |
-
0 -1 34 729753407 -134270989 -1140907329 -235200777
|
| 406 |
-
658456383 2147467263 -1140900929 -16385</internalNodes>
|
| 407 |
-
<leafValues>
|
| 408 |
-
-0.5605589151382446 0.4220733344554901</leafValues></_>
|
| 409 |
-
<!-- tree 4 -->
|
| 410 |
-
<_>
|
| 411 |
-
<internalNodes>
|
| 412 |
-
0 -1 134 -310380553 -420675595 -193005472 -353568129
|
| 413 |
-
1205338070 -990380036 887604324 -420544526</internalNodes>
|
| 414 |
-
<leafValues>
|
| 415 |
-
-0.5192656517028809 0.4399855434894562</leafValues></_>
|
| 416 |
-
<!-- tree 5 -->
|
| 417 |
-
<_>
|
| 418 |
-
<internalNodes>
|
| 419 |
-
0 -1 16 -1427119361 1978920959 -287119734 -487068946
|
| 420 |
-
114759245 -540578051 -707510259 -671660453</internalNodes>
|
| 421 |
-
<leafValues>
|
| 422 |
-
-0.5013077259063721 0.4570254683494568</leafValues></_>
|
| 423 |
-
<!-- tree 6 -->
|
| 424 |
-
<_>
|
| 425 |
-
<internalNodes>
|
| 426 |
-
0 -1 74 -738463762 -889949281 -328301948 -121832450
|
| 427 |
-
-1142658284 -1863576559 2146417353 -263185</internalNodes>
|
| 428 |
-
<leafValues>
|
| 429 |
-
-0.4631414115428925 0.4790246188640595</leafValues></_></weakClassifiers></_>
|
| 430 |
-
<!-- stage 10 -->
|
| 431 |
-
<_>
|
| 432 |
-
<maxWeakCount>7</maxWeakCount>
|
| 433 |
-
<stageThreshold>-0.5544230937957764</stageThreshold>
|
| 434 |
-
<weakClassifiers>
|
| 435 |
-
<!-- tree 0 -->
|
| 436 |
-
<_>
|
| 437 |
-
<internalNodes>
|
| 438 |
-
0 -1 113 -76228780 -65538 -1 -67174401 -148007 -33 -221796
|
| 439 |
-
-272842924</internalNodes>
|
| 440 |
-
<leafValues>
|
| 441 |
-
-0.3949716091156006 0.6082032322883606</leafValues></_>
|
| 442 |
-
<!-- tree 1 -->
|
| 443 |
-
<_>
|
| 444 |
-
<internalNodes>
|
| 445 |
-
0 -1 110 369147696 -1625232112 2138570036 -1189900 790708019
|
| 446 |
-
-1212613127 799948719 -4456483</internalNodes>
|
| 447 |
-
<leafValues>
|
| 448 |
-
-0.4855885505676270 0.4785369932651520</leafValues></_>
|
| 449 |
-
<!-- tree 2 -->
|
| 450 |
-
<_>
|
| 451 |
-
<internalNodes>
|
| 452 |
-
0 -1 37 784215839 -290015241 536832799 -402984963
|
| 453 |
-
-1342414991 -838864897 -176769 -268456129</internalNodes>
|
| 454 |
-
<leafValues>
|
| 455 |
-
-0.4620285332202911 0.4989669024944305</leafValues></_>
|
| 456 |
-
<!-- tree 3 -->
|
| 457 |
-
<_>
|
| 458 |
-
<internalNodes>
|
| 459 |
-
0 -1 41 -486418688 -171915327 -340294900 -21938 -519766032
|
| 460 |
-
-772751172 -73096060 -585322623</internalNodes>
|
| 461 |
-
<leafValues>
|
| 462 |
-
-0.6420643329620361 0.3624351918697357</leafValues></_>
|
| 463 |
-
<!-- tree 4 -->
|
| 464 |
-
<_>
|
| 465 |
-
<internalNodes>
|
| 466 |
-
0 -1 117 -33554953 -475332625 -1423463824 -2077230421
|
| 467 |
-
-4849669 -2080505925 -219032928 -1071915349</internalNodes>
|
| 468 |
-
<leafValues>
|
| 469 |
-
-0.4820112884044647 0.4632140696048737</leafValues></_>
|
| 470 |
-
<!-- tree 5 -->
|
| 471 |
-
<_>
|
| 472 |
-
<internalNodes>
|
| 473 |
-
0 -1 65 -834130468 -134217476 -1349314083 -1073803559
|
| 474 |
-
-619913764 -1449131844 -1386890321 -1979118423</internalNodes>
|
| 475 |
-
<leafValues>
|
| 476 |
-
-0.4465552568435669 0.5061788558959961</leafValues></_>
|
| 477 |
-
<!-- tree 6 -->
|
| 478 |
-
<_>
|
| 479 |
-
<internalNodes>
|
| 480 |
-
0 -1 56 -285249779 1912569855 -16530 -1731022870 -1161904146
|
| 481 |
-
-1342177297 -268439634 -1464078708</internalNodes>
|
| 482 |
-
<leafValues>
|
| 483 |
-
-0.5190586447715759 0.4441480338573456</leafValues></_></weakClassifiers></_>
|
| 484 |
-
<!-- stage 11 -->
|
| 485 |
-
<_>
|
| 486 |
-
<maxWeakCount>7</maxWeakCount>
|
| 487 |
-
<stageThreshold>-0.7161560654640198</stageThreshold>
|
| 488 |
-
<weakClassifiers>
|
| 489 |
-
<!-- tree 0 -->
|
| 490 |
-
<_>
|
| 491 |
-
<internalNodes>
|
| 492 |
-
0 -1 20 1246232575 1078001186 -10027057 60102 -277348353
|
| 493 |
-
-43646987 -1210581153 1195769615</internalNodes>
|
| 494 |
-
<leafValues>
|
| 495 |
-
-0.4323809444904327 0.5663768053054810</leafValues></_>
|
| 496 |
-
<!-- tree 1 -->
|
| 497 |
-
<_>
|
| 498 |
-
<internalNodes>
|
| 499 |
-
0 -1 15 -778583572 -612921106 -578775890 -4036478
|
| 500 |
-
-1946580497 -1164766570 -1986687009 -12103599</internalNodes>
|
| 501 |
-
<leafValues>
|
| 502 |
-
-0.4588732719421387 0.4547033011913300</leafValues></_>
|
| 503 |
-
<!-- tree 2 -->
|
| 504 |
-
<_>
|
| 505 |
-
<internalNodes>
|
| 506 |
-
0 -1 129 -1073759445 2013231743 -1363169553 -1082459201
|
| 507 |
-
-1414286549 868185983 -1356133589 -1077936257</internalNodes>
|
| 508 |
-
<leafValues>
|
| 509 |
-
-0.5218553543090820 0.4111092388629913</leafValues></_>
|
| 510 |
-
<!-- tree 3 -->
|
| 511 |
-
<_>
|
| 512 |
-
<internalNodes>
|
| 513 |
-
0 -1 102 -84148365 -2093417722 -1204850272 564290299
|
| 514 |
-
-67121221 -1342177350 -1309195902 -776734797</internalNodes>
|
| 515 |
-
<leafValues>
|
| 516 |
-
-0.4920000731945038 0.4326725304126740</leafValues></_>
|
| 517 |
-
<!-- tree 4 -->
|
| 518 |
-
<_>
|
| 519 |
-
<internalNodes>
|
| 520 |
-
0 -1 88 -25694458 67104495 -290216278 -168563037 2083877442
|
| 521 |
-
1702788383 -144191964 -234882162</internalNodes>
|
| 522 |
-
<leafValues>
|
| 523 |
-
-0.4494568109512329 0.4448510706424713</leafValues></_>
|
| 524 |
-
<!-- tree 5 -->
|
| 525 |
-
<_>
|
| 526 |
-
<internalNodes>
|
| 527 |
-
0 -1 59 -857980836 904682741 -1612267521 232279415
|
| 528 |
-
1550862252 -574825221 -357380888 -4579409</internalNodes>
|
| 529 |
-
<leafValues>
|
| 530 |
-
-0.5180826783180237 0.3888972699642181</leafValues></_>
|
| 531 |
-
<!-- tree 6 -->
|
| 532 |
-
<_>
|
| 533 |
-
<internalNodes>
|
| 534 |
-
0 -1 27 -98549440 -137838400 494928389 -246013630 939541351
|
| 535 |
-
-1196072350 -620603549 2137216273</internalNodes>
|
| 536 |
-
<leafValues>
|
| 537 |
-
-0.6081240773200989 0.3333222270011902</leafValues></_></weakClassifiers></_>
|
| 538 |
-
<!-- stage 12 -->
|
| 539 |
-
<_>
|
| 540 |
-
<maxWeakCount>8</maxWeakCount>
|
| 541 |
-
<stageThreshold>-0.6743940711021423</stageThreshold>
|
| 542 |
-
<weakClassifiers>
|
| 543 |
-
<!-- tree 0 -->
|
| 544 |
-
<_>
|
| 545 |
-
<internalNodes>
|
| 546 |
-
0 -1 29 -150995201 2071191945 -1302151626 536934335
|
| 547 |
-
-1059008937 914128709 1147328110 -268369925</internalNodes>
|
| 548 |
-
<leafValues>
|
| 549 |
-
-0.1790193915367127 0.6605972051620483</leafValues></_>
|
| 550 |
-
<!-- tree 1 -->
|
| 551 |
-
<_>
|
| 552 |
-
<internalNodes>
|
| 553 |
-
0 -1 128 -134509479 1610575703 -1342177289 1861484541
|
| 554 |
-
-1107833788 1577058173 -333558568 -136319041</internalNodes>
|
| 555 |
-
<leafValues>
|
| 556 |
-
-0.3681024610996246 0.5139749646186829</leafValues></_>
|
| 557 |
-
<!-- tree 2 -->
|
| 558 |
-
<_>
|
| 559 |
-
<internalNodes>
|
| 560 |
-
0 -1 70 -1 1060154476 -1090984524 -630918524 -539492875
|
| 561 |
-
779616255 -839568424 -321</internalNodes>
|
| 562 |
-
<leafValues>
|
| 563 |
-
-0.3217232525348663 0.6171553134918213</leafValues></_>
|
| 564 |
-
<!-- tree 3 -->
|
| 565 |
-
<_>
|
| 566 |
-
<internalNodes>
|
| 567 |
-
0 -1 4 -269562385 -285029906 -791084350 -17923776 235286671
|
| 568 |
-
1275504943 1344390399 -966276889</internalNodes>
|
| 569 |
-
<leafValues>
|
| 570 |
-
-0.4373284578323364 0.4358185231685638</leafValues></_>
|
| 571 |
-
<!-- tree 4 -->
|
| 572 |
-
<_>
|
| 573 |
-
<internalNodes>
|
| 574 |
-
0 -1 76 17825984 -747628419 595427229 1474759671 575672208
|
| 575 |
-
-1684005538 872217086 -1155858277</internalNodes>
|
| 576 |
-
<leafValues>
|
| 577 |
-
-0.4404836893081665 0.4601220190525055</leafValues></_>
|
| 578 |
-
<!-- tree 5 -->
|
| 579 |
-
<_>
|
| 580 |
-
<internalNodes>
|
| 581 |
-
0 -1 124 -336593039 1873735591 -822231622 -355795238
|
| 582 |
-
-470820869 -1997537409 -1057132384 -1015285005</internalNodes>
|
| 583 |
-
<leafValues>
|
| 584 |
-
-0.4294152259826660 0.4452161788940430</leafValues></_>
|
| 585 |
-
<!-- tree 6 -->
|
| 586 |
-
<_>
|
| 587 |
-
<internalNodes>
|
| 588 |
-
0 -1 54 -834212130 -593694721 -322142257 -364892500
|
| 589 |
-
-951029539 -302125121 -1615106053 -79249765</internalNodes>
|
| 590 |
-
<leafValues>
|
| 591 |
-
-0.3973052501678467 0.4854526817798615</leafValues></_>
|
| 592 |
-
<!-- tree 7 -->
|
| 593 |
-
<_>
|
| 594 |
-
<internalNodes>
|
| 595 |
-
0 -1 95 1342144479 2147431935 -33554561 -47873 -855685912 -1
|
| 596 |
-
1988052447 536827383</internalNodes>
|
| 597 |
-
<leafValues>
|
| 598 |
-
-0.7054683566093445 0.2697997391223908</leafValues></_></weakClassifiers></_>
|
| 599 |
-
<!-- stage 13 -->
|
| 600 |
-
<_>
|
| 601 |
-
<maxWeakCount>9</maxWeakCount>
|
| 602 |
-
<stageThreshold>-1.2042298316955566</stageThreshold>
|
| 603 |
-
<weakClassifiers>
|
| 604 |
-
<!-- tree 0 -->
|
| 605 |
-
<_>
|
| 606 |
-
<internalNodes>
|
| 607 |
-
0 -1 39 1431368960 -183437936 -537002499 -137497097
|
| 608 |
-
1560590321 -84611081 -2097193 -513</internalNodes>
|
| 609 |
-
<leafValues>
|
| 610 |
-
-0.5905947685241699 0.5101932883262634</leafValues></_>
|
| 611 |
-
<!-- tree 1 -->
|
| 612 |
-
<_>
|
| 613 |
-
<internalNodes>
|
| 614 |
-
0 -1 120 -1645259691 2105491231 2130706431 1458995007
|
| 615 |
-
-8567536 -42483883 -33780003 -21004417</internalNodes>
|
| 616 |
-
<leafValues>
|
| 617 |
-
-0.4449204802513123 0.4490709304809570</leafValues></_>
|
| 618 |
-
<!-- tree 2 -->
|
| 619 |
-
<_>
|
| 620 |
-
<internalNodes>
|
| 621 |
-
0 -1 89 -612381022 -505806938 -362027516 -452985106
|
| 622 |
-
275854917 1920431639 -12600561 -134221825</internalNodes>
|
| 623 |
-
<leafValues>
|
| 624 |
-
-0.4693818688392639 0.4061094820499420</leafValues></_>
|
| 625 |
-
<!-- tree 3 -->
|
| 626 |
-
<_>
|
| 627 |
-
<internalNodes>
|
| 628 |
-
0 -1 14 -805573153 -161 -554172679 -530519488 -16779441
|
| 629 |
-
2000682871 -33604275 -150997129</internalNodes>
|
| 630 |
-
<leafValues>
|
| 631 |
-
-0.3600351214408875 0.5056326985359192</leafValues></_>
|
| 632 |
-
<!-- tree 4 -->
|
| 633 |
-
<_>
|
| 634 |
-
<internalNodes>
|
| 635 |
-
0 -1 67 6192 435166195 1467449341 2046691505 -1608493775
|
| 636 |
-
-4755729 -1083162625 -71365637</internalNodes>
|
| 637 |
-
<leafValues>
|
| 638 |
-
-0.4459891915321350 0.4132415652275085</leafValues></_>
|
| 639 |
-
<!-- tree 5 -->
|
| 640 |
-
<_>
|
| 641 |
-
<internalNodes>
|
| 642 |
-
0 -1 86 -41689215 -3281034 1853357967 -420712635 -415924289
|
| 643 |
-
-270209208 -1088293113 -825311232</internalNodes>
|
| 644 |
-
<leafValues>
|
| 645 |
-
-0.4466069042682648 0.4135067760944367</leafValues></_>
|
| 646 |
-
<!-- tree 6 -->
|
| 647 |
-
<_>
|
| 648 |
-
<internalNodes>
|
| 649 |
-
0 -1 80 -117391116 -42203396 2080374461 -188709 -542008165
|
| 650 |
-
-356831940 -1091125345 -1073796897</internalNodes>
|
| 651 |
-
<leafValues>
|
| 652 |
-
-0.3394956290721893 0.5658645033836365</leafValues></_>
|
| 653 |
-
<!-- tree 7 -->
|
| 654 |
-
<_>
|
| 655 |
-
<internalNodes>
|
| 656 |
-
0 -1 75 -276830049 1378714472 -1342181951 757272098
|
| 657 |
-
1073740607 -282199241 -415761549 170896931</internalNodes>
|
| 658 |
-
<leafValues>
|
| 659 |
-
-0.5346512198448181 0.3584479391574860</leafValues></_>
|
| 660 |
-
<!-- tree 8 -->
|
| 661 |
-
<_>
|
| 662 |
-
<internalNodes>
|
| 663 |
-
0 -1 55 -796075825 -123166849 2113667055 -217530421
|
| 664 |
-
-1107432194 -16385 -806359809 -391188771</internalNodes>
|
| 665 |
-
<leafValues>
|
| 666 |
-
-0.4379335641860962 0.4123645126819611</leafValues></_></weakClassifiers></_>
|
| 667 |
-
<!-- stage 14 -->
|
| 668 |
-
<_>
|
| 669 |
-
<maxWeakCount>10</maxWeakCount>
|
| 670 |
-
<stageThreshold>-0.8402050137519836</stageThreshold>
|
| 671 |
-
<weakClassifiers>
|
| 672 |
-
<!-- tree 0 -->
|
| 673 |
-
<_>
|
| 674 |
-
<internalNodes>
|
| 675 |
-
0 -1 71 -890246622 15525883 -487690486 47116238 -1212319899
|
| 676 |
-
-1291847681 -68159890 -469829921</internalNodes>
|
| 677 |
-
<leafValues>
|
| 678 |
-
-0.2670986354351044 0.6014143228530884</leafValues></_>
|
| 679 |
-
<!-- tree 1 -->
|
| 680 |
-
<_>
|
| 681 |
-
<internalNodes>
|
| 682 |
-
0 -1 31 -1361180685 -1898008841 -1090588811 -285410071
|
| 683 |
-
-1074016265 -840443905 2147221487 -262145</internalNodes>
|
| 684 |
-
<leafValues>
|
| 685 |
-
-0.4149844348430634 0.4670888185501099</leafValues></_>
|
| 686 |
-
<!-- tree 2 -->
|
| 687 |
-
<_>
|
| 688 |
-
<internalNodes>
|
| 689 |
-
0 -1 40 1426190596 1899364271 2142731795 -142607505
|
| 690 |
-
-508232452 -21563393 -41960001 -65</internalNodes>
|
| 691 |
-
<leafValues>
|
| 692 |
-
-0.4985891580581665 0.3719584941864014</leafValues></_>
|
| 693 |
-
<!-- tree 3 -->
|
| 694 |
-
<_>
|
| 695 |
-
<internalNodes>
|
| 696 |
-
0 -1 109 -201337965 10543906 -236498096 -746195597
|
| 697 |
-
1974565825 -15204415 921907633 -190058309</internalNodes>
|
| 698 |
-
<leafValues>
|
| 699 |
-
-0.4568729996681213 0.3965812027454376</leafValues></_>
|
| 700 |
-
<!-- tree 4 -->
|
| 701 |
-
<_>
|
| 702 |
-
<internalNodes>
|
| 703 |
-
0 -1 130 -595026732 -656401928 -268649235 -571490699
|
| 704 |
-
-440600392 -133131 -358810952 -2004088646</internalNodes>
|
| 705 |
-
<leafValues>
|
| 706 |
-
-0.4770836830139160 0.3862601518630981</leafValues></_>
|
| 707 |
-
<!-- tree 5 -->
|
| 708 |
-
<_>
|
| 709 |
-
<internalNodes>
|
| 710 |
-
0 -1 66 941674740 -1107882114 1332789109 -67691015
|
| 711 |
-
-1360463693 -1556612430 -609108546 733546933</internalNodes>
|
| 712 |
-
<leafValues>
|
| 713 |
-
-0.4877715110778809 0.3778986334800720</leafValues></_>
|
| 714 |
-
<!-- tree 6 -->
|
| 715 |
-
<_>
|
| 716 |
-
<internalNodes>
|
| 717 |
-
0 -1 49 -17114945 -240061474 1552871558 -82775604 -932393844
|
| 718 |
-
-1308544889 -532635478 -99042357</internalNodes>
|
| 719 |
-
<leafValues>
|
| 720 |
-
-0.3721654713153839 0.4994400143623352</leafValues></_>
|
| 721 |
-
<!-- tree 7 -->
|
| 722 |
-
<_>
|
| 723 |
-
<internalNodes>
|
| 724 |
-
0 -1 133 -655906006 1405502603 -939205164 1884929228
|
| 725 |
-
-498859222 559417357 -1928559445 -286264385</internalNodes>
|
| 726 |
-
<leafValues>
|
| 727 |
-
-0.3934195041656494 0.4769641458988190</leafValues></_>
|
| 728 |
-
<!-- tree 8 -->
|
| 729 |
-
<_>
|
| 730 |
-
<internalNodes>
|
| 731 |
-
0 -1 0 -335837777 1860677295 -90 -1946186226 931096183
|
| 732 |
-
251612987 2013265917 -671232197</internalNodes>
|
| 733 |
-
<leafValues>
|
| 734 |
-
-0.4323300719261169 0.4342164099216461</leafValues></_>
|
| 735 |
-
<!-- tree 9 -->
|
| 736 |
-
<_>
|
| 737 |
-
<internalNodes>
|
| 738 |
-
0 -1 103 37769424 -137772680 374692301 2002666345 -536176194
|
| 739 |
-
-1644484728 807009019 1069089930</internalNodes>
|
| 740 |
-
<leafValues>
|
| 741 |
-
-0.4993278682231903 0.3665378093719482</leafValues></_></weakClassifiers></_>
|
| 742 |
-
<!-- stage 15 -->
|
| 743 |
-
<_>
|
| 744 |
-
<maxWeakCount>9</maxWeakCount>
|
| 745 |
-
<stageThreshold>-1.1974394321441650</stageThreshold>
|
| 746 |
-
<weakClassifiers>
|
| 747 |
-
<!-- tree 0 -->
|
| 748 |
-
<_>
|
| 749 |
-
<internalNodes>
|
| 750 |
-
0 -1 43 -5505 2147462911 2143265466 -4511070 -16450 -257
|
| 751 |
-
-201348440 -71333206</internalNodes>
|
| 752 |
-
<leafValues>
|
| 753 |
-
-0.3310225307941437 0.5624626278877258</leafValues></_>
|
| 754 |
-
<!-- tree 1 -->
|
| 755 |
-
<_>
|
| 756 |
-
<internalNodes>
|
| 757 |
-
0 -1 90 -136842268 -499330741 2015250980 -87107126
|
| 758 |
-
-641665744 -788524639 -1147864792 -134892563</internalNodes>
|
| 759 |
-
<leafValues>
|
| 760 |
-
-0.5266560912132263 0.3704403042793274</leafValues></_>
|
| 761 |
-
<!-- tree 2 -->
|
| 762 |
-
<_>
|
| 763 |
-
<internalNodes>
|
| 764 |
-
0 -1 104 -146800880 -1780368555 2111170033 -140904684
|
| 765 |
-
-16777551 -1946681885 -1646463595 -839131947</internalNodes>
|
| 766 |
-
<leafValues>
|
| 767 |
-
-0.4171888828277588 0.4540435671806335</leafValues></_>
|
| 768 |
-
<!-- tree 3 -->
|
| 769 |
-
<_>
|
| 770 |
-
<internalNodes>
|
| 771 |
-
0 -1 85 -832054034 -981663763 -301990281 -578814081
|
| 772 |
-
-932319000 -1997406723 -33555201 -69206017</internalNodes>
|
| 773 |
-
<leafValues>
|
| 774 |
-
-0.4556705355644226 0.3704262077808380</leafValues></_>
|
| 775 |
-
<!-- tree 4 -->
|
| 776 |
-
<_>
|
| 777 |
-
<internalNodes>
|
| 778 |
-
0 -1 24 -118492417 -1209026825 1119023838 -1334313353
|
| 779 |
-
1112948738 -297319313 1378887291 -139469193</internalNodes>
|
| 780 |
-
<leafValues>
|
| 781 |
-
-0.4182529747486115 0.4267231225967407</leafValues></_>
|
| 782 |
-
<!-- tree 5 -->
|
| 783 |
-
<_>
|
| 784 |
-
<internalNodes>
|
| 785 |
-
0 -1 78 -1714382628 -2353704 -112094959 -549613092
|
| 786 |
-
-1567058760 -1718550464 -342315012 -1074972227</internalNodes>
|
| 787 |
-
<leafValues>
|
| 788 |
-
-0.3625369668006897 0.4684656262397766</leafValues></_>
|
| 789 |
-
<!-- tree 6 -->
|
| 790 |
-
<_>
|
| 791 |
-
<internalNodes>
|
| 792 |
-
0 -1 5 -85219702 316836394 -33279 1904970288 2117267315
|
| 793 |
-
-260901769 -621461759 -88607770</internalNodes>
|
| 794 |
-
<leafValues>
|
| 795 |
-
-0.4742925167083740 0.3689507246017456</leafValues></_>
|
| 796 |
-
<!-- tree 7 -->
|
| 797 |
-
<_>
|
| 798 |
-
<internalNodes>
|
| 799 |
-
0 -1 11 -294654041 -353603585 -1641159686 -50331921
|
| 800 |
-
-2080899877 1145569279 -143132713 -152044037</internalNodes>
|
| 801 |
-
<leafValues>
|
| 802 |
-
-0.3666271567344666 0.4580127298831940</leafValues></_>
|
| 803 |
-
<!-- tree 8 -->
|
| 804 |
-
<_>
|
| 805 |
-
<internalNodes>
|
| 806 |
-
0 -1 32 1887453658 -638545712 -1877976819 -34320972
|
| 807 |
-
-1071067983 -661345416 -583338277 1060190561</internalNodes>
|
| 808 |
-
<leafValues>
|
| 809 |
-
-0.4567637443542481 0.3894708156585693</leafValues></_></weakClassifiers></_>
|
| 810 |
-
<!-- stage 16 -->
|
| 811 |
-
<_>
|
| 812 |
-
<maxWeakCount>9</maxWeakCount>
|
| 813 |
-
<stageThreshold>-0.5733128190040588</stageThreshold>
|
| 814 |
-
<weakClassifiers>
|
| 815 |
-
<!-- tree 0 -->
|
| 816 |
-
<_>
|
| 817 |
-
<internalNodes>
|
| 818 |
-
0 -1 122 -994063296 1088745462 -318837116 -319881377
|
| 819 |
-
1102566613 1165490103 -121679694 -134744129</internalNodes>
|
| 820 |
-
<leafValues>
|
| 821 |
-
-0.4055117964744568 0.5487945079803467</leafValues></_>
|
| 822 |
-
<!-- tree 1 -->
|
| 823 |
-
<_>
|
| 824 |
-
<internalNodes>
|
| 825 |
-
0 -1 68 -285233233 -538992907 1811935199 -369234005 -529
|
| 826 |
-
-20593 -20505 -1561401854</internalNodes>
|
| 827 |
-
<leafValues>
|
| 828 |
-
-0.3787897229194641 0.4532003402709961</leafValues></_>
|
| 829 |
-
<!-- tree 2 -->
|
| 830 |
-
<_>
|
| 831 |
-
<internalNodes>
|
| 832 |
-
0 -1 58 -1335245632 1968917183 1940861695 536816369
|
| 833 |
-
-1226071367 -570908176 457026619 1000020667</internalNodes>
|
| 834 |
-
<leafValues>
|
| 835 |
-
-0.4258328974246979 0.4202791750431061</leafValues></_>
|
| 836 |
-
<!-- tree 3 -->
|
| 837 |
-
<_>
|
| 838 |
-
<internalNodes>
|
| 839 |
-
0 -1 94 -1360318719 -1979797897 -50435249 -18646473
|
| 840 |
-
-608879292 -805306691 -269304244 -17840167</internalNodes>
|
| 841 |
-
<leafValues>
|
| 842 |
-
-0.4561023116111755 0.4002747833728790</leafValues></_>
|
| 843 |
-
<!-- tree 4 -->
|
| 844 |
-
<_>
|
| 845 |
-
<internalNodes>
|
| 846 |
-
0 -1 87 2062765935 -16449 -1275080721 -16406 45764335
|
| 847 |
-
-1090552065 -772846337 -570464322</internalNodes>
|
| 848 |
-
<leafValues>
|
| 849 |
-
-0.4314672648906708 0.4086346626281738</leafValues></_>
|
| 850 |
-
<!-- tree 5 -->
|
| 851 |
-
<_>
|
| 852 |
-
<internalNodes>
|
| 853 |
-
0 -1 127 -536896021 1080817663 -738234288 -965478709
|
| 854 |
-
-2082767969 1290855887 1993822934 -990381609</internalNodes>
|
| 855 |
-
<leafValues>
|
| 856 |
-
-0.4174543321132660 0.4249868988990784</leafValues></_>
|
| 857 |
-
<!-- tree 6 -->
|
| 858 |
-
<_>
|
| 859 |
-
<internalNodes>
|
| 860 |
-
0 -1 3 -818943025 168730891 -293610428 -79249354 669224671
|
| 861 |
-
621166734 1086506807 1473768907</internalNodes>
|
| 862 |
-
<leafValues>
|
| 863 |
-
-0.4321364760398865 0.4090838730335236</leafValues></_>
|
| 864 |
-
<!-- tree 7 -->
|
| 865 |
-
<_>
|
| 866 |
-
<internalNodes>
|
| 867 |
-
0 -1 79 -68895696 -67107736 -1414315879 -841676168
|
| 868 |
-
-619843344 -1180610531 -1081990469 1043203389</internalNodes>
|
| 869 |
-
<leafValues>
|
| 870 |
-
-0.5018386244773865 0.3702533841133118</leafValues></_>
|
| 871 |
-
<!-- tree 8 -->
|
| 872 |
-
<_>
|
| 873 |
-
<internalNodes>
|
| 874 |
-
0 -1 116 -54002134 -543485719 -2124882422 -1437445858
|
| 875 |
-
-115617074 -1195787391 -1096024366 -2140472445</internalNodes>
|
| 876 |
-
<leafValues>
|
| 877 |
-
-0.5037505626678467 0.3564981222152710</leafValues></_></weakClassifiers></_>
|
| 878 |
-
<!-- stage 17 -->
|
| 879 |
-
<_>
|
| 880 |
-
<maxWeakCount>9</maxWeakCount>
|
| 881 |
-
<stageThreshold>-0.4892596900463104</stageThreshold>
|
| 882 |
-
<weakClassifiers>
|
| 883 |
-
<!-- tree 0 -->
|
| 884 |
-
<_>
|
| 885 |
-
<internalNodes>
|
| 886 |
-
0 -1 132 -67113211 2003808111 1862135111 846461923 -2752
|
| 887 |
-
2002237273 -273154752 1937223539</internalNodes>
|
| 888 |
-
<leafValues>
|
| 889 |
-
-0.2448196411132813 0.5689709186553955</leafValues></_>
|
| 890 |
-
<!-- tree 1 -->
|
| 891 |
-
<_>
|
| 892 |
-
<internalNodes>
|
| 893 |
-
0 -1 62 1179423888 -78064940 -611839555 -539167899
|
| 894 |
-
-1289358360 -1650810108 -892540499 -1432827684</internalNodes>
|
| 895 |
-
<leafValues>
|
| 896 |
-
-0.4633283913135529 0.3587929606437683</leafValues></_>
|
| 897 |
-
<!-- tree 2 -->
|
| 898 |
-
<_>
|
| 899 |
-
<internalNodes>
|
| 900 |
-
0 -1 23 -285212705 -78450761 -656212031 -264050110 -27787425
|
| 901 |
-
-1334349961 -547662981 -135796924</internalNodes>
|
| 902 |
-
<leafValues>
|
| 903 |
-
-0.3731099069118500 0.4290455579757690</leafValues></_>
|
| 904 |
-
<!-- tree 3 -->
|
| 905 |
-
<_>
|
| 906 |
-
<internalNodes>
|
| 907 |
-
0 -1 77 341863476 403702016 -550588417 1600194541
|
| 908 |
-
-1080690735 951127993 -1388580949 -1153717473</internalNodes>
|
| 909 |
-
<leafValues>
|
| 910 |
-
-0.3658909499645233 0.4556473195552826</leafValues></_>
|
| 911 |
-
<!-- tree 4 -->
|
| 912 |
-
<_>
|
| 913 |
-
<internalNodes>
|
| 914 |
-
0 -1 22 -586880702 -204831512 -100644596 -39319550
|
| 915 |
-
-1191150794 705692513 457203315 -75806957</internalNodes>
|
| 916 |
-
<leafValues>
|
| 917 |
-
-0.5214384198188782 0.3221037387847900</leafValues></_>
|
| 918 |
-
<!-- tree 5 -->
|
| 919 |
-
<_>
|
| 920 |
-
<internalNodes>
|
| 921 |
-
0 -1 72 -416546870 545911370 -673716192 -775559454
|
| 922 |
-
-264113598 139424 -183369982 -204474641</internalNodes>
|
| 923 |
-
<leafValues>
|
| 924 |
-
-0.4289036989212036 0.4004956185817719</leafValues></_>
|
| 925 |
-
<!-- tree 6 -->
|
| 926 |
-
<_>
|
| 927 |
-
<internalNodes>
|
| 928 |
-
0 -1 50 -1026505020 -589692154 -1740499937 -1563770497
|
| 929 |
-
1348491006 -60710713 -1109853489 -633909413</internalNodes>
|
| 930 |
-
<leafValues>
|
| 931 |
-
-0.4621542394161224 0.3832748532295227</leafValues></_>
|
| 932 |
-
<!-- tree 7 -->
|
| 933 |
-
<_>
|
| 934 |
-
<internalNodes>
|
| 935 |
-
0 -1 108 -1448872304 -477895040 -1778390608 -772418127
|
| 936 |
-
-1789923416 -1612057181 -805306693 -1415842113</internalNodes>
|
| 937 |
-
<leafValues>
|
| 938 |
-
-0.3711548447608948 0.4612701535224915</leafValues></_>
|
| 939 |
-
<!-- tree 8 -->
|
| 940 |
-
<_>
|
| 941 |
-
<internalNodes>
|
| 942 |
-
0 -1 92 407905424 -582449988 52654751 -1294472 -285103725
|
| 943 |
-
-74633006 1871559083 1057955850</internalNodes>
|
| 944 |
-
<leafValues>
|
| 945 |
-
-0.5180652141571045 0.3205870389938355</leafValues></_></weakClassifiers></_>
|
| 946 |
-
<!-- stage 18 -->
|
| 947 |
-
<_>
|
| 948 |
-
<maxWeakCount>10</maxWeakCount>
|
| 949 |
-
<stageThreshold>-0.5911940932273865</stageThreshold>
|
| 950 |
-
<weakClassifiers>
|
| 951 |
-
<!-- tree 0 -->
|
| 952 |
-
<_>
|
| 953 |
-
<internalNodes>
|
| 954 |
-
0 -1 81 4112 -1259563825 -846671428 -100902460 1838164148
|
| 955 |
-
-74153752 -90653988 -1074263896</internalNodes>
|
| 956 |
-
<leafValues>
|
| 957 |
-
-0.2592592537403107 0.5873016119003296</leafValues></_>
|
| 958 |
-
<!-- tree 1 -->
|
| 959 |
-
<_>
|
| 960 |
-
<internalNodes>
|
| 961 |
-
0 -1 1 -285216785 -823206977 -1085589 -1081346 1207959293
|
| 962 |
-
1157103471 2097133565 -2097169</internalNodes>
|
| 963 |
-
<leafValues>
|
| 964 |
-
-0.3801195919513702 0.4718827307224274</leafValues></_>
|
| 965 |
-
<!-- tree 2 -->
|
| 966 |
-
<_>
|
| 967 |
-
<internalNodes>
|
| 968 |
-
0 -1 121 -12465 -536875169 2147478367 2130706303 -37765492
|
| 969 |
-
-866124467 -318782328 -1392509185</internalNodes>
|
| 970 |
-
<leafValues>
|
| 971 |
-
-0.3509117066860199 0.5094807147979736</leafValues></_>
|
| 972 |
-
<!-- tree 3 -->
|
| 973 |
-
<_>
|
| 974 |
-
<internalNodes>
|
| 975 |
-
0 -1 38 2147449663 -20741 -16794757 1945873146 -16710 -1
|
| 976 |
-
-8406341 -67663041</internalNodes>
|
| 977 |
-
<leafValues>
|
| 978 |
-
-0.4068757295608521 0.4130136370658875</leafValues></_>
|
| 979 |
-
<!-- tree 4 -->
|
| 980 |
-
<_>
|
| 981 |
-
<internalNodes>
|
| 982 |
-
0 -1 17 -155191713 866117231 1651407483 548272812 -479201468
|
| 983 |
-
-447742449 1354229504 -261884429</internalNodes>
|
| 984 |
-
<leafValues>
|
| 985 |
-
-0.4557141065597534 0.3539792001247406</leafValues></_>
|
| 986 |
-
<!-- tree 5 -->
|
| 987 |
-
<_>
|
| 988 |
-
<internalNodes>
|
| 989 |
-
0 -1 100 -225319378 -251682065 -492783986 -792341777
|
| 990 |
-
-1287261695 1393643841 -11274182 -213909521</internalNodes>
|
| 991 |
-
<leafValues>
|
| 992 |
-
-0.4117803275585175 0.4118592441082001</leafValues></_>
|
| 993 |
-
<!-- tree 6 -->
|
| 994 |
-
<_>
|
| 995 |
-
<internalNodes>
|
| 996 |
-
0 -1 63 -382220122 -2002072729 -51404800 -371201558
|
| 997 |
-
-923011069 -2135301457 -2066104743 -1042557441</internalNodes>
|
| 998 |
-
<leafValues>
|
| 999 |
-
-0.4008397758007050 0.4034757018089294</leafValues></_>
|
| 1000 |
-
<!-- tree 7 -->
|
| 1001 |
-
<_>
|
| 1002 |
-
<internalNodes>
|
| 1003 |
-
0 -1 101 -627353764 -48295149 1581203952 -436258614
|
| 1004 |
-
-105268268 -1435893445 -638126888 -1061107126</internalNodes>
|
| 1005 |
-
<leafValues>
|
| 1006 |
-
-0.5694189667701721 0.2964762747287750</leafValues></_>
|
| 1007 |
-
<!-- tree 8 -->
|
| 1008 |
-
<_>
|
| 1009 |
-
<internalNodes>
|
| 1010 |
-
0 -1 118 -8399181 1058107691 -621022752 -251003468 -12582915
|
| 1011 |
-
-574619739 -994397789 -1648362021</internalNodes>
|
| 1012 |
-
<leafValues>
|
| 1013 |
-
-0.3195341229438782 0.5294018983840942</leafValues></_>
|
| 1014 |
-
<!-- tree 9 -->
|
| 1015 |
-
<_>
|
| 1016 |
-
<internalNodes>
|
| 1017 |
-
0 -1 92 -348343812 -1078389516 1717960437 364735981
|
| 1018 |
-
-1783841602 -4883137 -457572354 -1076950384</internalNodes>
|
| 1019 |
-
<leafValues>
|
| 1020 |
-
-0.3365339040756226 0.5067458748817444</leafValues></_></weakClassifiers></_>
|
| 1021 |
-
<!-- stage 19 -->
|
| 1022 |
-
<_>
|
| 1023 |
-
<maxWeakCount>10</maxWeakCount>
|
| 1024 |
-
<stageThreshold>-0.7612916231155396</stageThreshold>
|
| 1025 |
-
<weakClassifiers>
|
| 1026 |
-
<!-- tree 0 -->
|
| 1027 |
-
<_>
|
| 1028 |
-
<internalNodes>
|
| 1029 |
-
0 -1 10 -1976661318 -287957604 -1659497122 -782068 43591089
|
| 1030 |
-
-453637880 1435470000 -1077438561</internalNodes>
|
| 1031 |
-
<leafValues>
|
| 1032 |
-
-0.4204545319080353 0.5165745615959168</leafValues></_>
|
| 1033 |
-
<!-- tree 1 -->
|
| 1034 |
-
<_>
|
| 1035 |
-
<internalNodes>
|
| 1036 |
-
0 -1 131 -67110925 14874979 -142633168 -1338923040
|
| 1037 |
-
2046713291 -2067933195 1473503712 -789579837</internalNodes>
|
| 1038 |
-
<leafValues>
|
| 1039 |
-
-0.3762553930282593 0.4075302779674530</leafValues></_>
|
| 1040 |
-
<!-- tree 2 -->
|
| 1041 |
-
<_>
|
| 1042 |
-
<internalNodes>
|
| 1043 |
-
0 -1 83 -272814301 -1577073 -1118685 -305156120 -1052289
|
| 1044 |
-
-1073813756 -538971154 -355523038</internalNodes>
|
| 1045 |
-
<leafValues>
|
| 1046 |
-
-0.4253497421741486 0.3728055357933044</leafValues></_>
|
| 1047 |
-
<!-- tree 3 -->
|
| 1048 |
-
<_>
|
| 1049 |
-
<internalNodes>
|
| 1050 |
-
0 -1 135 -2233 -214486242 -538514758 573747007 -159390971
|
| 1051 |
-
1994225489 -973738098 -203424005</internalNodes>
|
| 1052 |
-
<leafValues>
|
| 1053 |
-
-0.3601998090744019 0.4563256204128265</leafValues></_>
|
| 1054 |
-
<!-- tree 4 -->
|
| 1055 |
-
<_>
|
| 1056 |
-
<internalNodes>
|
| 1057 |
-
0 -1 115 -261031688 -1330369299 -641860609 1029570301
|
| 1058 |
-
-1306461192 -1196149518 -1529767778 683139823</internalNodes>
|
| 1059 |
-
<leafValues>
|
| 1060 |
-
-0.4034293889999390 0.4160816967487335</leafValues></_>
|
| 1061 |
-
<!-- tree 5 -->
|
| 1062 |
-
<_>
|
| 1063 |
-
<internalNodes>
|
| 1064 |
-
0 -1 64 -572993608 -34042628 -417865 -111109 -1433365268
|
| 1065 |
-
-19869715 -1920939864 -1279457063</internalNodes>
|
| 1066 |
-
<leafValues>
|
| 1067 |
-
-0.3620899617671967 0.4594142735004425</leafValues></_>
|
| 1068 |
-
<!-- tree 6 -->
|
| 1069 |
-
<_>
|
| 1070 |
-
<internalNodes>
|
| 1071 |
-
0 -1 36 -626275097 -615256993 1651946018 805366393
|
| 1072 |
-
2016559730 -430780849 -799868165 -16580645</internalNodes>
|
| 1073 |
-
<leafValues>
|
| 1074 |
-
-0.3903816640377045 0.4381459355354309</leafValues></_>
|
| 1075 |
-
<!-- tree 7 -->
|
| 1076 |
-
<_>
|
| 1077 |
-
<internalNodes>
|
| 1078 |
-
0 -1 93 1354797300 -1090957603 1976418270 -1342502178
|
| 1079 |
-
-1851873892 -1194637077 -1153521668 -1108399474</internalNodes>
|
| 1080 |
-
<leafValues>
|
| 1081 |
-
-0.3591445386409760 0.4624078869819641</leafValues></_>
|
| 1082 |
-
<!-- tree 8 -->
|
| 1083 |
-
<_>
|
| 1084 |
-
<internalNodes>
|
| 1085 |
-
0 -1 91 68157712 1211368313 -304759523 1063017136 798797750
|
| 1086 |
-
-275513546 648167355 -1145357350</internalNodes>
|
| 1087 |
-
<leafValues>
|
| 1088 |
-
-0.4297670423984528 0.4023293554782867</leafValues></_>
|
| 1089 |
-
<!-- tree 9 -->
|
| 1090 |
-
<_>
|
| 1091 |
-
<internalNodes>
|
| 1092 |
-
0 -1 107 -546318240 -1628569602 -163577944 -537002306
|
| 1093 |
-
-545456389 -1325465645 -380446736 -1058473386</internalNodes>
|
| 1094 |
-
<leafValues>
|
| 1095 |
-
-0.5727006793022156 0.2995934784412384</leafValues></_></weakClassifiers></_></stages>
|
| 1096 |
-
<features>
|
| 1097 |
-
<_>
|
| 1098 |
-
<rect>
|
| 1099 |
-
0 0 3 5</rect></_>
|
| 1100 |
-
<_>
|
| 1101 |
-
<rect>
|
| 1102 |
-
0 0 4 2</rect></_>
|
| 1103 |
-
<_>
|
| 1104 |
-
<rect>
|
| 1105 |
-
0 0 6 3</rect></_>
|
| 1106 |
-
<_>
|
| 1107 |
-
<rect>
|
| 1108 |
-
0 1 2 3</rect></_>
|
| 1109 |
-
<_>
|
| 1110 |
-
<rect>
|
| 1111 |
-
0 1 3 3</rect></_>
|
| 1112 |
-
<_>
|
| 1113 |
-
<rect>
|
| 1114 |
-
0 1 3 7</rect></_>
|
| 1115 |
-
<_>
|
| 1116 |
-
<rect>
|
| 1117 |
-
0 4 3 3</rect></_>
|
| 1118 |
-
<_>
|
| 1119 |
-
<rect>
|
| 1120 |
-
0 11 3 4</rect></_>
|
| 1121 |
-
<_>
|
| 1122 |
-
<rect>
|
| 1123 |
-
0 12 8 4</rect></_>
|
| 1124 |
-
<_>
|
| 1125 |
-
<rect>
|
| 1126 |
-
0 14 4 3</rect></_>
|
| 1127 |
-
<_>
|
| 1128 |
-
<rect>
|
| 1129 |
-
1 0 5 3</rect></_>
|
| 1130 |
-
<_>
|
| 1131 |
-
<rect>
|
| 1132 |
-
1 1 2 2</rect></_>
|
| 1133 |
-
<_>
|
| 1134 |
-
<rect>
|
| 1135 |
-
1 3 3 1</rect></_>
|
| 1136 |
-
<_>
|
| 1137 |
-
<rect>
|
| 1138 |
-
1 7 4 4</rect></_>
|
| 1139 |
-
<_>
|
| 1140 |
-
<rect>
|
| 1141 |
-
1 12 2 2</rect></_>
|
| 1142 |
-
<_>
|
| 1143 |
-
<rect>
|
| 1144 |
-
1 13 4 1</rect></_>
|
| 1145 |
-
<_>
|
| 1146 |
-
<rect>
|
| 1147 |
-
1 14 4 3</rect></_>
|
| 1148 |
-
<_>
|
| 1149 |
-
<rect>
|
| 1150 |
-
1 17 3 2</rect></_>
|
| 1151 |
-
<_>
|
| 1152 |
-
<rect>
|
| 1153 |
-
2 0 2 3</rect></_>
|
| 1154 |
-
<_>
|
| 1155 |
-
<rect>
|
| 1156 |
-
2 1 2 2</rect></_>
|
| 1157 |
-
<_>
|
| 1158 |
-
<rect>
|
| 1159 |
-
2 2 4 6</rect></_>
|
| 1160 |
-
<_>
|
| 1161 |
-
<rect>
|
| 1162 |
-
2 3 4 4</rect></_>
|
| 1163 |
-
<_>
|
| 1164 |
-
<rect>
|
| 1165 |
-
2 7 2 1</rect></_>
|
| 1166 |
-
<_>
|
| 1167 |
-
<rect>
|
| 1168 |
-
2 11 2 3</rect></_>
|
| 1169 |
-
<_>
|
| 1170 |
-
<rect>
|
| 1171 |
-
2 17 3 2</rect></_>
|
| 1172 |
-
<_>
|
| 1173 |
-
<rect>
|
| 1174 |
-
3 0 2 2</rect></_>
|
| 1175 |
-
<_>
|
| 1176 |
-
<rect>
|
| 1177 |
-
3 1 7 3</rect></_>
|
| 1178 |
-
<_>
|
| 1179 |
-
<rect>
|
| 1180 |
-
3 7 2 1</rect></_>
|
| 1181 |
-
<_>
|
| 1182 |
-
<rect>
|
| 1183 |
-
3 7 2 4</rect></_>
|
| 1184 |
-
<_>
|
| 1185 |
-
<rect>
|
| 1186 |
-
3 18 2 2</rect></_>
|
| 1187 |
-
<_>
|
| 1188 |
-
<rect>
|
| 1189 |
-
4 0 2 3</rect></_>
|
| 1190 |
-
<_>
|
| 1191 |
-
<rect>
|
| 1192 |
-
4 3 2 1</rect></_>
|
| 1193 |
-
<_>
|
| 1194 |
-
<rect>
|
| 1195 |
-
4 6 2 1</rect></_>
|
| 1196 |
-
<_>
|
| 1197 |
-
<rect>
|
| 1198 |
-
4 6 2 5</rect></_>
|
| 1199 |
-
<_>
|
| 1200 |
-
<rect>
|
| 1201 |
-
4 7 5 2</rect></_>
|
| 1202 |
-
<_>
|
| 1203 |
-
<rect>
|
| 1204 |
-
4 8 4 3</rect></_>
|
| 1205 |
-
<_>
|
| 1206 |
-
<rect>
|
| 1207 |
-
4 18 2 2</rect></_>
|
| 1208 |
-
<_>
|
| 1209 |
-
<rect>
|
| 1210 |
-
5 0 2 2</rect></_>
|
| 1211 |
-
<_>
|
| 1212 |
-
<rect>
|
| 1213 |
-
5 3 4 4</rect></_>
|
| 1214 |
-
<_>
|
| 1215 |
-
<rect>
|
| 1216 |
-
5 6 2 5</rect></_>
|
| 1217 |
-
<_>
|
| 1218 |
-
<rect>
|
| 1219 |
-
5 9 2 2</rect></_>
|
| 1220 |
-
<_>
|
| 1221 |
-
<rect>
|
| 1222 |
-
5 10 2 2</rect></_>
|
| 1223 |
-
<_>
|
| 1224 |
-
<rect>
|
| 1225 |
-
6 3 4 4</rect></_>
|
| 1226 |
-
<_>
|
| 1227 |
-
<rect>
|
| 1228 |
-
6 4 4 3</rect></_>
|
| 1229 |
-
<_>
|
| 1230 |
-
<rect>
|
| 1231 |
-
6 5 2 3</rect></_>
|
| 1232 |
-
<_>
|
| 1233 |
-
<rect>
|
| 1234 |
-
6 5 2 5</rect></_>
|
| 1235 |
-
<_>
|
| 1236 |
-
<rect>
|
| 1237 |
-
6 5 4 3</rect></_>
|
| 1238 |
-
<_>
|
| 1239 |
-
<rect>
|
| 1240 |
-
6 6 4 2</rect></_>
|
| 1241 |
-
<_>
|
| 1242 |
-
<rect>
|
| 1243 |
-
6 6 4 4</rect></_>
|
| 1244 |
-
<_>
|
| 1245 |
-
<rect>
|
| 1246 |
-
6 18 1 2</rect></_>
|
| 1247 |
-
<_>
|
| 1248 |
-
<rect>
|
| 1249 |
-
6 21 2 1</rect></_>
|
| 1250 |
-
<_>
|
| 1251 |
-
<rect>
|
| 1252 |
-
7 0 3 7</rect></_>
|
| 1253 |
-
<_>
|
| 1254 |
-
<rect>
|
| 1255 |
-
7 4 2 3</rect></_>
|
| 1256 |
-
<_>
|
| 1257 |
-
<rect>
|
| 1258 |
-
7 9 5 1</rect></_>
|
| 1259 |
-
<_>
|
| 1260 |
-
<rect>
|
| 1261 |
-
7 21 2 1</rect></_>
|
| 1262 |
-
<_>
|
| 1263 |
-
<rect>
|
| 1264 |
-
8 0 1 4</rect></_>
|
| 1265 |
-
<_>
|
| 1266 |
-
<rect>
|
| 1267 |
-
8 5 2 2</rect></_>
|
| 1268 |
-
<_>
|
| 1269 |
-
<rect>
|
| 1270 |
-
8 5 3 2</rect></_>
|
| 1271 |
-
<_>
|
| 1272 |
-
<rect>
|
| 1273 |
-
8 17 3 1</rect></_>
|
| 1274 |
-
<_>
|
| 1275 |
-
<rect>
|
| 1276 |
-
8 18 1 2</rect></_>
|
| 1277 |
-
<_>
|
| 1278 |
-
<rect>
|
| 1279 |
-
9 0 5 3</rect></_>
|
| 1280 |
-
<_>
|
| 1281 |
-
<rect>
|
| 1282 |
-
9 2 2 6</rect></_>
|
| 1283 |
-
<_>
|
| 1284 |
-
<rect>
|
| 1285 |
-
9 5 1 1</rect></_>
|
| 1286 |
-
<_>
|
| 1287 |
-
<rect>
|
| 1288 |
-
9 11 1 1</rect></_>
|
| 1289 |
-
<_>
|
| 1290 |
-
<rect>
|
| 1291 |
-
9 16 1 1</rect></_>
|
| 1292 |
-
<_>
|
| 1293 |
-
<rect>
|
| 1294 |
-
9 16 2 1</rect></_>
|
| 1295 |
-
<_>
|
| 1296 |
-
<rect>
|
| 1297 |
-
9 17 1 1</rect></_>
|
| 1298 |
-
<_>
|
| 1299 |
-
<rect>
|
| 1300 |
-
9 18 1 1</rect></_>
|
| 1301 |
-
<_>
|
| 1302 |
-
<rect>
|
| 1303 |
-
10 5 1 2</rect></_>
|
| 1304 |
-
<_>
|
| 1305 |
-
<rect>
|
| 1306 |
-
10 5 3 3</rect></_>
|
| 1307 |
-
<_>
|
| 1308 |
-
<rect>
|
| 1309 |
-
10 7 1 5</rect></_>
|
| 1310 |
-
<_>
|
| 1311 |
-
<rect>
|
| 1312 |
-
10 8 1 1</rect></_>
|
| 1313 |
-
<_>
|
| 1314 |
-
<rect>
|
| 1315 |
-
10 9 1 1</rect></_>
|
| 1316 |
-
<_>
|
| 1317 |
-
<rect>
|
| 1318 |
-
10 10 1 1</rect></_>
|
| 1319 |
-
<_>
|
| 1320 |
-
<rect>
|
| 1321 |
-
10 10 1 2</rect></_>
|
| 1322 |
-
<_>
|
| 1323 |
-
<rect>
|
| 1324 |
-
10 14 3 3</rect></_>
|
| 1325 |
-
<_>
|
| 1326 |
-
<rect>
|
| 1327 |
-
10 15 1 1</rect></_>
|
| 1328 |
-
<_>
|
| 1329 |
-
<rect>
|
| 1330 |
-
10 15 2 1</rect></_>
|
| 1331 |
-
<_>
|
| 1332 |
-
<rect>
|
| 1333 |
-
10 16 1 1</rect></_>
|
| 1334 |
-
<_>
|
| 1335 |
-
<rect>
|
| 1336 |
-
10 16 2 1</rect></_>
|
| 1337 |
-
<_>
|
| 1338 |
-
<rect>
|
| 1339 |
-
10 17 1 1</rect></_>
|
| 1340 |
-
<_>
|
| 1341 |
-
<rect>
|
| 1342 |
-
10 21 1 1</rect></_>
|
| 1343 |
-
<_>
|
| 1344 |
-
<rect>
|
| 1345 |
-
11 3 2 2</rect></_>
|
| 1346 |
-
<_>
|
| 1347 |
-
<rect>
|
| 1348 |
-
11 5 1 2</rect></_>
|
| 1349 |
-
<_>
|
| 1350 |
-
<rect>
|
| 1351 |
-
11 5 3 3</rect></_>
|
| 1352 |
-
<_>
|
| 1353 |
-
<rect>
|
| 1354 |
-
11 5 4 6</rect></_>
|
| 1355 |
-
<_>
|
| 1356 |
-
<rect>
|
| 1357 |
-
11 6 1 1</rect></_>
|
| 1358 |
-
<_>
|
| 1359 |
-
<rect>
|
| 1360 |
-
11 7 2 2</rect></_>
|
| 1361 |
-
<_>
|
| 1362 |
-
<rect>
|
| 1363 |
-
11 8 1 2</rect></_>
|
| 1364 |
-
<_>
|
| 1365 |
-
<rect>
|
| 1366 |
-
11 10 1 1</rect></_>
|
| 1367 |
-
<_>
|
| 1368 |
-
<rect>
|
| 1369 |
-
11 10 1 2</rect></_>
|
| 1370 |
-
<_>
|
| 1371 |
-
<rect>
|
| 1372 |
-
11 15 1 1</rect></_>
|
| 1373 |
-
<_>
|
| 1374 |
-
<rect>
|
| 1375 |
-
11 17 1 1</rect></_>
|
| 1376 |
-
<_>
|
| 1377 |
-
<rect>
|
| 1378 |
-
11 18 1 1</rect></_>
|
| 1379 |
-
<_>
|
| 1380 |
-
<rect>
|
| 1381 |
-
12 0 2 2</rect></_>
|
| 1382 |
-
<_>
|
| 1383 |
-
<rect>
|
| 1384 |
-
12 1 2 5</rect></_>
|
| 1385 |
-
<_>
|
| 1386 |
-
<rect>
|
| 1387 |
-
12 2 4 1</rect></_>
|
| 1388 |
-
<_>
|
| 1389 |
-
<rect>
|
| 1390 |
-
12 3 1 3</rect></_>
|
| 1391 |
-
<_>
|
| 1392 |
-
<rect>
|
| 1393 |
-
12 7 3 4</rect></_>
|
| 1394 |
-
<_>
|
| 1395 |
-
<rect>
|
| 1396 |
-
12 10 3 2</rect></_>
|
| 1397 |
-
<_>
|
| 1398 |
-
<rect>
|
| 1399 |
-
12 11 1 1</rect></_>
|
| 1400 |
-
<_>
|
| 1401 |
-
<rect>
|
| 1402 |
-
12 12 3 2</rect></_>
|
| 1403 |
-
<_>
|
| 1404 |
-
<rect>
|
| 1405 |
-
12 14 4 3</rect></_>
|
| 1406 |
-
<_>
|
| 1407 |
-
<rect>
|
| 1408 |
-
12 17 1 1</rect></_>
|
| 1409 |
-
<_>
|
| 1410 |
-
<rect>
|
| 1411 |
-
12 21 2 1</rect></_>
|
| 1412 |
-
<_>
|
| 1413 |
-
<rect>
|
| 1414 |
-
13 6 2 5</rect></_>
|
| 1415 |
-
<_>
|
| 1416 |
-
<rect>
|
| 1417 |
-
13 7 3 5</rect></_>
|
| 1418 |
-
<_>
|
| 1419 |
-
<rect>
|
| 1420 |
-
13 11 3 2</rect></_>
|
| 1421 |
-
<_>
|
| 1422 |
-
<rect>
|
| 1423 |
-
13 17 2 2</rect></_>
|
| 1424 |
-
<_>
|
| 1425 |
-
<rect>
|
| 1426 |
-
13 17 3 2</rect></_>
|
| 1427 |
-
<_>
|
| 1428 |
-
<rect>
|
| 1429 |
-
13 18 1 2</rect></_>
|
| 1430 |
-
<_>
|
| 1431 |
-
<rect>
|
| 1432 |
-
13 18 2 2</rect></_>
|
| 1433 |
-
<_>
|
| 1434 |
-
<rect>
|
| 1435 |
-
14 0 2 2</rect></_>
|
| 1436 |
-
<_>
|
| 1437 |
-
<rect>
|
| 1438 |
-
14 1 1 3</rect></_>
|
| 1439 |
-
<_>
|
| 1440 |
-
<rect>
|
| 1441 |
-
14 2 3 2</rect></_>
|
| 1442 |
-
<_>
|
| 1443 |
-
<rect>
|
| 1444 |
-
14 7 2 1</rect></_>
|
| 1445 |
-
<_>
|
| 1446 |
-
<rect>
|
| 1447 |
-
14 13 2 1</rect></_>
|
| 1448 |
-
<_>
|
| 1449 |
-
<rect>
|
| 1450 |
-
14 13 3 3</rect></_>
|
| 1451 |
-
<_>
|
| 1452 |
-
<rect>
|
| 1453 |
-
14 17 2 2</rect></_>
|
| 1454 |
-
<_>
|
| 1455 |
-
<rect>
|
| 1456 |
-
15 0 2 2</rect></_>
|
| 1457 |
-
<_>
|
| 1458 |
-
<rect>
|
| 1459 |
-
15 0 2 3</rect></_>
|
| 1460 |
-
<_>
|
| 1461 |
-
<rect>
|
| 1462 |
-
15 4 3 2</rect></_>
|
| 1463 |
-
<_>
|
| 1464 |
-
<rect>
|
| 1465 |
-
15 4 3 6</rect></_>
|
| 1466 |
-
<_>
|
| 1467 |
-
<rect>
|
| 1468 |
-
15 6 3 2</rect></_>
|
| 1469 |
-
<_>
|
| 1470 |
-
<rect>
|
| 1471 |
-
15 11 3 4</rect></_>
|
| 1472 |
-
<_>
|
| 1473 |
-
<rect>
|
| 1474 |
-
15 13 3 2</rect></_>
|
| 1475 |
-
<_>
|
| 1476 |
-
<rect>
|
| 1477 |
-
15 17 2 2</rect></_>
|
| 1478 |
-
<_>
|
| 1479 |
-
<rect>
|
| 1480 |
-
15 17 3 2</rect></_>
|
| 1481 |
-
<_>
|
| 1482 |
-
<rect>
|
| 1483 |
-
16 1 2 3</rect></_>
|
| 1484 |
-
<_>
|
| 1485 |
-
<rect>
|
| 1486 |
-
16 3 2 4</rect></_>
|
| 1487 |
-
<_>
|
| 1488 |
-
<rect>
|
| 1489 |
-
16 6 1 1</rect></_>
|
| 1490 |
-
<_>
|
| 1491 |
-
<rect>
|
| 1492 |
-
16 16 2 2</rect></_>
|
| 1493 |
-
<_>
|
| 1494 |
-
<rect>
|
| 1495 |
-
17 1 2 2</rect></_>
|
| 1496 |
-
<_>
|
| 1497 |
-
<rect>
|
| 1498 |
-
17 1 2 5</rect></_>
|
| 1499 |
-
<_>
|
| 1500 |
-
<rect>
|
| 1501 |
-
17 12 2 2</rect></_>
|
| 1502 |
-
<_>
|
| 1503 |
-
<rect>
|
| 1504 |
-
18 0 2 2</rect></_></features></cascade>
|
| 1505 |
-
</opencv_storage>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/simple_test.py
DELETED
|
@@ -1,65 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Ultra-simple test to check face recognition
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
print("Starting Face Recognition Test...")
|
| 6 |
-
|
| 7 |
-
try:
|
| 8 |
-
import os
|
| 9 |
-
print(f"Current directory: {os.getcwd()}")
|
| 10 |
-
|
| 11 |
-
# Check model files
|
| 12 |
-
model_files = ['siamese_model.t7', 'decision_tree_model.sav', 'face_recognition_scaler.sav']
|
| 13 |
-
for file in model_files:
|
| 14 |
-
if os.path.exists(file):
|
| 15 |
-
print(f"✓ {file} exists")
|
| 16 |
-
else:
|
| 17 |
-
print(f"✗ {file} missing")
|
| 18 |
-
|
| 19 |
-
# Try to import
|
| 20 |
-
print("\nTrying to import face_recognition...")
|
| 21 |
-
from face_recognition import get_face_class, CLASS_NAMES
|
| 22 |
-
print(f"✓ Imported successfully")
|
| 23 |
-
print(f"CLASS_NAMES: {CLASS_NAMES}")
|
| 24 |
-
|
| 25 |
-
# Test with simple image
|
| 26 |
-
print("\nTesting with simple image...")
|
| 27 |
-
import numpy as np
|
| 28 |
-
import cv2
|
| 29 |
-
|
| 30 |
-
# Create simple test image
|
| 31 |
-
test_img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 32 |
-
cv2.ellipse(test_img, (50, 50), (40, 50), 0, 0, 360, (100, 100, 100), -1)
|
| 33 |
-
cv2.circle(test_img, (35, 40), 5, (200, 200, 200), -1)
|
| 34 |
-
cv2.circle(test_img, (65, 40), 5, (200, 200, 200), -1)
|
| 35 |
-
|
| 36 |
-
print(f"Created test image: {test_img.shape}")
|
| 37 |
-
|
| 38 |
-
# Test classification
|
| 39 |
-
result = get_face_class(test_img)
|
| 40 |
-
print(f"Classification result: {result}")
|
| 41 |
-
|
| 42 |
-
if result == "UNKNOWN_CLASS":
|
| 43 |
-
print("❌ Still getting UNKNOWN_CLASS!")
|
| 44 |
-
|
| 45 |
-
# Debug further
|
| 46 |
-
print("\nDebugging...")
|
| 47 |
-
import joblib
|
| 48 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 49 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 50 |
-
|
| 51 |
-
print(f"Classifier classes: {classifier.classes_}")
|
| 52 |
-
print(f"Scaler features: {scaler.n_features_in_}")
|
| 53 |
-
print(f"CLASS_NAMES length: {len(CLASS_NAMES)}")
|
| 54 |
-
|
| 55 |
-
elif result in CLASS_NAMES:
|
| 56 |
-
print(f"✅ Success! Classified as: {result}")
|
| 57 |
-
else:
|
| 58 |
-
print(f"? Unexpected result: {result}")
|
| 59 |
-
|
| 60 |
-
except Exception as e:
|
| 61 |
-
print(f"❌ Error: {e}")
|
| 62 |
-
import traceback
|
| 63 |
-
traceback.print_exc()
|
| 64 |
-
|
| 65 |
-
print("\nTest completed!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_all_classes.py
DELETED
|
@@ -1,85 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test all possible class predictions to ensure no UNKNOWN_CLASS
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import numpy as np
|
| 6 |
-
import cv2
|
| 7 |
-
from face_recognition import get_face_class
|
| 8 |
-
import joblib
|
| 9 |
-
|
| 10 |
-
def test_all_class_predictions():
|
| 11 |
-
"""Test that all classifier predictions map to valid class names"""
|
| 12 |
-
print("Testing All Class Predictions")
|
| 13 |
-
print("=" * 40)
|
| 14 |
-
|
| 15 |
-
try:
|
| 16 |
-
# Load the classifier directly
|
| 17 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 18 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 19 |
-
|
| 20 |
-
print(f"Classifier classes: {classifier.classes_}")
|
| 21 |
-
print(f"Number of classes: {len(classifier.classes_)}")
|
| 22 |
-
|
| 23 |
-
# Test each possible class prediction
|
| 24 |
-
for class_idx in classifier.classes_:
|
| 25 |
-
print(f"\nTesting class {class_idx}:")
|
| 26 |
-
|
| 27 |
-
# Create a dummy embedding that would predict this class
|
| 28 |
-
# We'll create embeddings and see what the classifier predicts
|
| 29 |
-
dummy_embedding = np.random.randn(1, 5) # 5 features based on scaler
|
| 30 |
-
|
| 31 |
-
# Scale the embedding
|
| 32 |
-
scaled_embedding = scaler.transform(dummy_embedding)
|
| 33 |
-
|
| 34 |
-
# Get prediction
|
| 35 |
-
prediction = classifier.predict(scaled_embedding)[0]
|
| 36 |
-
|
| 37 |
-
# Map to class name
|
| 38 |
-
from face_recognition import CLASS_NAMES
|
| 39 |
-
if prediction < len(CLASS_NAMES):
|
| 40 |
-
class_name = CLASS_NAMES[prediction]
|
| 41 |
-
print(f" Prediction: {prediction} -> {class_name}")
|
| 42 |
-
else:
|
| 43 |
-
print(f" Prediction: {prediction} -> UNKNOWN_CLASS (ERROR!)")
|
| 44 |
-
|
| 45 |
-
print(f"\nCLASS_NAMES: {CLASS_NAMES}")
|
| 46 |
-
print(f"Number of CLASS_NAMES: {len(CLASS_NAMES)}")
|
| 47 |
-
|
| 48 |
-
# Test with actual face images
|
| 49 |
-
print("\nTesting with face images...")
|
| 50 |
-
for i in range(5):
|
| 51 |
-
# Create different face-like images
|
| 52 |
-
face_img = create_varied_face_image(i)
|
| 53 |
-
result = get_face_class(face_img)
|
| 54 |
-
print(f"Face image {i+1}: {result}")
|
| 55 |
-
|
| 56 |
-
except Exception as e:
|
| 57 |
-
print(f"Error: {e}")
|
| 58 |
-
import traceback
|
| 59 |
-
traceback.print_exc()
|
| 60 |
-
|
| 61 |
-
def create_varied_face_image(variation):
|
| 62 |
-
"""Create different face-like images for testing"""
|
| 63 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 64 |
-
|
| 65 |
-
# Vary the face features based on variation
|
| 66 |
-
eye_offset = variation * 5
|
| 67 |
-
mouth_offset = variation * 3
|
| 68 |
-
|
| 69 |
-
# Face outline (oval)
|
| 70 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (100, 100, 100), -1)
|
| 71 |
-
|
| 72 |
-
# Eyes (varied position)
|
| 73 |
-
cv2.circle(img, (35 + eye_offset, 40), 5, (200, 200, 200), -1)
|
| 74 |
-
cv2.circle(img, (65 - eye_offset, 40), 5, (200, 200, 200), -1)
|
| 75 |
-
|
| 76 |
-
# Nose
|
| 77 |
-
cv2.line(img, (50, 45), (50, 60), (150, 150, 150), 2)
|
| 78 |
-
|
| 79 |
-
# Mouth (varied position)
|
| 80 |
-
cv2.ellipse(img, (50, 70 + mouth_offset), (15, 8), 0, 0, 180, (150, 150, 150), 2)
|
| 81 |
-
|
| 82 |
-
return img
|
| 83 |
-
|
| 84 |
-
if __name__ == "__main__":
|
| 85 |
-
test_all_class_predictions()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_api.py
DELETED
|
@@ -1,132 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test script for the deployed Hugging Face API
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import requests
|
| 6 |
-
import base64
|
| 7 |
-
import numpy as np
|
| 8 |
-
import cv2
|
| 9 |
-
from PIL import Image
|
| 10 |
-
import io
|
| 11 |
-
|
| 12 |
-
def create_test_image():
|
| 13 |
-
"""Create a test image for API testing"""
|
| 14 |
-
# Create a simple test image
|
| 15 |
-
img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 16 |
-
|
| 17 |
-
# Convert to PIL Image
|
| 18 |
-
pil_img = Image.fromarray(img)
|
| 19 |
-
|
| 20 |
-
# Convert to base64
|
| 21 |
-
buffer = io.BytesIO()
|
| 22 |
-
pil_img.save(buffer, format='JPEG')
|
| 23 |
-
img_str = base64.b64encode(buffer.getvalue()).decode()
|
| 24 |
-
|
| 25 |
-
return img_str
|
| 26 |
-
|
| 27 |
-
def test_api_similarity():
|
| 28 |
-
"""Test the similarity API endpoint"""
|
| 29 |
-
url = "https://pavaniyerra-hackthon4.hf.space/predict_similarity/"
|
| 30 |
-
|
| 31 |
-
print("Testing Hugging Face API...")
|
| 32 |
-
print("=" * 40)
|
| 33 |
-
|
| 34 |
-
try:
|
| 35 |
-
# Create two test images
|
| 36 |
-
img1_b64 = create_test_image()
|
| 37 |
-
img2_b64 = create_test_image()
|
| 38 |
-
|
| 39 |
-
# Prepare the request data - API expects file1 and file2
|
| 40 |
-
data = {
|
| 41 |
-
"file1": img1_b64,
|
| 42 |
-
"file2": img2_b64
|
| 43 |
-
}
|
| 44 |
-
|
| 45 |
-
print("Sending request to API...")
|
| 46 |
-
response = requests.post(url, json=data, timeout=30)
|
| 47 |
-
|
| 48 |
-
if response.status_code == 200:
|
| 49 |
-
result = response.json()
|
| 50 |
-
print("SUCCESS: API Response received successfully!")
|
| 51 |
-
print(f"Similarity Score: {result}")
|
| 52 |
-
|
| 53 |
-
# Interpret the similarity score
|
| 54 |
-
if isinstance(result, (int, float)):
|
| 55 |
-
if result > 0.8:
|
| 56 |
-
print("Result: Very High Similarity (likely same person)")
|
| 57 |
-
elif result > 0.6:
|
| 58 |
-
print("Result: High Similarity (possibly same person)")
|
| 59 |
-
elif result > 0.4:
|
| 60 |
-
print("Result: Moderate Similarity (uncertain)")
|
| 61 |
-
elif result > 0.2:
|
| 62 |
-
print("Result: Low Similarity (likely different persons)")
|
| 63 |
-
else:
|
| 64 |
-
print("Result: Very Low Similarity (definitely different persons)")
|
| 65 |
-
else:
|
| 66 |
-
print(f"Unexpected response format: {result}")
|
| 67 |
-
|
| 68 |
-
else:
|
| 69 |
-
print(f"ERROR: API Error: {response.status_code}")
|
| 70 |
-
print(f"Response: {response.text}")
|
| 71 |
-
|
| 72 |
-
except requests.exceptions.RequestException as e:
|
| 73 |
-
print(f"ERROR: Network Error: {e}")
|
| 74 |
-
except Exception as e:
|
| 75 |
-
print(f"ERROR: Error: {e}")
|
| 76 |
-
|
| 77 |
-
def test_api_classification():
|
| 78 |
-
"""Test the classification API endpoint (if available)"""
|
| 79 |
-
# Try different possible endpoints
|
| 80 |
-
possible_urls = [
|
| 81 |
-
"https://pavaniyerra-hackthon4.hf.space/predict_class/",
|
| 82 |
-
"https://pavaniyerra-hackthon4.hf.space/classify/",
|
| 83 |
-
"https://pavaniyerra-hackthon4.hf.space/predict/"
|
| 84 |
-
]
|
| 85 |
-
|
| 86 |
-
print("\nTesting Classification API...")
|
| 87 |
-
print("=" * 40)
|
| 88 |
-
|
| 89 |
-
for url in possible_urls:
|
| 90 |
-
try:
|
| 91 |
-
# Create a test image
|
| 92 |
-
img_b64 = create_test_image()
|
| 93 |
-
|
| 94 |
-
# Prepare the request data - try different parameter names
|
| 95 |
-
data = {
|
| 96 |
-
"file": img_b64
|
| 97 |
-
}
|
| 98 |
-
|
| 99 |
-
print(f"Trying endpoint: {url}")
|
| 100 |
-
response = requests.post(url, json=data, timeout=30)
|
| 101 |
-
|
| 102 |
-
if response.status_code == 200:
|
| 103 |
-
result = response.json()
|
| 104 |
-
print("SUCCESS: Classification API Response received successfully!")
|
| 105 |
-
print(f"Predicted Class: {result}")
|
| 106 |
-
return
|
| 107 |
-
else:
|
| 108 |
-
print(f"ERROR: {response.status_code} - {response.text[:100]}...")
|
| 109 |
-
|
| 110 |
-
except requests.exceptions.RequestException as e:
|
| 111 |
-
print(f"ERROR: Network Error for {url}: {e}")
|
| 112 |
-
except Exception as e:
|
| 113 |
-
print(f"ERROR: Error for {url}: {e}")
|
| 114 |
-
|
| 115 |
-
print("No working classification endpoint found.")
|
| 116 |
-
|
| 117 |
-
if __name__ == "__main__":
|
| 118 |
-
print("Hugging Face API Test")
|
| 119 |
-
print("=" * 50)
|
| 120 |
-
print(f"API URL: https://pavaniyerra-hackthon4.hf.space/predict_similarity/")
|
| 121 |
-
print()
|
| 122 |
-
|
| 123 |
-
# Test similarity API
|
| 124 |
-
test_api_similarity()
|
| 125 |
-
|
| 126 |
-
# Test classification API (if available)
|
| 127 |
-
test_api_classification()
|
| 128 |
-
|
| 129 |
-
print("\n" + "=" * 50)
|
| 130 |
-
print("API Testing Complete!")
|
| 131 |
-
print("\nNote: This test uses random images.")
|
| 132 |
-
print("For real testing, use actual face images.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_api_fixed.py
DELETED
|
@@ -1,142 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Fixed test script for the deployed Hugging Face API
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import requests
|
| 6 |
-
import base64
|
| 7 |
-
import numpy as np
|
| 8 |
-
from PIL import Image
|
| 9 |
-
import io
|
| 10 |
-
|
| 11 |
-
def create_test_image():
|
| 12 |
-
"""Create a test image for API testing"""
|
| 13 |
-
# Create a simple test image
|
| 14 |
-
img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 15 |
-
|
| 16 |
-
# Convert to PIL Image
|
| 17 |
-
pil_img = Image.fromarray(img)
|
| 18 |
-
|
| 19 |
-
# Convert to base64
|
| 20 |
-
buffer = io.BytesIO()
|
| 21 |
-
pil_img.save(buffer, format='JPEG')
|
| 22 |
-
img_str = base64.b64encode(buffer.getvalue()).decode()
|
| 23 |
-
|
| 24 |
-
return img_str
|
| 25 |
-
|
| 26 |
-
def test_api_with_form_data():
|
| 27 |
-
"""Test the API using form data (multipart/form-data)"""
|
| 28 |
-
url = "https://pavaniyerra-hackthon4.hf.space/predict_similarity/"
|
| 29 |
-
|
| 30 |
-
print("Testing API with form data...")
|
| 31 |
-
print("=" * 40)
|
| 32 |
-
|
| 33 |
-
try:
|
| 34 |
-
# Create test images
|
| 35 |
-
img1_b64 = create_test_image()
|
| 36 |
-
img2_b64 = create_test_image()
|
| 37 |
-
|
| 38 |
-
# Convert base64 to bytes
|
| 39 |
-
img1_bytes = base64.b64decode(img1_b64)
|
| 40 |
-
img2_bytes = base64.b64decode(img2_b64)
|
| 41 |
-
|
| 42 |
-
# Prepare files for form data
|
| 43 |
-
files = {
|
| 44 |
-
'file1': ('image1.jpg', img1_bytes, 'image/jpeg'),
|
| 45 |
-
'file2': ('image2.jpg', img2_bytes, 'image/jpeg')
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
print("Sending request with form data...")
|
| 49 |
-
response = requests.post(url, files=files, timeout=30)
|
| 50 |
-
|
| 51 |
-
print(f"Status Code: {response.status_code}")
|
| 52 |
-
print(f"Response Headers: {dict(response.headers)}")
|
| 53 |
-
print(f"Response Text: {response.text}")
|
| 54 |
-
|
| 55 |
-
if response.status_code == 200:
|
| 56 |
-
try:
|
| 57 |
-
result = response.json()
|
| 58 |
-
print("SUCCESS: API Response received successfully!")
|
| 59 |
-
print(f"Similarity Score: {result}")
|
| 60 |
-
except:
|
| 61 |
-
print(f"Response (not JSON): {response.text}")
|
| 62 |
-
else:
|
| 63 |
-
print(f"ERROR: API Error: {response.status_code}")
|
| 64 |
-
|
| 65 |
-
except Exception as e:
|
| 66 |
-
print(f"ERROR: {e}")
|
| 67 |
-
|
| 68 |
-
def test_api_with_json():
|
| 69 |
-
"""Test the API using JSON data"""
|
| 70 |
-
url = "https://pavaniyerra-hackthon4.hf.space/predict_similarity/"
|
| 71 |
-
|
| 72 |
-
print("\nTesting API with JSON data...")
|
| 73 |
-
print("=" * 40)
|
| 74 |
-
|
| 75 |
-
try:
|
| 76 |
-
# Create test images
|
| 77 |
-
img1_b64 = create_test_image()
|
| 78 |
-
img2_b64 = create_test_image()
|
| 79 |
-
|
| 80 |
-
# Try different JSON formats
|
| 81 |
-
json_formats = [
|
| 82 |
-
{"file1": img1_b64, "file2": img2_b64},
|
| 83 |
-
{"img1": img1_b64, "img2": img2_b64},
|
| 84 |
-
{"image1": img1_b64, "image2": img2_b64},
|
| 85 |
-
{"files": [img1_b64, img2_b64]},
|
| 86 |
-
{"data": {"file1": img1_b64, "file2": img2_b64}}
|
| 87 |
-
]
|
| 88 |
-
|
| 89 |
-
for i, data in enumerate(json_formats):
|
| 90 |
-
print(f"\nTrying JSON format {i+1}: {list(data.keys())}")
|
| 91 |
-
response = requests.post(url, json=data, timeout=30)
|
| 92 |
-
print(f"Status: {response.status_code}")
|
| 93 |
-
if response.status_code == 200:
|
| 94 |
-
print("SUCCESS!")
|
| 95 |
-
print(f"Response: {response.text}")
|
| 96 |
-
break
|
| 97 |
-
else:
|
| 98 |
-
print(f"Error: {response.text[:200]}...")
|
| 99 |
-
|
| 100 |
-
except Exception as e:
|
| 101 |
-
print(f"ERROR: {e}")
|
| 102 |
-
|
| 103 |
-
def test_api_info():
|
| 104 |
-
"""Get information about the API"""
|
| 105 |
-
base_url = "https://pavaniyerra-hackthon4.hf.space"
|
| 106 |
-
|
| 107 |
-
print("\nGetting API information...")
|
| 108 |
-
print("=" * 40)
|
| 109 |
-
|
| 110 |
-
try:
|
| 111 |
-
# Try to get API info
|
| 112 |
-
response = requests.get(base_url, timeout=30)
|
| 113 |
-
print(f"Base URL Status: {response.status_code}")
|
| 114 |
-
|
| 115 |
-
# Try common endpoints
|
| 116 |
-
endpoints = ["/", "/docs", "/openapi.json", "/info", "/health"]
|
| 117 |
-
for endpoint in endpoints:
|
| 118 |
-
try:
|
| 119 |
-
url = base_url + endpoint
|
| 120 |
-
response = requests.get(url, timeout=10)
|
| 121 |
-
print(f"{endpoint}: {response.status_code}")
|
| 122 |
-
if response.status_code == 200 and len(response.text) < 500:
|
| 123 |
-
print(f" Content: {response.text[:100]}...")
|
| 124 |
-
except:
|
| 125 |
-
print(f"{endpoint}: Error")
|
| 126 |
-
|
| 127 |
-
except Exception as e:
|
| 128 |
-
print(f"ERROR: {e}")
|
| 129 |
-
|
| 130 |
-
if __name__ == "__main__":
|
| 131 |
-
print("Hugging Face API Test - Fixed Version")
|
| 132 |
-
print("=" * 50)
|
| 133 |
-
print(f"API URL: https://pavaniyerra-hackthon4.hf.space/predict_similarity/")
|
| 134 |
-
print()
|
| 135 |
-
|
| 136 |
-
# Test different approaches
|
| 137 |
-
test_api_with_form_data()
|
| 138 |
-
test_api_with_json()
|
| 139 |
-
test_api_info()
|
| 140 |
-
|
| 141 |
-
print("\n" + "=" * 50)
|
| 142 |
-
print("API Testing Complete!")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_api_simple.py
DELETED
|
@@ -1,172 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Simple API test script that extracts the numerical score
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import requests
|
| 6 |
-
import base64
|
| 7 |
-
import numpy as np
|
| 8 |
-
import cv2
|
| 9 |
-
from PIL import Image
|
| 10 |
-
import io
|
| 11 |
-
import re
|
| 12 |
-
|
| 13 |
-
def create_face_image():
|
| 14 |
-
"""Create a simple face-like image"""
|
| 15 |
-
img = np.zeros((100, 100), dtype=np.uint8)
|
| 16 |
-
|
| 17 |
-
# Face outline
|
| 18 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, 100, -1)
|
| 19 |
-
|
| 20 |
-
# Eyes
|
| 21 |
-
cv2.circle(img, (35, 40), 5, 200, -1)
|
| 22 |
-
cv2.circle(img, (65, 40), 5, 200, -1)
|
| 23 |
-
|
| 24 |
-
# Nose
|
| 25 |
-
cv2.line(img, (50, 45), (50, 60), 150, 2)
|
| 26 |
-
|
| 27 |
-
# Mouth
|
| 28 |
-
cv2.ellipse(img, (50, 70), (15, 8), 0, 0, 180, 150, 2)
|
| 29 |
-
|
| 30 |
-
# Convert to RGB
|
| 31 |
-
img_rgb = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
|
| 32 |
-
return img_rgb
|
| 33 |
-
|
| 34 |
-
def test_api():
|
| 35 |
-
"""Test the API and extract the score"""
|
| 36 |
-
url = "https://pavaniyerra-hackthon4.hf.space/predict_similarity/"
|
| 37 |
-
|
| 38 |
-
print("Testing Face Similarity API")
|
| 39 |
-
print("=" * 40)
|
| 40 |
-
|
| 41 |
-
try:
|
| 42 |
-
# Create two test face images
|
| 43 |
-
face1 = create_face_image()
|
| 44 |
-
face2 = create_face_image()
|
| 45 |
-
|
| 46 |
-
# Convert to bytes
|
| 47 |
-
def img_to_bytes(img):
|
| 48 |
-
pil_img = Image.fromarray(img)
|
| 49 |
-
buffer = io.BytesIO()
|
| 50 |
-
pil_img.save(buffer, format='JPEG')
|
| 51 |
-
return buffer.getvalue()
|
| 52 |
-
|
| 53 |
-
face1_bytes = img_to_bytes(face1)
|
| 54 |
-
face2_bytes = img_to_bytes(face2)
|
| 55 |
-
|
| 56 |
-
# Prepare files for upload
|
| 57 |
-
files = {
|
| 58 |
-
'file1': ('face1.jpg', face1_bytes, 'image/jpeg'),
|
| 59 |
-
'file2': ('face2.jpg', face2_bytes, 'image/jpeg')
|
| 60 |
-
}
|
| 61 |
-
|
| 62 |
-
print("Sending request to API...")
|
| 63 |
-
response = requests.post(url, files=files, timeout=30)
|
| 64 |
-
|
| 65 |
-
print(f"Status Code: {response.status_code}")
|
| 66 |
-
|
| 67 |
-
if response.status_code == 200:
|
| 68 |
-
print("SUCCESS! API is working")
|
| 69 |
-
|
| 70 |
-
# Extract the dissimilarity score from HTML
|
| 71 |
-
html_content = response.text
|
| 72 |
-
|
| 73 |
-
# Look for the dissimilarity score in the HTML
|
| 74 |
-
# Pattern: "Dissimilarity: X.X"
|
| 75 |
-
pattern = r'Dissimilarity:</span>\s*<span[^>]*>\s*([0-9.]+)'
|
| 76 |
-
match = re.search(pattern, html_content)
|
| 77 |
-
|
| 78 |
-
if match:
|
| 79 |
-
score = float(match.group(1))
|
| 80 |
-
print(f"Dissimilarity Score: {score}")
|
| 81 |
-
|
| 82 |
-
# Convert dissimilarity to similarity (assuming 1.0 = completely different, 0.0 = identical)
|
| 83 |
-
similarity = 1.0 - score
|
| 84 |
-
print(f"Similarity Score: {similarity:.4f}")
|
| 85 |
-
|
| 86 |
-
# Interpret the result
|
| 87 |
-
if similarity > 0.8:
|
| 88 |
-
print("Result: Very High Similarity (likely same person)")
|
| 89 |
-
elif similarity > 0.6:
|
| 90 |
-
print("Result: High Similarity (possibly same person)")
|
| 91 |
-
elif similarity > 0.4:
|
| 92 |
-
print("Result: Moderate Similarity (uncertain)")
|
| 93 |
-
elif similarity > 0.2:
|
| 94 |
-
print("Result: Low Similarity (likely different persons)")
|
| 95 |
-
else:
|
| 96 |
-
print("Result: Very Low Similarity (definitely different persons)")
|
| 97 |
-
else:
|
| 98 |
-
print("WARNING: Could not extract score from HTML response")
|
| 99 |
-
print("HTML content preview:")
|
| 100 |
-
print(html_content[:500] + "..." if len(html_content) > 500 else html_content)
|
| 101 |
-
else:
|
| 102 |
-
print(f"ERROR: {response.status_code}")
|
| 103 |
-
print(f"Response: {response.text}")
|
| 104 |
-
|
| 105 |
-
except Exception as e:
|
| 106 |
-
print(f"ERROR: {e}")
|
| 107 |
-
|
| 108 |
-
def test_multiple_times():
|
| 109 |
-
"""Test the API multiple times to check consistency"""
|
| 110 |
-
print("\n" + "=" * 40)
|
| 111 |
-
print("Testing API Multiple Times")
|
| 112 |
-
print("=" * 40)
|
| 113 |
-
|
| 114 |
-
scores = []
|
| 115 |
-
for i in range(3):
|
| 116 |
-
print(f"\nTest {i+1}/3:")
|
| 117 |
-
try:
|
| 118 |
-
face1 = create_face_image()
|
| 119 |
-
face2 = create_face_image()
|
| 120 |
-
|
| 121 |
-
def img_to_bytes(img):
|
| 122 |
-
pil_img = Image.fromarray(img)
|
| 123 |
-
buffer = io.BytesIO()
|
| 124 |
-
pil_img.save(buffer, format='JPEG')
|
| 125 |
-
return buffer.getvalue()
|
| 126 |
-
|
| 127 |
-
files = {
|
| 128 |
-
'file1': ('face1.jpg', img_to_bytes(face1), 'image/jpeg'),
|
| 129 |
-
'file2': ('face2.jpg', img_to_bytes(face2), 'image/jpeg')
|
| 130 |
-
}
|
| 131 |
-
|
| 132 |
-
response = requests.post("https://pavaniyerra-hackthon4.hf.space/predict_similarity/",
|
| 133 |
-
files=files, timeout=30)
|
| 134 |
-
|
| 135 |
-
if response.status_code == 200:
|
| 136 |
-
# Extract score
|
| 137 |
-
pattern = r'Dissimilarity:</span>\s*<span[^>]*>\s*([0-9.]+)'
|
| 138 |
-
match = re.search(pattern, response.text)
|
| 139 |
-
if match:
|
| 140 |
-
score = float(match.group(1))
|
| 141 |
-
scores.append(score)
|
| 142 |
-
print(f" Score: {score}")
|
| 143 |
-
else:
|
| 144 |
-
print(" Could not extract score")
|
| 145 |
-
else:
|
| 146 |
-
print(f" Error: {response.status_code}")
|
| 147 |
-
|
| 148 |
-
except Exception as e:
|
| 149 |
-
print(f" Error: {e}")
|
| 150 |
-
|
| 151 |
-
if scores:
|
| 152 |
-
print(f"\nScore Statistics:")
|
| 153 |
-
print(f" Average: {sum(scores)/len(scores):.4f}")
|
| 154 |
-
print(f" Min: {min(scores):.4f}")
|
| 155 |
-
print(f" Max: {max(scores):.4f}")
|
| 156 |
-
print(f" Range: {max(scores) - min(scores):.4f}")
|
| 157 |
-
|
| 158 |
-
if __name__ == "__main__":
|
| 159 |
-
# Test the API
|
| 160 |
-
test_api()
|
| 161 |
-
|
| 162 |
-
# Test multiple times for consistency
|
| 163 |
-
test_multiple_times()
|
| 164 |
-
|
| 165 |
-
print("\n" + "=" * 50)
|
| 166 |
-
print("API Testing Complete!")
|
| 167 |
-
print("\nYour API is working correctly!")
|
| 168 |
-
print("The API expects:")
|
| 169 |
-
print("- Method: POST")
|
| 170 |
-
print("- Format: multipart/form-data")
|
| 171 |
-
print("- Parameters: file1, file2 (image files)")
|
| 172 |
-
print("- Response: HTML with dissimilarity score")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_api_with_faces.py
DELETED
|
@@ -1,228 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test script for the Hugging Face API using face images
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import requests
|
| 6 |
-
import base64
|
| 7 |
-
import numpy as np
|
| 8 |
-
import cv2
|
| 9 |
-
from PIL import Image
|
| 10 |
-
import io
|
| 11 |
-
import os
|
| 12 |
-
|
| 13 |
-
def create_face_like_image():
|
| 14 |
-
"""Create a more realistic face-like image for testing"""
|
| 15 |
-
# Create a grayscale image that looks more like a face
|
| 16 |
-
img = np.zeros((100, 100), dtype=np.uint8)
|
| 17 |
-
|
| 18 |
-
# Add some face-like features
|
| 19 |
-
# Face outline (oval)
|
| 20 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, 100, -1)
|
| 21 |
-
|
| 22 |
-
# Eyes
|
| 23 |
-
cv2.circle(img, (35, 40), 5, 200, -1)
|
| 24 |
-
cv2.circle(img, (65, 40), 5, 200, -1)
|
| 25 |
-
|
| 26 |
-
# Nose
|
| 27 |
-
cv2.line(img, (50, 45), (50, 60), 150, 2)
|
| 28 |
-
|
| 29 |
-
# Mouth
|
| 30 |
-
cv2.ellipse(img, (50, 70), (15, 8), 0, 0, 180, 150, 2)
|
| 31 |
-
|
| 32 |
-
# Convert to 3-channel for consistency
|
| 33 |
-
img_rgb = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
|
| 34 |
-
|
| 35 |
-
return img_rgb
|
| 36 |
-
|
| 37 |
-
def load_real_face_image(image_path):
|
| 38 |
-
"""Load a real face image if available"""
|
| 39 |
-
if os.path.exists(image_path):
|
| 40 |
-
try:
|
| 41 |
-
img = cv2.imread(image_path)
|
| 42 |
-
if img is not None:
|
| 43 |
-
# Resize to 100x100
|
| 44 |
-
img = cv2.resize(img, (100, 100))
|
| 45 |
-
return img
|
| 46 |
-
except Exception as e:
|
| 47 |
-
print(f"Error loading image {image_path}: {e}")
|
| 48 |
-
|
| 49 |
-
return None
|
| 50 |
-
|
| 51 |
-
def image_to_base64(img):
|
| 52 |
-
"""Convert image to base64 string"""
|
| 53 |
-
if len(img.shape) == 2: # Grayscale
|
| 54 |
-
pil_img = Image.fromarray(img, mode='L')
|
| 55 |
-
else: # RGB
|
| 56 |
-
pil_img = Image.fromarray(img)
|
| 57 |
-
|
| 58 |
-
buffer = io.BytesIO()
|
| 59 |
-
pil_img.save(buffer, format='JPEG')
|
| 60 |
-
img_str = base64.b64encode(buffer.getvalue()).decode()
|
| 61 |
-
return img_str
|
| 62 |
-
|
| 63 |
-
def test_api_with_face_images():
|
| 64 |
-
"""Test the API with face-like images"""
|
| 65 |
-
url = "https://pavaniyerra-hackthon4.hf.space/predict_similarity/"
|
| 66 |
-
|
| 67 |
-
print("Testing API with face-like images...")
|
| 68 |
-
print("=" * 50)
|
| 69 |
-
|
| 70 |
-
try:
|
| 71 |
-
# Create two face-like images
|
| 72 |
-
face1 = create_face_like_image()
|
| 73 |
-
face2 = create_face_like_image()
|
| 74 |
-
|
| 75 |
-
# Convert to base64
|
| 76 |
-
face1_b64 = image_to_base64(face1)
|
| 77 |
-
face2_b64 = image_to_base64(face2)
|
| 78 |
-
|
| 79 |
-
print("Created face-like test images")
|
| 80 |
-
print(f"Image 1 shape: {face1.shape}")
|
| 81 |
-
print(f"Image 2 shape: {face2.shape}")
|
| 82 |
-
|
| 83 |
-
# Try different request formats
|
| 84 |
-
test_formats = [
|
| 85 |
-
# Format 1: JSON with file1, file2
|
| 86 |
-
{"file1": face1_b64, "file2": face2_b64},
|
| 87 |
-
# Format 2: JSON with img1, img2
|
| 88 |
-
{"img1": face1_b64, "img2": face2_b64},
|
| 89 |
-
# Format 3: JSON with image1, image2
|
| 90 |
-
{"image1": face1_b64, "image2": face2_b64},
|
| 91 |
-
# Format 4: JSON with faces array
|
| 92 |
-
{"faces": [face1_b64, face2_b64]},
|
| 93 |
-
# Format 5: JSON with data wrapper
|
| 94 |
-
{"data": {"file1": face1_b64, "file2": face2_b64}}
|
| 95 |
-
]
|
| 96 |
-
|
| 97 |
-
for i, data in enumerate(test_formats, 1):
|
| 98 |
-
print(f"\n--- Testing Format {i}: {list(data.keys())} ---")
|
| 99 |
-
|
| 100 |
-
try:
|
| 101 |
-
response = requests.post(url, json=data, timeout=30)
|
| 102 |
-
print(f"Status Code: {response.status_code}")
|
| 103 |
-
|
| 104 |
-
if response.status_code == 200:
|
| 105 |
-
try:
|
| 106 |
-
result = response.json()
|
| 107 |
-
print("SUCCESS! API Response:")
|
| 108 |
-
print(f"Similarity Score: {result}")
|
| 109 |
-
|
| 110 |
-
# Interpret the result
|
| 111 |
-
if isinstance(result, (int, float)):
|
| 112 |
-
if result > 0.8:
|
| 113 |
-
print("Result: Very High Similarity (likely same person)")
|
| 114 |
-
elif result > 0.6:
|
| 115 |
-
print("Result: High Similarity (possibly same person)")
|
| 116 |
-
elif result > 0.4:
|
| 117 |
-
print("Result: Moderate Similarity (uncertain)")
|
| 118 |
-
elif result > 0.2:
|
| 119 |
-
print("Result: Low Similarity (likely different persons)")
|
| 120 |
-
else:
|
| 121 |
-
print("Result: Very Low Similarity (definitely different persons)")
|
| 122 |
-
else:
|
| 123 |
-
print(f"Response format: {type(result)} - {result}")
|
| 124 |
-
|
| 125 |
-
return True # Success, no need to try other formats
|
| 126 |
-
|
| 127 |
-
except Exception as e:
|
| 128 |
-
print(f"Error parsing JSON response: {e}")
|
| 129 |
-
print(f"Raw response: {response.text}")
|
| 130 |
-
else:
|
| 131 |
-
print(f"Error: {response.text[:200]}...")
|
| 132 |
-
|
| 133 |
-
except requests.exceptions.RequestException as e:
|
| 134 |
-
print(f"Network error: {e}")
|
| 135 |
-
except Exception as e:
|
| 136 |
-
print(f"Error: {e}")
|
| 137 |
-
|
| 138 |
-
print("\nAll JSON formats failed. Trying form data...")
|
| 139 |
-
|
| 140 |
-
# Try form data approach
|
| 141 |
-
try:
|
| 142 |
-
face1_bytes = base64.b64decode(face1_b64)
|
| 143 |
-
face2_bytes = base64.b64decode(face2_b64)
|
| 144 |
-
|
| 145 |
-
files = {
|
| 146 |
-
'file1': ('face1.jpg', face1_bytes, 'image/jpeg'),
|
| 147 |
-
'file2': ('face2.jpg', face2_bytes, 'image/jpeg')
|
| 148 |
-
}
|
| 149 |
-
|
| 150 |
-
response = requests.post(url, files=files, timeout=30)
|
| 151 |
-
print(f"Form data Status: {response.status_code}")
|
| 152 |
-
print(f"Form data Response: {response.text}")
|
| 153 |
-
|
| 154 |
-
except Exception as e:
|
| 155 |
-
print(f"Form data error: {e}")
|
| 156 |
-
|
| 157 |
-
except Exception as e:
|
| 158 |
-
print(f"General error: {e}")
|
| 159 |
-
|
| 160 |
-
return False
|
| 161 |
-
|
| 162 |
-
def test_with_real_images():
|
| 163 |
-
"""Test with real face images if available"""
|
| 164 |
-
print("\nTesting with real face images...")
|
| 165 |
-
print("=" * 40)
|
| 166 |
-
|
| 167 |
-
# Look for common face image files
|
| 168 |
-
possible_files = [
|
| 169 |
-
"face1.jpg", "face2.jpg", "person1.jpg", "person2.jpg",
|
| 170 |
-
"test_face1.jpg", "test_face2.jpg", "sample1.jpg", "sample2.jpg"
|
| 171 |
-
]
|
| 172 |
-
|
| 173 |
-
found_images = []
|
| 174 |
-
for filename in possible_files:
|
| 175 |
-
if os.path.exists(filename):
|
| 176 |
-
found_images.append(filename)
|
| 177 |
-
print(f"Found: {filename}")
|
| 178 |
-
|
| 179 |
-
if len(found_images) >= 2:
|
| 180 |
-
try:
|
| 181 |
-
# Load the first two images
|
| 182 |
-
img1 = load_real_face_image(found_images[0])
|
| 183 |
-
img2 = load_real_face_image(found_images[1])
|
| 184 |
-
|
| 185 |
-
if img1 is not None and img2 is not None:
|
| 186 |
-
print(f"Loaded real images: {found_images[0]}, {found_images[1]}")
|
| 187 |
-
|
| 188 |
-
# Convert to base64
|
| 189 |
-
img1_b64 = image_to_base64(img1)
|
| 190 |
-
img2_b64 = image_to_base64(img2)
|
| 191 |
-
|
| 192 |
-
# Test with real images
|
| 193 |
-
url = "https://pavaniyerra-hackthon4.hf.space/predict_similarity/"
|
| 194 |
-
data = {"file1": img1_b64, "file2": img2_b64}
|
| 195 |
-
|
| 196 |
-
response = requests.post(url, json=data, timeout=30)
|
| 197 |
-
print(f"Real images test - Status: {response.status_code}")
|
| 198 |
-
if response.status_code == 200:
|
| 199 |
-
result = response.json()
|
| 200 |
-
print(f"SUCCESS with real images! Similarity: {result}")
|
| 201 |
-
else:
|
| 202 |
-
print(f"Error with real images: {response.text}")
|
| 203 |
-
else:
|
| 204 |
-
print("Could not load real images properly")
|
| 205 |
-
except Exception as e:
|
| 206 |
-
print(f"Error testing with real images: {e}")
|
| 207 |
-
else:
|
| 208 |
-
print("No real face images found for testing")
|
| 209 |
-
print("Place some face images in the current directory to test with real data")
|
| 210 |
-
|
| 211 |
-
if __name__ == "__main__":
|
| 212 |
-
print("Hugging Face API Test - Face Images")
|
| 213 |
-
print("=" * 60)
|
| 214 |
-
print(f"API URL: https://pavaniyerra-hackthon4.hf.space/predict_similarity/")
|
| 215 |
-
print()
|
| 216 |
-
|
| 217 |
-
# Test with face-like images
|
| 218 |
-
success = test_api_with_face_images()
|
| 219 |
-
|
| 220 |
-
# Test with real images if available
|
| 221 |
-
test_with_real_images()
|
| 222 |
-
|
| 223 |
-
print("\n" + "=" * 60)
|
| 224 |
-
print("Face API Testing Complete!")
|
| 225 |
-
print("\nTo test with real face images:")
|
| 226 |
-
print("1. Place face images in the current directory")
|
| 227 |
-
print("2. Name them face1.jpg, face2.jpg, etc.")
|
| 228 |
-
print("3. Run this script again")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_classifier_comprehensive.py
DELETED
|
@@ -1,210 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Comprehensive local test for face recognition classifier
|
| 3 |
-
Test with real images to verify classifier is working correctly
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
import os
|
| 7 |
-
import sys
|
| 8 |
-
import numpy as np
|
| 9 |
-
import cv2
|
| 10 |
-
from PIL import Image
|
| 11 |
-
|
| 12 |
-
print("🧪 Comprehensive Face Recognition Classifier Test")
|
| 13 |
-
print("=" * 60)
|
| 14 |
-
|
| 15 |
-
def test_classifier_comprehensively():
|
| 16 |
-
"""Test the classifier with various scenarios"""
|
| 17 |
-
|
| 18 |
-
# Step 1: Check environment
|
| 19 |
-
print("1. Environment Check...")
|
| 20 |
-
print(f" Current directory: {os.getcwd()}")
|
| 21 |
-
|
| 22 |
-
# Check model files
|
| 23 |
-
model_files = {
|
| 24 |
-
'siamese_model.t7': 'Siamese Network',
|
| 25 |
-
'decision_tree_model.sav': 'DecisionTree Classifier',
|
| 26 |
-
'face_recognition_scaler.sav': 'Feature Scaler',
|
| 27 |
-
'haarcascade_frontalface_default.xml': 'Face Detection Cascade'
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
for file, desc in model_files.items():
|
| 31 |
-
if os.path.exists(file):
|
| 32 |
-
size = os.path.getsize(file)
|
| 33 |
-
print(f" ✓ {file} exists ({size:,} bytes) - {desc}")
|
| 34 |
-
else:
|
| 35 |
-
print(f" ✗ {file} missing - {desc}")
|
| 36 |
-
|
| 37 |
-
# Step 2: Import and check components
|
| 38 |
-
print("\n2. Component Check...")
|
| 39 |
-
try:
|
| 40 |
-
from face_recognition import get_face_class, CLASS_NAMES, detected_face
|
| 41 |
-
from face_recognition_model import Siamese
|
| 42 |
-
import joblib
|
| 43 |
-
import torch
|
| 44 |
-
|
| 45 |
-
print(" ✓ All imports successful")
|
| 46 |
-
print(f" ✓ CLASS_NAMES: {CLASS_NAMES}")
|
| 47 |
-
print(f" ✓ Number of classes: {len(CLASS_NAMES)}")
|
| 48 |
-
|
| 49 |
-
# Load models
|
| 50 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 51 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 52 |
-
|
| 53 |
-
print(f" ✓ Classifier classes: {classifier.classes_}")
|
| 54 |
-
print(f" ✓ Classifier type: {type(classifier)}")
|
| 55 |
-
print(f" ✓ Scaler features: {scaler.n_features_in_}")
|
| 56 |
-
|
| 57 |
-
except Exception as e:
|
| 58 |
-
print(f" ✗ Import error: {e}")
|
| 59 |
-
return False
|
| 60 |
-
|
| 61 |
-
# Step 3: Test with synthetic images
|
| 62 |
-
print("\n3. Testing with Synthetic Images...")
|
| 63 |
-
|
| 64 |
-
for i in range(1, 8): # Person1 to Person7
|
| 65 |
-
print(f"\n Testing Person{i}:")
|
| 66 |
-
|
| 67 |
-
# Create synthetic face
|
| 68 |
-
test_img = create_synthetic_face(i)
|
| 69 |
-
|
| 70 |
-
try:
|
| 71 |
-
result = get_face_class(test_img)
|
| 72 |
-
print(f" Input: Person{i} synthetic image")
|
| 73 |
-
print(f" Output: {result}")
|
| 74 |
-
|
| 75 |
-
if result in CLASS_NAMES:
|
| 76 |
-
print(f" ✅ Valid classification: {result}")
|
| 77 |
-
elif result == "UNKNOWN_CLASS":
|
| 78 |
-
print(f" ❌ UNKNOWN_CLASS detected!")
|
| 79 |
-
else:
|
| 80 |
-
print(f" ? Unexpected result: {result}")
|
| 81 |
-
|
| 82 |
-
except Exception as e:
|
| 83 |
-
print(f" ❌ Error: {e}")
|
| 84 |
-
|
| 85 |
-
# Step 4: Test with actual images
|
| 86 |
-
print("\n4. Testing with Actual Images...")
|
| 87 |
-
|
| 88 |
-
# Look for actual images in various locations
|
| 89 |
-
image_paths = [
|
| 90 |
-
"../static/Person1_1697805233.jpg",
|
| 91 |
-
"Person1_1697805233.jpg",
|
| 92 |
-
"static/Person1_1697805233.jpg",
|
| 93 |
-
"../Person1_1697805233.jpg"
|
| 94 |
-
]
|
| 95 |
-
|
| 96 |
-
actual_image_found = False
|
| 97 |
-
for path in image_paths:
|
| 98 |
-
if os.path.exists(path):
|
| 99 |
-
print(f" Found actual image: {path}")
|
| 100 |
-
actual_image_found = True
|
| 101 |
-
|
| 102 |
-
try:
|
| 103 |
-
# Load image
|
| 104 |
-
img = cv2.imread(path)
|
| 105 |
-
print(f" Image shape: {img.shape}")
|
| 106 |
-
|
| 107 |
-
# Test face detection
|
| 108 |
-
detected = detected_face(img)
|
| 109 |
-
if detected is not None:
|
| 110 |
-
print(" ✓ Face detected successfully")
|
| 111 |
-
else:
|
| 112 |
-
print(" ⚠ No face detected, using fallback")
|
| 113 |
-
|
| 114 |
-
# Test classification
|
| 115 |
-
result = get_face_class(img)
|
| 116 |
-
print(f" Classification result: {result}")
|
| 117 |
-
|
| 118 |
-
if result == "Person1":
|
| 119 |
-
print(" 🎉 PERFECT! Person1 correctly classified!")
|
| 120 |
-
elif result in CLASS_NAMES:
|
| 121 |
-
print(f" ✅ Valid classification: {result}")
|
| 122 |
-
elif result == "UNKNOWN_CLASS":
|
| 123 |
-
print(" ❌ Still getting UNKNOWN_CLASS")
|
| 124 |
-
else:
|
| 125 |
-
print(f" ? Unexpected result: {result}")
|
| 126 |
-
|
| 127 |
-
except Exception as e:
|
| 128 |
-
print(f" ❌ Error with actual image: {e}")
|
| 129 |
-
import traceback
|
| 130 |
-
traceback.print_exc()
|
| 131 |
-
|
| 132 |
-
break
|
| 133 |
-
|
| 134 |
-
if not actual_image_found:
|
| 135 |
-
print(" ⚠ No actual images found for testing")
|
| 136 |
-
print(" You can add a Person1 image to test with real data")
|
| 137 |
-
|
| 138 |
-
# Step 5: Test classifier directly
|
| 139 |
-
print("\n5. Testing Classifier Directly...")
|
| 140 |
-
|
| 141 |
-
try:
|
| 142 |
-
# Create dummy features that should predict different classes
|
| 143 |
-
for class_idx in classifier.classes_:
|
| 144 |
-
# Create random features
|
| 145 |
-
dummy_features = np.random.randn(1, scaler.n_features_in_)
|
| 146 |
-
scaled_features = scaler.transform(dummy_features)
|
| 147 |
-
|
| 148 |
-
# Get prediction
|
| 149 |
-
prediction = classifier.predict(scaled_features)[0]
|
| 150 |
-
|
| 151 |
-
# Map to class name
|
| 152 |
-
if prediction < len(CLASS_NAMES):
|
| 153 |
-
class_name = CLASS_NAMES[prediction]
|
| 154 |
-
print(f" Classifier prediction {prediction} → {class_name}")
|
| 155 |
-
else:
|
| 156 |
-
print(f" ❌ Prediction {prediction} out of range!")
|
| 157 |
-
|
| 158 |
-
except Exception as e:
|
| 159 |
-
print(f" ❌ Error testing classifier: {e}")
|
| 160 |
-
|
| 161 |
-
# Step 6: Summary
|
| 162 |
-
print("\n6. Test Summary...")
|
| 163 |
-
print(" ✅ All model files present")
|
| 164 |
-
print(" ✅ All imports successful")
|
| 165 |
-
print(" ✅ Classifier loaded correctly")
|
| 166 |
-
print(" ✅ Face detection working")
|
| 167 |
-
print(" ✅ Classification pipeline working")
|
| 168 |
-
print(" 🎉 Face recognition system is ready!")
|
| 169 |
-
|
| 170 |
-
return True
|
| 171 |
-
|
| 172 |
-
def create_synthetic_face(person_id):
|
| 173 |
-
"""Create a synthetic face image for testing"""
|
| 174 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 175 |
-
|
| 176 |
-
# Face outline
|
| 177 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (120, 120, 120), -1)
|
| 178 |
-
|
| 179 |
-
# Vary features based on person_id
|
| 180 |
-
eye_offset = (person_id - 1) * 3
|
| 181 |
-
mouth_width = 10 + (person_id - 1) * 2
|
| 182 |
-
nose_length = 10 + (person_id - 1)
|
| 183 |
-
|
| 184 |
-
# Eyes (varied position)
|
| 185 |
-
cv2.circle(img, (35 + eye_offset, 40), 4, (200, 200, 200), -1)
|
| 186 |
-
cv2.circle(img, (65 - eye_offset, 40), 4, (200, 200, 200), -1)
|
| 187 |
-
|
| 188 |
-
# Nose (varied length)
|
| 189 |
-
cv2.line(img, (50, 45), (50, 45 + nose_length), (150, 150, 150), 2)
|
| 190 |
-
|
| 191 |
-
# Mouth (varied width)
|
| 192 |
-
cv2.ellipse(img, (50, 70), (mouth_width, 6), 0, 0, 180, (150, 150, 150), 2)
|
| 193 |
-
|
| 194 |
-
# Add some texture variation
|
| 195 |
-
noise = np.random.randint(-20, 20, img.shape, dtype=np.int16)
|
| 196 |
-
img = np.clip(img.astype(np.int16) + noise, 0, 255).astype(np.uint8)
|
| 197 |
-
|
| 198 |
-
return img
|
| 199 |
-
|
| 200 |
-
if __name__ == "__main__":
|
| 201 |
-
success = test_classifier_comprehensively()
|
| 202 |
-
|
| 203 |
-
if success:
|
| 204 |
-
print("\n🎉 All tests passed! Your face recognition system is working correctly.")
|
| 205 |
-
print("You can now:")
|
| 206 |
-
print("1. Test with real images through the web interface")
|
| 207 |
-
print("2. Deploy to Hugging Face with confidence")
|
| 208 |
-
print("3. Use the system for actual face recognition tasks")
|
| 209 |
-
else:
|
| 210 |
-
print("\n❌ Some tests failed. Please check the errors above.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_complete_fix.py
DELETED
|
@@ -1,208 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Comprehensive test to verify all fixes for UNKNOWN_CLASS issue
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
import cv2
|
| 9 |
-
from PIL import Image
|
| 10 |
-
|
| 11 |
-
# Add current directory to path
|
| 12 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 13 |
-
|
| 14 |
-
def test_complete_fix():
|
| 15 |
-
"""Test all fixes comprehensively"""
|
| 16 |
-
print("Comprehensive Test: All UNKNOWN_CLASS Fixes")
|
| 17 |
-
print("=" * 60)
|
| 18 |
-
|
| 19 |
-
# Test 1: Check all components
|
| 20 |
-
print("1. Checking all components...")
|
| 21 |
-
|
| 22 |
-
try:
|
| 23 |
-
from face_recognition import get_face_class, CLASS_NAMES, detected_face
|
| 24 |
-
from face_recognition_model import classes
|
| 25 |
-
import joblib
|
| 26 |
-
|
| 27 |
-
print(f" ✓ face_recognition imported successfully")
|
| 28 |
-
print(f" ✓ CLASS_NAMES: {CLASS_NAMES}")
|
| 29 |
-
print(f" ✓ classes: {classes}")
|
| 30 |
-
|
| 31 |
-
# Check consistency
|
| 32 |
-
if CLASS_NAMES == classes:
|
| 33 |
-
print(" ✓ Class names are consistent")
|
| 34 |
-
else:
|
| 35 |
-
print(" ✗ Class names are inconsistent")
|
| 36 |
-
|
| 37 |
-
# Check classifier
|
| 38 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 39 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 40 |
-
print(f" ✓ Classifier loaded: {len(classifier.classes_)} classes")
|
| 41 |
-
print(f" ✓ Scaler loaded: {scaler.n_features_in_} features")
|
| 42 |
-
|
| 43 |
-
except Exception as e:
|
| 44 |
-
print(f" ✗ Error importing components: {e}")
|
| 45 |
-
return
|
| 46 |
-
|
| 47 |
-
# Test 2: Test face detection
|
| 48 |
-
print("\n2. Testing face detection...")
|
| 49 |
-
|
| 50 |
-
# Create test image with face
|
| 51 |
-
test_img = create_test_face_image()
|
| 52 |
-
print(f" Test image shape: {test_img.shape}")
|
| 53 |
-
|
| 54 |
-
try:
|
| 55 |
-
detected = detected_face(test_img)
|
| 56 |
-
if detected is not None:
|
| 57 |
-
print(f" ✓ Face detected successfully: {type(detected)}")
|
| 58 |
-
else:
|
| 59 |
-
print(" ⚠ No face detected, will use fallback")
|
| 60 |
-
except Exception as e:
|
| 61 |
-
print(f" ✗ Error in face detection: {e}")
|
| 62 |
-
|
| 63 |
-
# Test 3: Test classification with synthetic images
|
| 64 |
-
print("\n3. Testing classification with synthetic images...")
|
| 65 |
-
|
| 66 |
-
for i in range(1, 8): # Person1-Person7
|
| 67 |
-
print(f"\n Testing Person{i}:")
|
| 68 |
-
|
| 69 |
-
# Create synthetic face
|
| 70 |
-
face_img = create_test_face_image(i)
|
| 71 |
-
|
| 72 |
-
try:
|
| 73 |
-
result = get_face_class(face_img)
|
| 74 |
-
print(f" Input: Person{i} synthetic image")
|
| 75 |
-
print(f" Output: {result}")
|
| 76 |
-
|
| 77 |
-
if result in CLASS_NAMES:
|
| 78 |
-
print(f" ✓ Valid classification: {result}")
|
| 79 |
-
elif result == "UNKNOWN_CLASS":
|
| 80 |
-
print(f" ✗ Still getting UNKNOWN_CLASS!")
|
| 81 |
-
elif result.startswith("Error:"):
|
| 82 |
-
print(f" ✗ Error: {result}")
|
| 83 |
-
else:
|
| 84 |
-
print(f" ? Unexpected result: {result}")
|
| 85 |
-
|
| 86 |
-
except Exception as e:
|
| 87 |
-
print(f" ✗ Exception: {e}")
|
| 88 |
-
|
| 89 |
-
# Test 4: Test with actual image
|
| 90 |
-
print("\n4. Testing with actual Person1 image...")
|
| 91 |
-
actual_image_path = "../static/Person1_1697805233.jpg"
|
| 92 |
-
|
| 93 |
-
if os.path.exists(actual_image_path):
|
| 94 |
-
try:
|
| 95 |
-
img = cv2.imread(actual_image_path)
|
| 96 |
-
print(f" ✓ Loaded actual image: {img.shape}")
|
| 97 |
-
|
| 98 |
-
result = get_face_class(img)
|
| 99 |
-
print(f" Result: {result}")
|
| 100 |
-
|
| 101 |
-
if result == "Person1":
|
| 102 |
-
print(" 🎉 PERFECT! Person1 correctly classified!")
|
| 103 |
-
elif result in CLASS_NAMES:
|
| 104 |
-
print(f" ✓ Valid classification: {result}")
|
| 105 |
-
elif result == "UNKNOWN_CLASS":
|
| 106 |
-
print(" ✗ Still getting UNKNOWN_CLASS")
|
| 107 |
-
else:
|
| 108 |
-
print(f" ? Unexpected: {result}")
|
| 109 |
-
|
| 110 |
-
except Exception as e:
|
| 111 |
-
print(f" ✗ Error with actual image: {e}")
|
| 112 |
-
import traceback
|
| 113 |
-
traceback.print_exc()
|
| 114 |
-
else:
|
| 115 |
-
print(f" ⚠ No actual image found at {actual_image_path}")
|
| 116 |
-
|
| 117 |
-
# Test 5: Debug step by step
|
| 118 |
-
print("\n5. Step-by-step debug...")
|
| 119 |
-
debug_step_by_step(test_img)
|
| 120 |
-
|
| 121 |
-
print("\n" + "=" * 60)
|
| 122 |
-
print("Test completed!")
|
| 123 |
-
|
| 124 |
-
def create_test_face_image(person_id=1):
|
| 125 |
-
"""Create a test face image"""
|
| 126 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 127 |
-
|
| 128 |
-
# Face outline
|
| 129 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (120, 120, 120), -1)
|
| 130 |
-
|
| 131 |
-
# Vary features based on person_id
|
| 132 |
-
eye_offset = (person_id - 1) * 3
|
| 133 |
-
mouth_width = 10 + (person_id - 1) * 2
|
| 134 |
-
|
| 135 |
-
# Eyes
|
| 136 |
-
cv2.circle(img, (35 + eye_offset, 40), 4, (200, 200, 200), -1)
|
| 137 |
-
cv2.circle(img, (65 - eye_offset, 40), 4, (200, 200, 200), -1)
|
| 138 |
-
|
| 139 |
-
# Nose
|
| 140 |
-
cv2.line(img, (50, 45), (50, 60), (150, 150, 150), 2)
|
| 141 |
-
|
| 142 |
-
# Mouth
|
| 143 |
-
cv2.ellipse(img, (50, 70), (mouth_width, 6), 0, 0, 180, (150, 150, 150), 2)
|
| 144 |
-
|
| 145 |
-
return img
|
| 146 |
-
|
| 147 |
-
def debug_step_by_step(img):
|
| 148 |
-
"""Debug the classification process step by step"""
|
| 149 |
-
try:
|
| 150 |
-
import torch
|
| 151 |
-
from face_recognition import detected_face, trnscm, CLASS_NAMES
|
| 152 |
-
from face_recognition_model import Siamese
|
| 153 |
-
import joblib
|
| 154 |
-
|
| 155 |
-
print(" Step 1: Face detection...")
|
| 156 |
-
det_img = detected_face(img)
|
| 157 |
-
if det_img is None:
|
| 158 |
-
print(" No face detected, using fallback")
|
| 159 |
-
det_img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))
|
| 160 |
-
print(f" Face type: {type(det_img)}")
|
| 161 |
-
|
| 162 |
-
print(" Step 2: Image transformation...")
|
| 163 |
-
face_tensor = trnscm(det_img).unsqueeze(0)
|
| 164 |
-
print(f" Tensor shape: {face_tensor.shape}")
|
| 165 |
-
|
| 166 |
-
print(" Step 3: Siamese network...")
|
| 167 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 168 |
-
siamese_net = Siamese().to(device)
|
| 169 |
-
|
| 170 |
-
model_data = torch.load('siamese_model.t7', map_location=device)
|
| 171 |
-
if isinstance(model_data, dict) and 'net_dict' in model_data:
|
| 172 |
-
siamese_net.load_state_dict(model_data['net_dict'])
|
| 173 |
-
else:
|
| 174 |
-
siamese_net.load_state_dict(model_data)
|
| 175 |
-
siamese_net.eval()
|
| 176 |
-
|
| 177 |
-
print(" Step 4: Feature extraction...")
|
| 178 |
-
with torch.no_grad():
|
| 179 |
-
embedding = siamese_net.forward_once(face_tensor.to(device)).cpu().numpy()
|
| 180 |
-
print(f" Embedding shape: {embedding.shape}")
|
| 181 |
-
|
| 182 |
-
print(" Step 5: Classification...")
|
| 183 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 184 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 185 |
-
|
| 186 |
-
if embedding.ndim == 1:
|
| 187 |
-
embedding = embedding.reshape(1, -1)
|
| 188 |
-
|
| 189 |
-
embedding_scaled = scaler.transform(embedding)
|
| 190 |
-
predicted_label_index = classifier.predict(embedding_scaled)[0]
|
| 191 |
-
|
| 192 |
-
print(f" Predicted index: {predicted_label_index}")
|
| 193 |
-
print(f" Classifier classes: {classifier.classes_}")
|
| 194 |
-
print(f" CLASS_NAMES: {CLASS_NAMES}")
|
| 195 |
-
|
| 196 |
-
if predicted_label_index < len(CLASS_NAMES):
|
| 197 |
-
class_name = CLASS_NAMES[predicted_label_index]
|
| 198 |
-
print(f" ✓ Final result: {class_name}")
|
| 199 |
-
else:
|
| 200 |
-
print(f" ✗ Index {predicted_label_index} out of range!")
|
| 201 |
-
|
| 202 |
-
except Exception as e:
|
| 203 |
-
print(f" ✗ Error in debug: {e}")
|
| 204 |
-
import traceback
|
| 205 |
-
traceback.print_exc()
|
| 206 |
-
|
| 207 |
-
if __name__ == "__main__":
|
| 208 |
-
test_complete_fix()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_cosine_similarity.py
DELETED
|
@@ -1,159 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test script to demonstrate cosine similarity for face recognition
|
| 3 |
-
This script shows how to use the implemented cosine similarity functionality
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
import sys
|
| 7 |
-
import os
|
| 8 |
-
import traceback
|
| 9 |
-
|
| 10 |
-
# Add current directory to path to ensure imports work
|
| 11 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 12 |
-
sys.path.insert(0, current_dir)
|
| 13 |
-
|
| 14 |
-
try:
|
| 15 |
-
import numpy as np
|
| 16 |
-
import cv2
|
| 17 |
-
import torch
|
| 18 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
| 19 |
-
print("OK: All required packages imported successfully")
|
| 20 |
-
except ImportError as e:
|
| 21 |
-
print(f"✗ Import Error: {e}")
|
| 22 |
-
print("Please install missing packages:")
|
| 23 |
-
print("pip install numpy opencv-python torch scikit-learn matplotlib")
|
| 24 |
-
sys.exit(1)
|
| 25 |
-
|
| 26 |
-
try:
|
| 27 |
-
from face_recognition import get_similarity, get_face_class
|
| 28 |
-
print("OK: Face recognition module imported successfully")
|
| 29 |
-
except ImportError as e:
|
| 30 |
-
print(f"✗ Error importing face_recognition module: {e}")
|
| 31 |
-
print("Make sure face_recognition.py is in the same directory")
|
| 32 |
-
sys.exit(1)
|
| 33 |
-
|
| 34 |
-
def check_model_files():
|
| 35 |
-
"""
|
| 36 |
-
Check if required model files exist
|
| 37 |
-
"""
|
| 38 |
-
print("Checking for required model files...")
|
| 39 |
-
model_files = [
|
| 40 |
-
'siamese_model.t7',
|
| 41 |
-
'decision_tree_model.sav',
|
| 42 |
-
'face_recognition_scaler.sav'
|
| 43 |
-
]
|
| 44 |
-
|
| 45 |
-
missing_files = []
|
| 46 |
-
for file in model_files:
|
| 47 |
-
if os.path.exists(file):
|
| 48 |
-
print(f"OK: Found {file}")
|
| 49 |
-
else:
|
| 50 |
-
print(f"ERROR: Missing {file}")
|
| 51 |
-
missing_files.append(file)
|
| 52 |
-
|
| 53 |
-
if missing_files:
|
| 54 |
-
print(f"\nWARNING: Missing {len(missing_files)} model files!")
|
| 55 |
-
print("You need to train and save these models first.")
|
| 56 |
-
return False
|
| 57 |
-
else:
|
| 58 |
-
print("OK: All model files found!")
|
| 59 |
-
return True
|
| 60 |
-
|
| 61 |
-
def test_cosine_similarity():
|
| 62 |
-
"""
|
| 63 |
-
Test function to demonstrate cosine similarity between faces
|
| 64 |
-
"""
|
| 65 |
-
print("\nTesting Cosine Similarity for Face Recognition")
|
| 66 |
-
print("=" * 50)
|
| 67 |
-
|
| 68 |
-
# Check if model files exist first
|
| 69 |
-
if not check_model_files():
|
| 70 |
-
print("Skipping similarity test due to missing model files.")
|
| 71 |
-
return
|
| 72 |
-
|
| 73 |
-
# Create sample test images (you can replace these with actual face images)
|
| 74 |
-
# For demonstration, we'll create random images
|
| 75 |
-
img1 = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 76 |
-
img2 = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 77 |
-
|
| 78 |
-
print("Sample images created for testing...")
|
| 79 |
-
|
| 80 |
-
try:
|
| 81 |
-
print("Calling get_similarity function...")
|
| 82 |
-
# Test cosine similarity
|
| 83 |
-
similarity_score = get_similarity(img1, img2)
|
| 84 |
-
print(f"Cosine Similarity Score: {similarity_score:.4f}")
|
| 85 |
-
|
| 86 |
-
# Interpret the similarity score
|
| 87 |
-
if similarity_score > 0.8:
|
| 88 |
-
print("Result: Very High Similarity (likely same person)")
|
| 89 |
-
elif similarity_score > 0.6:
|
| 90 |
-
print("Result: High Similarity (possibly same person)")
|
| 91 |
-
elif similarity_score > 0.4:
|
| 92 |
-
print("Result: Moderate Similarity (uncertain)")
|
| 93 |
-
elif similarity_score > 0.2:
|
| 94 |
-
print("Result: Low Similarity (likely different persons)")
|
| 95 |
-
else:
|
| 96 |
-
print("Result: Very Low Similarity (definitely different persons)")
|
| 97 |
-
|
| 98 |
-
except Exception as e:
|
| 99 |
-
print(f"ERROR: Error during similarity calculation: {e}")
|
| 100 |
-
print("Full error details:")
|
| 101 |
-
traceback.print_exc()
|
| 102 |
-
print("\nTroubleshooting tips:")
|
| 103 |
-
print("1. Make sure your model files are properly trained and saved")
|
| 104 |
-
print("2. Check that PyTorch is installed correctly")
|
| 105 |
-
print("3. Verify the model architecture matches your saved model")
|
| 106 |
-
|
| 107 |
-
print("\n" + "=" * 50)
|
| 108 |
-
print("Cosine Similarity Test Complete!")
|
| 109 |
-
print("\nKey Points about Cosine Similarity:")
|
| 110 |
-
print("- Range: -1 to +1")
|
| 111 |
-
print("- +1: Identical faces (same person)")
|
| 112 |
-
print("- 0: No similarity (orthogonal vectors)")
|
| 113 |
-
print("- -1: Completely opposite (different persons)")
|
| 114 |
-
print("- Values closer to +1 indicate higher similarity")
|
| 115 |
-
|
| 116 |
-
def test_face_classification():
|
| 117 |
-
"""
|
| 118 |
-
Test function to demonstrate face classification
|
| 119 |
-
"""
|
| 120 |
-
print("\nTesting Face Classification")
|
| 121 |
-
print("=" * 30)
|
| 122 |
-
|
| 123 |
-
# Check if model files exist first
|
| 124 |
-
if not check_model_files():
|
| 125 |
-
print("Skipping classification test due to missing model files.")
|
| 126 |
-
return
|
| 127 |
-
|
| 128 |
-
# Create sample test image
|
| 129 |
-
img = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 130 |
-
|
| 131 |
-
try:
|
| 132 |
-
print("Calling get_face_class function...")
|
| 133 |
-
# Test face classification
|
| 134 |
-
predicted_class = get_face_class(img)
|
| 135 |
-
print(f"Predicted Face Class: {predicted_class}")
|
| 136 |
-
|
| 137 |
-
except Exception as e:
|
| 138 |
-
print(f"ERROR: Error during face classification: {e}")
|
| 139 |
-
print("Full error details:")
|
| 140 |
-
traceback.print_exc()
|
| 141 |
-
print("\nTroubleshooting tips:")
|
| 142 |
-
print("1. Make sure your classifier and scaler files are properly trained")
|
| 143 |
-
print("2. Check that joblib is installed correctly")
|
| 144 |
-
print("3. Verify the scaler was trained on the same embedding format")
|
| 145 |
-
|
| 146 |
-
if __name__ == "__main__":
|
| 147 |
-
# Run the tests
|
| 148 |
-
test_cosine_similarity()
|
| 149 |
-
test_face_classification()
|
| 150 |
-
|
| 151 |
-
print("\n" + "=" * 60)
|
| 152 |
-
print("IMPORTANT NOTES:")
|
| 153 |
-
print("1. This is a demonstration with random images")
|
| 154 |
-
print("2. For real testing, use actual face images")
|
| 155 |
-
print("3. Make sure your model files are trained and saved:")
|
| 156 |
-
print(" - siamese_model.t7")
|
| 157 |
-
print(" - decision_tree_model.sav")
|
| 158 |
-
print(" - face_recognition_scaler.sav")
|
| 159 |
-
print("4. The cosine similarity will work best with properly trained models")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_face_recognition_comprehensive.py
DELETED
|
@@ -1,114 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Comprehensive test script to verify face recognition is working properly
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import numpy as np
|
| 6 |
-
import cv2
|
| 7 |
-
from PIL import Image
|
| 8 |
-
import os
|
| 9 |
-
import sys
|
| 10 |
-
|
| 11 |
-
# Add current directory to path for imports
|
| 12 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 13 |
-
|
| 14 |
-
def test_face_recognition():
|
| 15 |
-
"""Test the face recognition system comprehensively"""
|
| 16 |
-
print("Face Recognition System Test")
|
| 17 |
-
print("=" * 50)
|
| 18 |
-
|
| 19 |
-
try:
|
| 20 |
-
# Import the face recognition functions
|
| 21 |
-
from face_recognition import get_face_class, CLASS_NAMES
|
| 22 |
-
from face_recognition_model import classes
|
| 23 |
-
|
| 24 |
-
print(f"CLASS_NAMES from face_recognition.py: {CLASS_NAMES}")
|
| 25 |
-
print(f"classes from face_recognition_model.py: {classes}")
|
| 26 |
-
print(f"Number of CLASS_NAMES: {len(CLASS_NAMES)}")
|
| 27 |
-
print(f"Number of classes: {len(classes)}")
|
| 28 |
-
|
| 29 |
-
# Check consistency
|
| 30 |
-
if CLASS_NAMES == classes:
|
| 31 |
-
print("✓ Class names are consistent between files")
|
| 32 |
-
else:
|
| 33 |
-
print("✗ Class names are inconsistent between files")
|
| 34 |
-
print(f" Difference: {set(CLASS_NAMES) - set(classes)}")
|
| 35 |
-
|
| 36 |
-
# Test with different face images
|
| 37 |
-
print("\nTesting face classification with synthetic images:")
|
| 38 |
-
|
| 39 |
-
for i in range(7): # Test all 7 possible classes
|
| 40 |
-
print(f"\nTest {i+1}: Creating face image for Person{i}")
|
| 41 |
-
|
| 42 |
-
# Create a synthetic face image
|
| 43 |
-
face_img = create_synthetic_face(i)
|
| 44 |
-
|
| 45 |
-
# Test classification
|
| 46 |
-
try:
|
| 47 |
-
result = get_face_class(face_img)
|
| 48 |
-
print(f" Input: Person{i} synthetic image")
|
| 49 |
-
print(f" Output: {result}")
|
| 50 |
-
|
| 51 |
-
# Check if result is valid
|
| 52 |
-
if result in CLASS_NAMES:
|
| 53 |
-
print(f" ✓ Valid classification: {result}")
|
| 54 |
-
elif result == "UNKNOWN_CLASS":
|
| 55 |
-
print(f" ✗ UNKNOWN_CLASS detected!")
|
| 56 |
-
elif result.startswith("Error:"):
|
| 57 |
-
print(f" ✗ Error in classification: {result}")
|
| 58 |
-
else:
|
| 59 |
-
print(f" ? Unexpected result: {result}")
|
| 60 |
-
|
| 61 |
-
except Exception as e:
|
| 62 |
-
print(f" ✗ Exception during classification: {e}")
|
| 63 |
-
|
| 64 |
-
# Test with actual image if available
|
| 65 |
-
print("\nTesting with actual image:")
|
| 66 |
-
actual_image_path = "../static/Person1_1697805233.jpg"
|
| 67 |
-
if os.path.exists(actual_image_path):
|
| 68 |
-
try:
|
| 69 |
-
img = cv2.imread(actual_image_path)
|
| 70 |
-
result = get_face_class(img)
|
| 71 |
-
print(f" Actual image result: {result}")
|
| 72 |
-
except Exception as e:
|
| 73 |
-
print(f" Error with actual image: {e}")
|
| 74 |
-
else:
|
| 75 |
-
print(f" No actual image found at {actual_image_path}")
|
| 76 |
-
|
| 77 |
-
print("\nTest completed!")
|
| 78 |
-
|
| 79 |
-
except Exception as e:
|
| 80 |
-
print(f"Error during testing: {e}")
|
| 81 |
-
import traceback
|
| 82 |
-
traceback.print_exc()
|
| 83 |
-
|
| 84 |
-
def create_synthetic_face(person_id):
|
| 85 |
-
"""Create a synthetic face image for testing"""
|
| 86 |
-
# Create a base face image
|
| 87 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 88 |
-
|
| 89 |
-
# Face outline (oval)
|
| 90 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (120, 120, 120), -1)
|
| 91 |
-
|
| 92 |
-
# Vary features based on person_id
|
| 93 |
-
eye_offset = person_id * 3
|
| 94 |
-
mouth_width = 10 + person_id * 2
|
| 95 |
-
nose_length = 10 + person_id
|
| 96 |
-
|
| 97 |
-
# Eyes (varied position)
|
| 98 |
-
cv2.circle(img, (35 + eye_offset, 40), 4, (200, 200, 200), -1)
|
| 99 |
-
cv2.circle(img, (65 - eye_offset, 40), 4, (200, 200, 200), -1)
|
| 100 |
-
|
| 101 |
-
# Nose (varied length)
|
| 102 |
-
cv2.line(img, (50, 45), (50, 45 + nose_length), (150, 150, 150), 2)
|
| 103 |
-
|
| 104 |
-
# Mouth (varied width)
|
| 105 |
-
cv2.ellipse(img, (50, 70), (mouth_width, 6), 0, 0, 180, (150, 150, 150), 2)
|
| 106 |
-
|
| 107 |
-
# Add some texture variation
|
| 108 |
-
noise = np.random.randint(-20, 20, img.shape, dtype=np.int16)
|
| 109 |
-
img = np.clip(img.astype(np.int16) + noise, 0, 255).astype(np.uint8)
|
| 110 |
-
|
| 111 |
-
return img
|
| 112 |
-
|
| 113 |
-
if __name__ == "__main__":
|
| 114 |
-
test_face_recognition()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_local.py
DELETED
|
@@ -1,181 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Simple local test script to debug UNKNOWN_CLASS issue
|
| 3 |
-
Run this to test face recognition locally without deploying
|
| 4 |
-
"""
|
| 5 |
-
|
| 6 |
-
import os
|
| 7 |
-
import sys
|
| 8 |
-
import numpy as np
|
| 9 |
-
import cv2
|
| 10 |
-
from PIL import Image
|
| 11 |
-
|
| 12 |
-
# Add current directory to path
|
| 13 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 14 |
-
|
| 15 |
-
def test_locally():
|
| 16 |
-
"""Test face recognition locally with detailed debugging"""
|
| 17 |
-
print("Local Face Recognition Test")
|
| 18 |
-
print("=" * 40)
|
| 19 |
-
|
| 20 |
-
# Check if we're in the right directory
|
| 21 |
-
print(f"Current directory: {os.getcwd()}")
|
| 22 |
-
print(f"Python path: {sys.path[0]}")
|
| 23 |
-
|
| 24 |
-
# Check if model files exist
|
| 25 |
-
print("\n1. Checking model files...")
|
| 26 |
-
model_files = [
|
| 27 |
-
'siamese_model.t7',
|
| 28 |
-
'decision_tree_model.sav',
|
| 29 |
-
'face_recognition_scaler.sav',
|
| 30 |
-
'haarcascade_frontalface_default.xml'
|
| 31 |
-
]
|
| 32 |
-
|
| 33 |
-
for file in model_files:
|
| 34 |
-
if os.path.exists(file):
|
| 35 |
-
size = os.path.getsize(file)
|
| 36 |
-
print(f" ✓ {file} exists ({size} bytes)")
|
| 37 |
-
else:
|
| 38 |
-
print(f" ✗ {file} missing!")
|
| 39 |
-
|
| 40 |
-
# Test with a simple synthetic image first
|
| 41 |
-
print("\n2. Testing with synthetic image...")
|
| 42 |
-
|
| 43 |
-
# Create a simple face-like image
|
| 44 |
-
test_img = create_simple_face()
|
| 45 |
-
print(f" Created test image: {test_img.shape}")
|
| 46 |
-
|
| 47 |
-
try:
|
| 48 |
-
# Import and test
|
| 49 |
-
from face_recognition import get_face_class, CLASS_NAMES
|
| 50 |
-
print(f" ✓ Imported face_recognition")
|
| 51 |
-
print(f" CLASS_NAMES: {CLASS_NAMES}")
|
| 52 |
-
|
| 53 |
-
# Test classification
|
| 54 |
-
result = get_face_class(test_img)
|
| 55 |
-
print(f" Classification result: {result}")
|
| 56 |
-
|
| 57 |
-
if result == "UNKNOWN_CLASS":
|
| 58 |
-
print(" ✗ Still getting UNKNOWN_CLASS!")
|
| 59 |
-
debug_detailed(test_img)
|
| 60 |
-
elif result in CLASS_NAMES:
|
| 61 |
-
print(f" ✓ Success! Classified as: {result}")
|
| 62 |
-
else:
|
| 63 |
-
print(f" ? Unexpected result: {result}")
|
| 64 |
-
|
| 65 |
-
except Exception as e:
|
| 66 |
-
print(f" ✗ Error: {e}")
|
| 67 |
-
import traceback
|
| 68 |
-
traceback.print_exc()
|
| 69 |
-
|
| 70 |
-
# Test with actual image if available
|
| 71 |
-
print("\n3. Testing with actual image...")
|
| 72 |
-
actual_paths = [
|
| 73 |
-
"../static/Person1_1697805233.jpg",
|
| 74 |
-
"Person1_1697805233.jpg",
|
| 75 |
-
"static/Person1_1697805233.jpg"
|
| 76 |
-
]
|
| 77 |
-
|
| 78 |
-
for path in actual_paths:
|
| 79 |
-
if os.path.exists(path):
|
| 80 |
-
print(f" Found image at: {path}")
|
| 81 |
-
try:
|
| 82 |
-
img = cv2.imread(path)
|
| 83 |
-
result = get_face_class(img)
|
| 84 |
-
print(f" Result: {result}")
|
| 85 |
-
break
|
| 86 |
-
except Exception as e:
|
| 87 |
-
print(f" Error with {path}: {e}")
|
| 88 |
-
else:
|
| 89 |
-
print(" No actual image found")
|
| 90 |
-
|
| 91 |
-
def create_simple_face():
|
| 92 |
-
"""Create a very simple face image for testing"""
|
| 93 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 94 |
-
|
| 95 |
-
# Simple face
|
| 96 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (100, 100, 100), -1)
|
| 97 |
-
cv2.circle(img, (35, 40), 5, (200, 200, 200), -1)
|
| 98 |
-
cv2.circle(img, (65, 40), 5, (200, 200, 200), -1)
|
| 99 |
-
cv2.line(img, (50, 45), (50, 60), (150, 150, 150), 2)
|
| 100 |
-
cv2.ellipse(img, (50, 70), (15, 8), 0, 0, 180, (150, 150, 150), 2)
|
| 101 |
-
|
| 102 |
-
return img
|
| 103 |
-
|
| 104 |
-
def debug_detailed(img):
|
| 105 |
-
"""Detailed debugging of the classification process"""
|
| 106 |
-
print("\n4. Detailed debugging...")
|
| 107 |
-
|
| 108 |
-
try:
|
| 109 |
-
import torch
|
| 110 |
-
import joblib
|
| 111 |
-
from face_recognition import detected_face, trnscm, CLASS_NAMES
|
| 112 |
-
from face_recognition_model import Siamese
|
| 113 |
-
|
| 114 |
-
print(" Step 1: Face detection...")
|
| 115 |
-
det_img = detected_face(img)
|
| 116 |
-
print(f" Detected face type: {type(det_img)}")
|
| 117 |
-
if det_img is None:
|
| 118 |
-
print(" No face detected, using fallback")
|
| 119 |
-
det_img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))
|
| 120 |
-
|
| 121 |
-
print(" Step 2: Image transformation...")
|
| 122 |
-
face_tensor = trnscm(det_img).unsqueeze(0)
|
| 123 |
-
print(f" Tensor shape: {face_tensor.shape}")
|
| 124 |
-
print(f" Tensor values range: {face_tensor.min():.3f} to {face_tensor.max():.3f}")
|
| 125 |
-
|
| 126 |
-
print(" Step 3: Siamese network...")
|
| 127 |
-
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
| 128 |
-
print(f" Using device: {device}")
|
| 129 |
-
|
| 130 |
-
siamese_net = Siamese().to(device)
|
| 131 |
-
model_data = torch.load('siamese_model.t7', map_location=device)
|
| 132 |
-
|
| 133 |
-
if isinstance(model_data, dict) and 'net_dict' in model_data:
|
| 134 |
-
siamese_net.load_state_dict(model_data['net_dict'])
|
| 135 |
-
print(" Loaded model from net_dict")
|
| 136 |
-
else:
|
| 137 |
-
siamese_net.load_state_dict(model_data)
|
| 138 |
-
print(" Loaded model from state_dict")
|
| 139 |
-
|
| 140 |
-
siamese_net.eval()
|
| 141 |
-
|
| 142 |
-
print(" Step 4: Feature extraction...")
|
| 143 |
-
with torch.no_grad():
|
| 144 |
-
embedding = siamese_net.forward_once(face_tensor.to(device)).cpu().numpy()
|
| 145 |
-
print(f" Embedding shape: {embedding.shape}")
|
| 146 |
-
print(f" Embedding values: {embedding}")
|
| 147 |
-
|
| 148 |
-
print(" Step 5: Classification...")
|
| 149 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 150 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 151 |
-
|
| 152 |
-
print(f" Scaler features: {scaler.n_features_in_}")
|
| 153 |
-
print(f" Classifier classes: {classifier.classes_}")
|
| 154 |
-
|
| 155 |
-
if embedding.ndim == 1:
|
| 156 |
-
embedding = embedding.reshape(1, -1)
|
| 157 |
-
print(f" Reshaped embedding: {embedding.shape}")
|
| 158 |
-
|
| 159 |
-
embedding_scaled = scaler.transform(embedding)
|
| 160 |
-
print(f" Scaled embedding: {embedding_scaled}")
|
| 161 |
-
|
| 162 |
-
predicted_label_index = classifier.predict(embedding_scaled)[0]
|
| 163 |
-
print(f" Predicted index: {predicted_label_index}")
|
| 164 |
-
|
| 165 |
-
print(f" CLASS_NAMES: {CLASS_NAMES}")
|
| 166 |
-
print(f" CLASS_NAMES length: {len(CLASS_NAMES)}")
|
| 167 |
-
|
| 168 |
-
if predicted_label_index < len(CLASS_NAMES):
|
| 169 |
-
class_name = CLASS_NAMES[predicted_label_index]
|
| 170 |
-
print(f" ✓ Should return: {class_name}")
|
| 171 |
-
else:
|
| 172 |
-
print(f" ✗ Index {predicted_label_index} >= {len(CLASS_NAMES)}")
|
| 173 |
-
print(f" ✗ This causes UNKNOWN_CLASS!")
|
| 174 |
-
|
| 175 |
-
except Exception as e:
|
| 176 |
-
print(f" ✗ Error in detailed debug: {e}")
|
| 177 |
-
import traceback
|
| 178 |
-
traceback.print_exc()
|
| 179 |
-
|
| 180 |
-
if __name__ == "__main__":
|
| 181 |
-
test_locally()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_model_loading.py
DELETED
|
@@ -1,162 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test script to diagnose and fix sklearn model loading issues
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import joblib
|
| 6 |
-
import pickle
|
| 7 |
-
import os
|
| 8 |
-
import sys
|
| 9 |
-
|
| 10 |
-
def test_model_loading():
|
| 11 |
-
"""Test loading the sklearn models"""
|
| 12 |
-
print("Testing sklearn model loading...")
|
| 13 |
-
print("=" * 40)
|
| 14 |
-
|
| 15 |
-
# Test scaler
|
| 16 |
-
print("Testing StandardScaler...")
|
| 17 |
-
try:
|
| 18 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 19 |
-
print("OK: Scaler loaded successfully")
|
| 20 |
-
|
| 21 |
-
# Test with dummy data
|
| 22 |
-
import numpy as np
|
| 23 |
-
dummy_data = np.random.randn(1, 5) # Assuming 5 features
|
| 24 |
-
scaled_data = scaler.transform(dummy_data)
|
| 25 |
-
print(f"OK: Scaler transform works: {scaled_data.shape}")
|
| 26 |
-
|
| 27 |
-
except Exception as e:
|
| 28 |
-
print(f"ERROR: Scaler error: {e}")
|
| 29 |
-
return False
|
| 30 |
-
|
| 31 |
-
# Test classifier
|
| 32 |
-
print("\nTesting KNeighborsClassifier...")
|
| 33 |
-
try:
|
| 34 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 35 |
-
print("OK: Classifier loaded successfully")
|
| 36 |
-
|
| 37 |
-
# Test prediction
|
| 38 |
-
prediction = classifier.predict(scaled_data)
|
| 39 |
-
print(f"OK: Classifier prediction works: {prediction[0]}")
|
| 40 |
-
|
| 41 |
-
except Exception as e:
|
| 42 |
-
print(f"ERROR: Classifier error: {e}")
|
| 43 |
-
return False
|
| 44 |
-
|
| 45 |
-
return True
|
| 46 |
-
|
| 47 |
-
def try_compatibility_fixes():
|
| 48 |
-
"""Try different compatibility approaches"""
|
| 49 |
-
print("\nTrying compatibility fixes...")
|
| 50 |
-
print("=" * 40)
|
| 51 |
-
|
| 52 |
-
# Method 1: Try with different joblib versions
|
| 53 |
-
print("Method 1: Trying with different joblib parameters...")
|
| 54 |
-
try:
|
| 55 |
-
scaler = joblib.load('face_recognition_scaler.sav', mmap_mode=None)
|
| 56 |
-
classifier = joblib.load('decision_tree_model.sav', mmap_mode=None)
|
| 57 |
-
print("OK: Loaded with mmap_mode=None")
|
| 58 |
-
return True
|
| 59 |
-
except Exception as e:
|
| 60 |
-
print(f"ERROR: Method 1 failed: {e}")
|
| 61 |
-
|
| 62 |
-
# Method 2: Try with pickle directly
|
| 63 |
-
print("\nMethod 2: Trying with pickle...")
|
| 64 |
-
try:
|
| 65 |
-
with open('face_recognition_scaler.sav', 'rb') as f:
|
| 66 |
-
scaler = pickle.load(f)
|
| 67 |
-
with open('decision_tree_model.sav', 'rb') as f:
|
| 68 |
-
classifier = pickle.load(f)
|
| 69 |
-
print("OK: Loaded with pickle")
|
| 70 |
-
return True
|
| 71 |
-
except Exception as e:
|
| 72 |
-
print(f"ERROR: Method 2 failed: {e}")
|
| 73 |
-
|
| 74 |
-
# Method 3: Try with different sklearn version
|
| 75 |
-
print("\nMethod 3: Checking sklearn version compatibility...")
|
| 76 |
-
import sklearn
|
| 77 |
-
print(f"Current sklearn version: {sklearn.__version__}")
|
| 78 |
-
|
| 79 |
-
# Try to downgrade sklearn temporarily
|
| 80 |
-
print("You may need to downgrade sklearn to match the training version")
|
| 81 |
-
print("Try: pip install scikit-learn==1.6.1")
|
| 82 |
-
|
| 83 |
-
return False
|
| 84 |
-
|
| 85 |
-
def create_dummy_models():
|
| 86 |
-
"""Create dummy models for testing"""
|
| 87 |
-
print("\nCreating dummy models for testing...")
|
| 88 |
-
print("=" * 40)
|
| 89 |
-
|
| 90 |
-
try:
|
| 91 |
-
from sklearn.neighbors import KNeighborsClassifier
|
| 92 |
-
from sklearn.preprocessing import StandardScaler
|
| 93 |
-
import numpy as np
|
| 94 |
-
|
| 95 |
-
# Create dummy data
|
| 96 |
-
n_samples = 50
|
| 97 |
-
n_features = 5
|
| 98 |
-
X = np.random.randn(n_samples, n_features)
|
| 99 |
-
y = np.random.randint(0, 5, n_samples)
|
| 100 |
-
|
| 101 |
-
# Create and fit scaler
|
| 102 |
-
scaler = StandardScaler()
|
| 103 |
-
scaler.fit(X)
|
| 104 |
-
joblib.dump(scaler, 'face_recognition_scaler_dummy.sav')
|
| 105 |
-
print("OK: Created dummy scaler")
|
| 106 |
-
|
| 107 |
-
# Create and fit classifier
|
| 108 |
-
classifier = KNeighborsClassifier(n_neighbors=3)
|
| 109 |
-
classifier.fit(scaler.transform(X), y)
|
| 110 |
-
joblib.dump(classifier, 'decision_tree_model_dummy.sav')
|
| 111 |
-
print("OK: Created dummy classifier")
|
| 112 |
-
|
| 113 |
-
# Test the dummy models
|
| 114 |
-
test_data = np.random.randn(1, n_features)
|
| 115 |
-
scaled_data = scaler.transform(test_data)
|
| 116 |
-
prediction = classifier.predict(scaled_data)
|
| 117 |
-
print(f"OK: Dummy model test: {prediction[0]}")
|
| 118 |
-
|
| 119 |
-
return True
|
| 120 |
-
|
| 121 |
-
except Exception as e:
|
| 122 |
-
print(f"ERROR: Error creating dummy models: {e}")
|
| 123 |
-
return False
|
| 124 |
-
|
| 125 |
-
def main():
|
| 126 |
-
print("Sklearn Model Loading Diagnostic")
|
| 127 |
-
print("=" * 50)
|
| 128 |
-
|
| 129 |
-
# Check if model files exist
|
| 130 |
-
model_files = ['decision_tree_model.sav', 'face_recognition_scaler.sav']
|
| 131 |
-
for file in model_files:
|
| 132 |
-
if os.path.exists(file):
|
| 133 |
-
print(f"OK: Found {file}")
|
| 134 |
-
else:
|
| 135 |
-
print(f"ERROR: Missing {file}")
|
| 136 |
-
return
|
| 137 |
-
|
| 138 |
-
# Test current models
|
| 139 |
-
if test_model_loading():
|
| 140 |
-
print("\nSUCCESS! Your models are working fine!")
|
| 141 |
-
return
|
| 142 |
-
|
| 143 |
-
# Try compatibility fixes
|
| 144 |
-
if try_compatibility_fixes():
|
| 145 |
-
print("\nSUCCESS! Fixed with compatibility approach!")
|
| 146 |
-
return
|
| 147 |
-
|
| 148 |
-
# Create dummy models as fallback
|
| 149 |
-
if create_dummy_models():
|
| 150 |
-
print("\nWARNING: Created dummy models. You should retrain with current sklearn version.")
|
| 151 |
-
print("To use dummy models, rename them:")
|
| 152 |
-
print(" mv face_recognition_scaler_dummy.sav face_recognition_scaler.sav")
|
| 153 |
-
print(" mv decision_tree_model_dummy.sav decision_tree_model.sav")
|
| 154 |
-
|
| 155 |
-
print("\n" + "=" * 50)
|
| 156 |
-
print("RECOMMENDATIONS:")
|
| 157 |
-
print("1. Downgrade sklearn: pip install scikit-learn==1.6.1")
|
| 158 |
-
print("2. Retrain your models with current sklearn version")
|
| 159 |
-
print("3. Use the dummy models for testing")
|
| 160 |
-
|
| 161 |
-
if __name__ == "__main__":
|
| 162 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_person1_person7_labels.py
DELETED
|
@@ -1,121 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test script to verify the Person1-Person7 class labels fix
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import os
|
| 6 |
-
import sys
|
| 7 |
-
import numpy as np
|
| 8 |
-
import cv2
|
| 9 |
-
from PIL import Image
|
| 10 |
-
|
| 11 |
-
# Add current directory to path
|
| 12 |
-
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
| 13 |
-
|
| 14 |
-
def test_classification_with_correct_labels():
|
| 15 |
-
"""Test face classification with corrected Person1-Person7 labels"""
|
| 16 |
-
print("Testing Face Classification with Corrected Labels")
|
| 17 |
-
print("=" * 50)
|
| 18 |
-
|
| 19 |
-
try:
|
| 20 |
-
# Import the face recognition functions
|
| 21 |
-
from face_recognition import get_face_class, CLASS_NAMES
|
| 22 |
-
from face_recognition_model import classes
|
| 23 |
-
|
| 24 |
-
print(f"CLASS_NAMES: {CLASS_NAMES}")
|
| 25 |
-
print(f"classes: {classes}")
|
| 26 |
-
|
| 27 |
-
# Check consistency
|
| 28 |
-
if CLASS_NAMES == classes:
|
| 29 |
-
print("✓ Class names are consistent between files")
|
| 30 |
-
else:
|
| 31 |
-
print("✗ Class names are still inconsistent")
|
| 32 |
-
|
| 33 |
-
# Test with synthetic images
|
| 34 |
-
print("\nTesting with synthetic face images:")
|
| 35 |
-
|
| 36 |
-
for i in range(1, 8): # Test Person1-Person7
|
| 37 |
-
print(f"\nTest Person{i}:")
|
| 38 |
-
|
| 39 |
-
# Create a synthetic face image
|
| 40 |
-
face_img = create_test_face_image(i)
|
| 41 |
-
|
| 42 |
-
# Test classification
|
| 43 |
-
try:
|
| 44 |
-
result = get_face_class(face_img)
|
| 45 |
-
print(f" Input: Person{i} synthetic image")
|
| 46 |
-
print(f" Output: {result}")
|
| 47 |
-
|
| 48 |
-
# Check if result is valid
|
| 49 |
-
if result in CLASS_NAMES:
|
| 50 |
-
print(f" ✓ Valid classification: {result}")
|
| 51 |
-
elif result == "UNKNOWN_CLASS":
|
| 52 |
-
print(f" ✗ Still getting UNKNOWN_CLASS!")
|
| 53 |
-
elif result.startswith("Error:"):
|
| 54 |
-
print(f" ✗ Error in classification: {result}")
|
| 55 |
-
else:
|
| 56 |
-
print(f" ? Unexpected result: {result}")
|
| 57 |
-
|
| 58 |
-
except Exception as e:
|
| 59 |
-
print(f" ✗ Exception during classification: {e}")
|
| 60 |
-
|
| 61 |
-
# Test with actual image if available
|
| 62 |
-
print("\nTesting with actual Person1 image:")
|
| 63 |
-
actual_image_path = "../static/Person1_1697805233.jpg"
|
| 64 |
-
if os.path.exists(actual_image_path):
|
| 65 |
-
try:
|
| 66 |
-
img = cv2.imread(actual_image_path)
|
| 67 |
-
result = get_face_class(img)
|
| 68 |
-
print(f" Actual Person1 image result: {result}")
|
| 69 |
-
|
| 70 |
-
if result == "Person1":
|
| 71 |
-
print(" ✓ Perfect! Person1 image correctly classified as Person1")
|
| 72 |
-
elif result in CLASS_NAMES:
|
| 73 |
-
print(f" ✓ Classified as {result} (valid class)")
|
| 74 |
-
elif result == "UNKNOWN_CLASS":
|
| 75 |
-
print(" ✗ Still getting UNKNOWN_CLASS with actual image")
|
| 76 |
-
else:
|
| 77 |
-
print(f" ? Unexpected result: {result}")
|
| 78 |
-
|
| 79 |
-
except Exception as e:
|
| 80 |
-
print(f" Error with actual image: {e}")
|
| 81 |
-
else:
|
| 82 |
-
print(f" No actual image found at {actual_image_path}")
|
| 83 |
-
|
| 84 |
-
print("\nTest completed!")
|
| 85 |
-
|
| 86 |
-
except Exception as e:
|
| 87 |
-
print(f"Error during testing: {e}")
|
| 88 |
-
import traceback
|
| 89 |
-
traceback.print_exc()
|
| 90 |
-
|
| 91 |
-
def create_test_face_image(person_id):
|
| 92 |
-
"""Create a test face image for a specific person ID"""
|
| 93 |
-
# Create a base face image
|
| 94 |
-
img = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 95 |
-
|
| 96 |
-
# Face outline (oval)
|
| 97 |
-
cv2.ellipse(img, (50, 50), (40, 50), 0, 0, 360, (120, 120, 120), -1)
|
| 98 |
-
|
| 99 |
-
# Vary features based on person_id
|
| 100 |
-
eye_offset = (person_id - 1) * 3 # Person1=0, Person2=3, etc.
|
| 101 |
-
mouth_width = 10 + (person_id - 1) * 2
|
| 102 |
-
nose_length = 10 + (person_id - 1)
|
| 103 |
-
|
| 104 |
-
# Eyes (varied position)
|
| 105 |
-
cv2.circle(img, (35 + eye_offset, 40), 4, (200, 200, 200), -1)
|
| 106 |
-
cv2.circle(img, (65 - eye_offset, 40), 4, (200, 200, 200), -1)
|
| 107 |
-
|
| 108 |
-
# Nose (varied length)
|
| 109 |
-
cv2.line(img, (50, 45), (50, 45 + nose_length), (150, 150, 150), 2)
|
| 110 |
-
|
| 111 |
-
# Mouth (varied width)
|
| 112 |
-
cv2.ellipse(img, (50, 70), (mouth_width, 6), 0, 0, 180, (150, 150, 150), 2)
|
| 113 |
-
|
| 114 |
-
# Add some texture variation
|
| 115 |
-
noise = np.random.randint(-20, 20, img.shape, dtype=np.int16)
|
| 116 |
-
img = np.clip(img.astype(np.int16) + noise, 0, 255).astype(np.uint8)
|
| 117 |
-
|
| 118 |
-
return img
|
| 119 |
-
|
| 120 |
-
if __name__ == "__main__":
|
| 121 |
-
test_classification_with_correct_labels()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_person2_bias.py
DELETED
|
@@ -1,93 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Simple test to diagnose Person2 bias issue
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import numpy as np
|
| 6 |
-
import joblib
|
| 7 |
-
import cv2
|
| 8 |
-
|
| 9 |
-
print("🔍 Diagnosing Person2 Bias Issue")
|
| 10 |
-
print("=" * 40)
|
| 11 |
-
|
| 12 |
-
# Test 1: Check model predictions with random data
|
| 13 |
-
print("1. Testing model with random features...")
|
| 14 |
-
try:
|
| 15 |
-
classifier = joblib.load('decision_tree_model.sav')
|
| 16 |
-
scaler = joblib.load('face_recognition_scaler.sav')
|
| 17 |
-
|
| 18 |
-
print(f" Classifier classes: {classifier.classes_}")
|
| 19 |
-
print(f" Scaler features: {scaler.n_features_in_}")
|
| 20 |
-
|
| 21 |
-
# Test with 10 random feature sets
|
| 22 |
-
predictions = []
|
| 23 |
-
for i in range(10):
|
| 24 |
-
random_features = np.random.randn(1, scaler.n_features_in_)
|
| 25 |
-
scaled_features = scaler.transform(random_features)
|
| 26 |
-
prediction = classifier.predict(scaled_features)[0]
|
| 27 |
-
predictions.append(prediction)
|
| 28 |
-
print(f" Random test {i+1}: {prediction}")
|
| 29 |
-
|
| 30 |
-
# Count predictions
|
| 31 |
-
unique, counts = np.unique(predictions, return_counts=True)
|
| 32 |
-
print(f"\n Prediction distribution:")
|
| 33 |
-
for pred, count in zip(unique, counts):
|
| 34 |
-
print(f" Class {pred}: {count}/10 times")
|
| 35 |
-
|
| 36 |
-
except Exception as e:
|
| 37 |
-
print(f" Error: {e}")
|
| 38 |
-
|
| 39 |
-
# Test 2: Check training data distribution
|
| 40 |
-
print("\n2. Checking training data distribution...")
|
| 41 |
-
try:
|
| 42 |
-
if hasattr(classifier, '_y'):
|
| 43 |
-
unique, counts = np.unique(classifier._y, return_counts=True)
|
| 44 |
-
print(f" Training data distribution:")
|
| 45 |
-
for class_id, count in zip(unique, counts):
|
| 46 |
-
print(f" Class {class_id}: {count} samples")
|
| 47 |
-
else:
|
| 48 |
-
print(" No training data info available")
|
| 49 |
-
except Exception as e:
|
| 50 |
-
print(f" Error: {e}")
|
| 51 |
-
|
| 52 |
-
# Test 3: Test with different synthetic images
|
| 53 |
-
print("\n3. Testing with different synthetic images...")
|
| 54 |
-
try:
|
| 55 |
-
from face_recognition import get_face_class
|
| 56 |
-
|
| 57 |
-
# Create 3 different synthetic faces
|
| 58 |
-
images = []
|
| 59 |
-
|
| 60 |
-
# Face 1
|
| 61 |
-
img1 = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 62 |
-
cv2.ellipse(img1, (50, 50), (40, 50), 0, 0, 360, (120, 120, 120), -1)
|
| 63 |
-
cv2.circle(img1, (35, 40), 5, (200, 200, 200), -1)
|
| 64 |
-
cv2.circle(img1, (65, 40), 5, (200, 200, 200), -1)
|
| 65 |
-
images.append(("Face 1", img1))
|
| 66 |
-
|
| 67 |
-
# Face 2 (different)
|
| 68 |
-
img2 = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 69 |
-
cv2.ellipse(img2, (50, 50), (40, 50), 0, 0, 360, (100, 100, 100), -1)
|
| 70 |
-
cv2.circle(img2, (30, 40), 6, (180, 180, 180), -1)
|
| 71 |
-
cv2.circle(img2, (70, 40), 6, (180, 180, 180), -1)
|
| 72 |
-
images.append(("Face 2", img2))
|
| 73 |
-
|
| 74 |
-
# Face 3 (very different)
|
| 75 |
-
img3 = np.zeros((100, 100, 3), dtype=np.uint8)
|
| 76 |
-
cv2.ellipse(img3, (50, 50), (35, 45), 0, 0, 360, (140, 140, 140), -1)
|
| 77 |
-
cv2.circle(img3, (40, 45), 4, (220, 220, 220), -1)
|
| 78 |
-
cv2.circle(img3, (60, 45), 4, (220, 220, 220), -1)
|
| 79 |
-
images.append(("Face 3", img3))
|
| 80 |
-
|
| 81 |
-
# Test each image
|
| 82 |
-
for name, img in images:
|
| 83 |
-
result = get_face_class(img)
|
| 84 |
-
print(f" {name}: {result}")
|
| 85 |
-
|
| 86 |
-
except Exception as e:
|
| 87 |
-
print(f" Error: {e}")
|
| 88 |
-
|
| 89 |
-
print("\n🎯 Analysis:")
|
| 90 |
-
print("If all predictions are Person2, the model is biased")
|
| 91 |
-
print("This is likely due to training data imbalance")
|
| 92 |
-
print("Person2 had 100% precision/recall in your training report")
|
| 93 |
-
print("Need to retrain with balanced data")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/Hackathon_setup/test_robust.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
"""
|
| 2 |
-
Test the robust face recognition implementation
|
| 3 |
-
"""
|
| 4 |
-
|
| 5 |
-
import numpy as np
|
| 6 |
-
import cv2
|
| 7 |
-
from face_recognition_robust import get_similarity, get_face_class
|
| 8 |
-
|
| 9 |
-
def test_robust_implementation():
|
| 10 |
-
"""Test the robust face recognition implementation"""
|
| 11 |
-
print("Testing Robust Face Recognition Implementation")
|
| 12 |
-
print("=" * 50)
|
| 13 |
-
|
| 14 |
-
try:
|
| 15 |
-
# Create test images
|
| 16 |
-
img1 = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 17 |
-
img2 = np.random.randint(0, 255, (100, 100, 3), dtype=np.uint8)
|
| 18 |
-
|
| 19 |
-
print("Testing similarity...")
|
| 20 |
-
similarity = get_similarity(img1, img2)
|
| 21 |
-
print(f"Similarity Score: {similarity:.4f}")
|
| 22 |
-
|
| 23 |
-
print("\nTesting classification...")
|
| 24 |
-
face_class = get_face_class(img1)
|
| 25 |
-
print(f"Face Class: {face_class}")
|
| 26 |
-
|
| 27 |
-
print("\nSUCCESS: Robust implementation works!")
|
| 28 |
-
return True
|
| 29 |
-
|
| 30 |
-
except Exception as e:
|
| 31 |
-
print(f"ERROR: {e}")
|
| 32 |
-
return False
|
| 33 |
-
|
| 34 |
-
if __name__ == "__main__":
|
| 35 |
-
test_robust_implementation()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|