aegishield commited on
Commit
3560de2
·
1 Parent(s): 7395aca
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -8,22 +8,31 @@ idpred = from_pretrained_keras("aegishield/idpred")
8
  fingpred = from_pretrained_keras("aegishield/fingpred")
9
 
10
  def predict_image(img):
 
 
 
 
11
  # Resize the image and convert to grayscale
12
  img_resized = img.resize((96, 96)).convert('L')
 
 
13
  img_array = np.array(img_resized)
 
 
14
  img_array = np.expand_dims(img_array, axis=-1)
15
- img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
16
 
17
- # Predictions and confidence
 
 
 
18
  y_SubjectID_pred = idpred.predict(img_array)
19
  y_fingerNum_pred = fingpred.predict(img_array)
20
 
 
21
  subject_id = np.argmax(y_SubjectID_pred, axis=1)[0]
22
  finger_num = np.argmax(y_fingerNum_pred, axis=1)[0]
23
-
24
- # Get the maximum probability as confidence
25
- subject_confidence = np.max(y_SubjectID_pred) * 100 # Convert to percentage
26
- finger_confidence = np.max(y_fingerNum_pred) * 100 # Convert to percentage
27
 
28
  return (f'Subject ID: {subject_id} (Confidence: {subject_confidence:.2f}%)',
29
  f'Finger Number: {finger_num} (Confidence: {finger_confidence:.2f}%)')
 
8
  fingpred = from_pretrained_keras("aegishield/fingpred")
9
 
10
  def predict_image(img):
11
+ # Ensure the image is a PIL Image
12
+ if not isinstance(img, Image.Image):
13
+ img = Image.fromarray(img)
14
+
15
  # Resize the image and convert to grayscale
16
  img_resized = img.resize((96, 96)).convert('L')
17
+
18
+ # Convert the resized grayscale image to a numpy array
19
  img_array = np.array(img_resized)
20
+
21
+ # Add a channel dimension since the model expects (96, 96, 1)
22
  img_array = np.expand_dims(img_array, axis=-1)
 
23
 
24
+ # Add batch dimension
25
+ img_array = np.expand_dims(img_array, axis=0)
26
+
27
+ # Predictions
28
  y_SubjectID_pred = idpred.predict(img_array)
29
  y_fingerNum_pred = fingpred.predict(img_array)
30
 
31
+ # Extract prediction and confidence
32
  subject_id = np.argmax(y_SubjectID_pred, axis=1)[0]
33
  finger_num = np.argmax(y_fingerNum_pred, axis=1)[0]
34
+ subject_confidence = np.max(y_SubjectID_pred) * 100
35
+ finger_confidence = np.max(y_fingerNum_pred) * 100
 
 
36
 
37
  return (f'Subject ID: {subject_id} (Confidence: {subject_confidence:.2f}%)',
38
  f'Finger Number: {finger_num} (Confidence: {finger_confidence:.2f}%)')