Kalbe-x-Bangkit commited on
Commit
1862f3a
1 Parent(s): 4055d22

Changing input of prediction function & move function to after enhancement.

Browse files
Files changed (1) hide show
  1. app.py +28 -19
app.py CHANGED
@@ -52,27 +52,14 @@ def load_model():
52
  )
53
  return model
54
 
55
- def preprocess_image(image):
56
- """ Preprocess the image to the required size and normalization. """
57
- image = cv2.resize(image, (W, H))
58
- image = (image - 127.5) / 127.5 # Normalize to [-1, +1]
59
- image = np.expand_dims(image, axis=0).astype(np.float32)
60
- return image
61
 
62
- def predict(model, image):
63
- """ Predict bounding box and label for the input image. """
64
- pred_bbox, pred_class = model.predict(image)
65
- pred_label_confidence = np.max(pred_class, axis=1)[0]
66
- pred_label = np.argmax(pred_class, axis=1)[0]
67
- return pred_bbox[0], pred_label, pred_label_confidence
68
 
69
- def draw_bbox(image, bbox):
70
- """ Draw bounding box on the image. """
71
- h, w, _ = image.shape
72
- x1, y1, x2, y2 = bbox
73
- x1, y1, x2, y2 = int(x1 * w), int(y1 * h), int(x2 * w), int(y2 * h)
74
- image = cv2.rectangle(image, (x1, y1), (x2, y2), (255, 0, 0), 2)
75
- return image
76
 
77
  # st.title("Chest X-ray Disease Detection")
78
 
@@ -352,6 +339,28 @@ def redirect_button(url):
352
  if button:
353
  st.markdown(f'<meta http-equiv="refresh" content="0;url={url}" />', unsafe_allow_html=True)
354
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  ###########################################################################################
356
  ########################### Streamlit Interface ###########################################
357
  ###########################################################################################
 
52
  )
53
  return model
54
 
55
+ # def preprocess_image(image):
56
+ # """ Preprocess the image to the required size and normalization. """
57
+ # image = cv2.resize(image, (W, H))
58
+ # image = (image - 127.5) / 127.5 # Normalize to [-1, +1]
59
+ # image = np.expand_dims(image, axis=0).astype(np.float32)
60
+ # return image
61
 
 
 
 
 
 
 
62
 
 
 
 
 
 
 
 
63
 
64
  # st.title("Chest X-ray Disease Detection")
65
 
 
339
  if button:
340
  st.markdown(f'<meta http-equiv="refresh" content="0;url={url}" />', unsafe_allow_html=True)
341
 
342
+
343
+ ###########################################################################################
344
+ ########################### Bounding Box Function ###########################################
345
+ ###########################################################################################
346
+
347
+
348
+ def predict(model, image):
349
+ """ Predict bounding box and label for the input image. """
350
+ pred_bbox, pred_class = model.predict(enhanced_image)
351
+ pred_label_confidence = np.max(pred_class, axis=1)[0]
352
+ pred_label = np.argmax(pred_class, axis=1)[0]
353
+ return pred_bbox[0], pred_label, pred_label_confidence
354
+
355
+ def draw_bbox(image, bbox):
356
+ """ Draw bounding box on the image. """
357
+ h, w, _ = image.shape
358
+ x1, y1, x2, y2 = bbox
359
+ x1, y1, x2, y2 = int(x1 * w), int(y1 * h), int(x2 * w), int(y2 * h)
360
+ image = cv2.rectangle(image, (x1, y1), (x2, y2), (255, 0, 0), 2)
361
+ return image
362
+
363
+
364
  ###########################################################################################
365
  ########################### Streamlit Interface ###########################################
366
  ###########################################################################################