bauckluc commited on
Commit
93de2ae
·
verified ·
1 Parent(s): e44d4e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -21,6 +21,9 @@ def predict_bmwX(image):
21
  # Apply softmax to get probabilities for each class
22
  prediction = tf.nn.softmax(prediction)
23
 
 
 
 
24
  # Define class names
25
  class_names = ['Afghan', 'African Wild Dog', 'Airedale', 'American Hairless', 'American Spaniel', 'Basenji', 'Basset', 'Beagle',
26
  'Bearded Collie', 'Bermaise', 'Bichon Frise', 'Blenheim', 'Bloodhound', 'Bluetick', 'Border Collie', 'Borzoi',
@@ -32,6 +35,10 @@ def predict_bmwX(image):
32
  'Poodle', 'Pug', 'Rhodesian', 'Rottweiler', 'Saint Bernard', 'Schnauzer', 'Scotch Terrier', 'Shar_Pei',
33
  'Shiba Inu', 'Shih-Tzu', 'Siberian Husky', 'Vizsla', 'Yorkie']
34
 
 
 
 
 
35
  # Create a dictionary with the probabilities for each dog breed
36
  prediction_dict = {class_names[i]: np.round(float(prediction[0][i]), 2) for i in range(len(class_names))}
37
 
 
21
  # Apply softmax to get probabilities for each class
22
  prediction = tf.nn.softmax(prediction)
23
 
24
+ # Debug statement to check the shape of the prediction
25
+ print(f"Prediction shape: {prediction.shape}")
26
+
27
  # Define class names
28
  class_names = ['Afghan', 'African Wild Dog', 'Airedale', 'American Hairless', 'American Spaniel', 'Basenji', 'Basset', 'Beagle',
29
  'Bearded Collie', 'Bermaise', 'Bichon Frise', 'Blenheim', 'Bloodhound', 'Bluetick', 'Border Collie', 'Borzoi',
 
35
  'Poodle', 'Pug', 'Rhodesian', 'Rottweiler', 'Saint Bernard', 'Schnauzer', 'Scotch Terrier', 'Shar_Pei',
36
  'Shiba Inu', 'Shih-Tzu', 'Siberian Husky', 'Vizsla', 'Yorkie']
37
 
38
+ # Check if the number of predictions matches the number of class names
39
+ if len(prediction[0]) != len(class_names):
40
+ return f"Error: Number of model outputs ({len(prediction[0])}) does not match number of class names ({len(class_names)})."
41
+
42
  # Create a dictionary with the probabilities for each dog breed
43
  prediction_dict = {class_names[i]: np.round(float(prediction[0][i]), 2) for i in range(len(class_names))}
44