npuliga commited on
Commit
b7c0340
·
1 Parent(s): 8406457

updated models

Browse files
app/Hackathon_setup/face_recognition.py CHANGED
@@ -23,18 +23,11 @@ from sklearn.preprocessing import StandardScaler
23
  # Current_path stores absolute path of the file from where it runs.
24
  current_path = os.path.dirname(os.path.abspath(__file__))
25
 
26
- # Simple fallback classifier for sklearn compatibility issues
27
- def create_fallback_classifier(current_features):
28
- """Creates a simple fallback classifier that just returns Person1 for now"""
29
- class FallbackClassifier:
30
- def predict(self, X):
31
- # For now, just return Person1 (index 0) for all predictions
32
- # This is a temporary workaround
33
- return [0] * len(X)
34
-
35
- print("[WARNING] Using fallback classifier - will always predict Person1")
36
- print("[WARNING] Please retrain and save classifier with compatible sklearn version")
37
- return FallbackClassifier()
38
 
39
  #1) The below function is used to detect faces in the given image.
40
  #2) It returns only one image which has maximum area out of all the detected faces in the photo.
@@ -154,61 +147,27 @@ def get_face_class(img1):
154
  print(f"[DEBUG] Extracted features shape: {features_np.shape}")
155
 
156
  # Load the classifier and scaler
157
- classifier_path = current_path + '/face_recognition_classifier.pkl'
158
- classifier_path_v2 = current_path + '/face_recognition_classifier_v2.pkl'
159
- classifier_path_joblib = current_path + '/face_recognition_classifier_joblib.pkl'
160
  simple_classifier_path = current_path + '/simple_face_classifier.pkl'
161
  scaler_path = current_path + '/face_recognition_scaler.pkl'
162
 
163
  print(f"[DEBUG] Looking for classifier files:")
164
- print(f"[DEBUG] Original: {os.path.exists(classifier_path)}")
165
- print(f"[DEBUG] V2: {os.path.exists(classifier_path_v2)}")
166
- print(f"[DEBUG] Joblib: {os.path.exists(classifier_path_joblib)}")
167
- print(f"[DEBUG] Simple: {os.path.exists(simple_classifier_path)}")
168
  print(f"[DEBUG] Scaler: {os.path.exists(scaler_path)}")
169
 
170
  classifier = None
171
- # Try to load classifier in order of preference
172
  try:
173
  if os.path.exists(simple_classifier_path):
174
  print("[DEBUG] Loading simple custom classifier...")
175
- import pickle
176
  with open(simple_classifier_path, 'rb') as f:
177
  classifier = pickle.load(f)
178
  print("[DEBUG] Simple classifier loaded successfully")
179
- elif os.path.exists(classifier_path_v2):
180
- print("[DEBUG] Loading v2 classifier...")
181
- import pickle
182
- with open(classifier_path_v2, 'rb') as f:
183
- classifier = pickle.load(f)
184
- print("[DEBUG] V2 classifier loaded successfully")
185
- elif os.path.exists(classifier_path_joblib):
186
- print("[DEBUG] Loading joblib classifier...")
187
- classifier = joblib.load(classifier_path_joblib)
188
- print("[DEBUG] Joblib classifier loaded successfully")
189
- elif os.path.exists(classifier_path):
190
- print("[DEBUG] Loading original classifier...")
191
- try:
192
- classifier = joblib.load(classifier_path)
193
- print("[DEBUG] Original classifier loaded successfully")
194
- except AttributeError as sklearn_error:
195
- if 'EuclideanDistance64' in str(sklearn_error):
196
- print("[WARNING] sklearn version compatibility issue detected!")
197
- print("[WARNING] Creating fallback distance-based classifier...")
198
- # Create a simple fallback classifier
199
- classifier = create_fallback_classifier(features_np)
200
- else:
201
- raise sklearn_error
202
  else:
203
  print("[ERROR] No classifier file found!")
204
  return "Unknown"
205
  except Exception as classifier_error:
206
- if 'EuclideanDistance64' in str(classifier_error):
207
- print("[WARNING] sklearn compatibility issue - using fallback classifier")
208
- classifier = create_fallback_classifier(features_np)
209
- else:
210
- print(f"[ERROR] Failed to load classifier: {classifier_error}")
211
- return "Unknown"
212
 
213
  if classifier is not None:
214
  # Load the scaler used during training
 
23
  # Current_path stores absolute path of the file from where it runs.
24
  current_path = os.path.dirname(os.path.abspath(__file__))
25
 
26
+ # Simple error handling for missing models
27
+ def handle_missing_model(error_msg):
28
+ """Helper function to handle missing model files"""
29
+ print(f"[ERROR] {error_msg}")
30
+ return "Unknown"
 
 
 
 
 
 
 
31
 
32
  #1) The below function is used to detect faces in the given image.
33
  #2) It returns only one image which has maximum area out of all the detected faces in the photo.
 
147
  print(f"[DEBUG] Extracted features shape: {features_np.shape}")
148
 
149
  # Load the classifier and scaler
 
 
 
150
  simple_classifier_path = current_path + '/simple_face_classifier.pkl'
151
  scaler_path = current_path + '/face_recognition_scaler.pkl'
152
 
153
  print(f"[DEBUG] Looking for classifier files:")
154
+ print(f"[DEBUG] Simple classifier: {os.path.exists(simple_classifier_path)}")
 
 
 
155
  print(f"[DEBUG] Scaler: {os.path.exists(scaler_path)}")
156
 
157
  classifier = None
158
+ # Try to load the simple classifier
159
  try:
160
  if os.path.exists(simple_classifier_path):
161
  print("[DEBUG] Loading simple custom classifier...")
 
162
  with open(simple_classifier_path, 'rb') as f:
163
  classifier = pickle.load(f)
164
  print("[DEBUG] Simple classifier loaded successfully")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  else:
166
  print("[ERROR] No classifier file found!")
167
  return "Unknown"
168
  except Exception as classifier_error:
169
+ print(f"[ERROR] Failed to load classifier: {classifier_error}")
170
+ return handle_missing_model("Failed to load classifier")
 
 
 
 
171
 
172
  if classifier is not None:
173
  # Load the scaler used during training
app/Hackathon_setup/face_recognition_classifier.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ab2cb40f8723c0eb1c00724ecd6ad410252bde054d140eb87b052789dfeb2ba9
3
- size 2326
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:553fc0f0033fe377470c3f4235b209bfcab2d14e85421c54005979a74b1b05b8
3
+ size 535
app/Hackathon_setup/face_recognition_classifier_joblib.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ab2cb40f8723c0eb1c00724ecd6ad410252bde054d140eb87b052789dfeb2ba9
3
- size 2326
 
 
 
 
app/Hackathon_setup/face_recognition_classifier_v2.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:f03af7986bfe5048e5fc0e053e9fb57f3443a5900ec5eaacc67626f3a787b858
3
- size 2034
 
 
 
 
app/Hackathon_setup/face_recognition_scaler.pkl CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:814c85400b6877b93468ea0b12a992e56b789c540626b470609372f1ae8e0d54
3
  size 719
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b5cf2a5316f974e017e272dda77c54e5ebd786463d1a0fbe44e6f58f916fe7b6
3
  size 719
app/Hackathon_setup/simple_face_classifier.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:c906e1a570a8e4f76adebac192f6f4dddb14c3aa49601e575b8e58221b0dd109
3
- size 535