AndrewMaru commited on
Commit
000b659
·
verified ·
1 Parent(s): 2a97a5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -3,15 +3,14 @@ import tensorflow as tf
3
  import numpy as np
4
  from PIL import Image
5
 
6
- st.title("🌊 Flood Segmentation with U-Net (TF SavedModel)")
7
 
8
  @st.cache_resource
9
  def load_model():
10
- model = tf.saved_model.load("unet_savedmodel")
11
- infer = model.signatures["serving_default"]
12
- return infer
13
 
14
- infer = load_model()
15
 
16
  uploaded = st.file_uploader("Upload flood image", type=["jpg", "jpeg", "png"])
17
 
@@ -22,9 +21,9 @@ if uploaded:
22
  x = np.array(img_resized, dtype=np.float32) / 255.0
23
  x = np.expand_dims(x, axis=0)
24
 
25
- pred = infer(tf.constant(x))["conv2d_9"].numpy()[0, :, :, 0]
26
 
27
  mask = (pred > 0.5).astype(np.uint8) * 255
28
 
29
  st.image(img, caption="Original Image")
30
- st.image(mask, caption="Predicted Mask", clamp=True)
 
3
  import numpy as np
4
  from PIL import Image
5
 
6
+ st.title("🌊 Flood Segmentation with U-Net")
7
 
8
  @st.cache_resource
9
  def load_model():
10
+ model = tf.keras.models.load_model("unet_savedmodel", compile=False)
11
+ return model
 
12
 
13
+ model = load_model()
14
 
15
  uploaded = st.file_uploader("Upload flood image", type=["jpg", "jpeg", "png"])
16
 
 
21
  x = np.array(img_resized, dtype=np.float32) / 255.0
22
  x = np.expand_dims(x, axis=0)
23
 
24
+ pred = model.predict(x)[0, :, :, 0]
25
 
26
  mask = (pred > 0.5).astype(np.uint8) * 255
27
 
28
  st.image(img, caption="Original Image")
29
+ st.image(mask, caption="Segmentation Mask", clamp=True)