Heizsenberg commited on
Commit
c27bcf0
·
1 Parent(s): 5e562ec

fix prediction

Browse files
Files changed (1) hide show
  1. src/prediction.py +3 -2
src/prediction.py CHANGED
@@ -33,6 +33,7 @@ def load_model_from_hub():
33
 
34
  def predict_image(model, img):
35
  # Preprocess
 
36
  img = img.resize((128, 128))
37
  img_array = np.array(img) / 255.0
38
  img_array = np.expand_dims(img_array, axis=0)
@@ -66,11 +67,11 @@ def run():
66
  # To read image file buffer as a PIL Image:
67
  img = Image.open(uploaded_file)
68
 
69
- image, predicted_class, probs = predict_image(
70
  classifier_model, img
71
  )
72
 
73
- confidence = np.max(probs) * 100
74
 
75
  # show result
76
  st.image(img, caption="Uploaded Image", use_container_width=True)
 
33
 
34
  def predict_image(model, img):
35
  # Preprocess
36
+ img = img.convert("RGB") # VERY IMPORTANT
37
  img = img.resize((128, 128))
38
  img_array = np.array(img) / 255.0
39
  img_array = np.expand_dims(img_array, axis=0)
 
67
  # To read image file buffer as a PIL Image:
68
  img = Image.open(uploaded_file)
69
 
70
+ image, predicted_class, confidence = predict_image(
71
  classifier_model, img
72
  )
73
 
74
+ confidence = confidence * 100
75
 
76
  # show result
77
  st.image(img, caption="Uploaded Image", use_container_width=True)