DOMMETI commited on
Commit
8c89d37
·
verified ·
1 Parent(s): 2b44bba

Update pages/2_Player_Comparison_Throw_Image.py

Browse files
pages/2_Player_Comparison_Throw_Image.py CHANGED
@@ -47,15 +47,18 @@ def detect_and_predict_face(image_file, model):
47
 
48
  expected_features = model.named_steps['scaler'].n_features_in_
49
 
50
- # CORRECT: width=113, height=109 113*109 = 12289
51
- resized_face = cv2.resize(face, (113, 109)) # <--- this is THE FIX
52
 
53
  flattened = resized_face.flatten().reshape(1, -1)
54
 
55
- # Debug output
56
- st.write(f"Resized shape: {resized_face.shape}") # should be (109, 113)
57
- st.write(f"Flattened shape: {flattened.shape}") # should be (1, 12289)
 
 
58
 
 
59
  if flattened.shape[1] != expected_features:
60
  return None, f"❌ Mismatch in feature count. Got {flattened.shape[1]}, expected {expected_features}"
61
 
@@ -68,6 +71,8 @@ def detect_and_predict_face(image_file, model):
68
 
69
 
70
 
 
 
71
  # Get player details from the dataset
72
  def get_player_details(df, player_name):
73
  return df[df['Player'] == player_name].iloc[0]
 
47
 
48
  expected_features = model.named_steps['scaler'].n_features_in_
49
 
50
+ # Resize to shape close to the expected features
51
+ resized_face = cv2.resize(face, (113, 109)) # width x height
52
 
53
  flattened = resized_face.flatten().reshape(1, -1)
54
 
55
+ # 🔧 Fix: if extra pixels due to rounding, trim them
56
+ if flattened.shape[1] > expected_features:
57
+ flattened = flattened[:, :expected_features]
58
+ elif flattened.shape[1] < expected_features:
59
+ return None, f"❌ Still too small after resizing. Got {flattened.shape[1]}"
60
 
61
+ # Final sanity check
62
  if flattened.shape[1] != expected_features:
63
  return None, f"❌ Mismatch in feature count. Got {flattened.shape[1]}, expected {expected_features}"
64
 
 
71
 
72
 
73
 
74
+
75
+
76
  # Get player details from the dataset
77
  def get_player_details(df, player_name):
78
  return df[df['Player'] == player_name].iloc[0]