osherr commited on
Commit
a3961aa
·
verified ·
1 Parent(s): e9f8684

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -77,6 +77,9 @@ if uploaded_image:
77
 
78
  st.image(image, caption="Input Image", use_column_width=True)
79
 
 
 
 
80
  # Preprocess and predict
81
  resized = image.resize((512, 512))
82
  x = np.expand_dims(np.array(resized), axis=0)
@@ -84,9 +87,8 @@ if uploaded_image:
84
 
85
  st.text(f"Prediction min/max: {y.min():.5f} / {y.max():.5f}")
86
 
87
- # Normalize output
88
- y_norm = (y - y.min()) / (y.max() - y.min() + 1e-6)
89
- mask = (y_norm * 255).astype(np.uint8)
90
- result = Image.fromarray(mask)
91
 
92
- st.image(result, caption="Predicted Segmentation", use_column_width=True)
 
77
 
78
  st.image(image, caption="Input Image", use_column_width=True)
79
 
80
+ # Confidence threshold slider
81
+ threshold = st.slider("Confidence Threshold", 0.0, 1.0, 0.5, step=0.01)
82
+
83
  # Preprocess and predict
84
  resized = image.resize((512, 512))
85
  x = np.expand_dims(np.array(resized), axis=0)
 
87
 
88
  st.text(f"Prediction min/max: {y.min():.5f} / {y.max():.5f}")
89
 
90
+ # Apply thresholding if needed
91
+ mask_bin = (y > threshold).astype(np.uint8) * 255
92
+ mask_image = Image.fromarray(mask_bin)
 
93
 
94
+ st.image(mask_image, caption=f"Segmentation Mask (Threshold = {threshold:.2f})", use_column_width=True)