Kalbe-x-Bangkit commited on
Commit
33daad3
·
verified ·
1 Parent(s): a647110

Change model to mode_detection.

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -37,7 +37,7 @@ H = 224
37
  W = 224
38
 
39
  @st.cache_resource
40
- def load_model():
41
  model = tf.keras.models.load_model("model-detection.h5", compile=False)
42
  model.compile(
43
  loss={
@@ -65,7 +65,7 @@ def load_model():
65
 
66
  # st.write("Upload a chest X-ray image and click on 'Detect' to find out if there's any disease.")
67
 
68
- model = load_model()
69
 
70
  # uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
71
 
@@ -353,9 +353,9 @@ def redirect_button(url):
353
  ###########################################################################################
354
 
355
 
356
- def predict(model, image):
357
  """ Predict bounding box and label for the input image. """
358
- pred_bbox, pred_class = model.predict(image)
359
  pred_label_confidence = np.max(pred_class, axis=1)[0]
360
  pred_label = np.argmax(pred_class, axis=1)[0]
361
  return pred_bbox[0], pred_label, pred_label_confidence
@@ -472,7 +472,7 @@ if uploaded_file is not None:
472
  input_image = cv2.resize(enhanced_image, (W, H)) # Resize the enhanced image to the required input size
473
  input_image = (input_image - 127.5) / 127.5 # Normalize to [-1, +1]
474
  input_image = np.expand_dims(input_image, axis=0).astype(np.float32) # Expand dimensions and convert to float32
475
- pred_bbox, pred_label, pred_label_confidence = predict(model, input_image)
476
 
477
  # Updated label mapping based on the dataset
478
  label_mapping = {
 
37
  W = 224
38
 
39
  @st.cache_resource
40
+ def load_model_detection():
41
  model = tf.keras.models.load_model("model-detection.h5", compile=False)
42
  model.compile(
43
  loss={
 
65
 
66
  # st.write("Upload a chest X-ray image and click on 'Detect' to find out if there's any disease.")
67
 
68
+ model_detection = load_model_detection()
69
 
70
  # uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
71
 
 
353
  ###########################################################################################
354
 
355
 
356
+ def predict(model_detection, image):
357
  """ Predict bounding box and label for the input image. """
358
+ pred_bbox, pred_class = model_detection.predict(image)
359
  pred_label_confidence = np.max(pred_class, axis=1)[0]
360
  pred_label = np.argmax(pred_class, axis=1)[0]
361
  return pred_bbox[0], pred_label, pred_label_confidence
 
472
  input_image = cv2.resize(enhanced_image, (W, H)) # Resize the enhanced image to the required input size
473
  input_image = (input_image - 127.5) / 127.5 # Normalize to [-1, +1]
474
  input_image = np.expand_dims(input_image, axis=0).astype(np.float32) # Expand dimensions and convert to float32
475
+ pred_bbox, pred_label, pred_label_confidence = predict(model_detection, input_image)
476
 
477
  # Updated label mapping based on the dataset
478
  label_mapping = {