DOMMETI commited on
Commit
a19d8e1
·
verified ·
1 Parent(s): 9635af9

Update pages/2_Player_Comparison_Throw_Image.py

Browse files
pages/2_Player_Comparison_Throw_Image.py CHANGED
@@ -32,9 +32,21 @@ def detect_and_predict_face(image_file, model):
32
 
33
  x, y, w, h = faces[0]
34
  face = gray[y:y+h, x:x+w]
35
- resized_face = cv2.resize(face, (64, 64))
 
 
 
 
 
 
 
 
 
36
  flattened = resized_face.flatten().reshape(1, -1)
37
 
 
 
 
38
  pred_label = model.predict(flattened)[0]
39
  return pred_label, None
40
 
@@ -42,7 +54,7 @@ def detect_and_predict_face(image_file, model):
42
  def get_player_details(df, player_name):
43
  return df[df['Player'] == player_name].iloc[0]
44
 
45
- # Plotting functions (matches, batting, bowling) -- same as your original code
46
  def plot_matches_pie(player_data):
47
  matches_stats = {
48
  'Format': ['Test', 'ODI', 'T20', 'IPL'],
 
32
 
33
  x, y, w, h = faces[0]
34
  face = gray[y:y+h, x:x+w]
35
+
36
+ # Get expected input shape from scaler in pipeline
37
+ expected_features = model.named_steps['scaler'].n_features_in_
38
+ target_dim = int(np.sqrt(expected_features)) # assumes square input
39
+
40
+ try:
41
+ resized_face = cv2.resize(face, (target_dim, target_dim))
42
+ except:
43
+ return None, f"❌ Failed to resize face to {target_dim}x{target_dim}"
44
+
45
  flattened = resized_face.flatten().reshape(1, -1)
46
 
47
+ if flattened.shape[1] != expected_features:
48
+ return None, f"❌ Mismatch in feature count. Got {flattened.shape[1]}, expected {expected_features}"
49
+
50
  pred_label = model.predict(flattened)[0]
51
  return pred_label, None
52
 
 
54
  def get_player_details(df, player_name):
55
  return df[df['Player'] == player_name].iloc[0]
56
 
57
+ # Plotting functions
58
  def plot_matches_pie(player_data):
59
  matches_stats = {
60
  'Format': ['Test', 'ODI', 'T20', 'IPL'],