subek commited on
Commit
259568f
·
verified ·
1 Parent(s): d4f1ac4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -5,9 +5,25 @@ import numpy as np
5
  from PIL import Image
6
  import base64
7
 
8
- # Load the pre-trained brain tumor segmentation model
9
- model = tf.keras.models.load_model("model.h5")
10
- img_size = (256, 256) # Adjust based on your model's input size
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  st.set_page_config(
13
  page_title="Brain Tumor Segmentation App",
@@ -28,12 +44,9 @@ custom_style = """
28
  }
29
  </style>
30
  """
31
-
32
  st.markdown(custom_style, unsafe_allow_html=True)
33
 
34
 
35
-
36
-
37
  def main():
38
  st.title("Brain Tumor Segmentation App")
39
 
 
5
  from PIL import Image
6
  import base64
7
 
8
+ H = 256
9
+ W = 256
10
+ smooth = 1e-15
11
+
12
+ def dice_loss(y_true, y_pred):
13
+ y_true = tf.keras.layers.Flatten()(y_true)
14
+ y_pred = tf.keras.layers.Flatten()(y_pred)
15
+ intersection = tf.reduce_sum(y_true * y_pred)
16
+ return 1.0 - (2. * intersection + smooth) / (tf.reduce_sum(y_true) + tf.reduce_sum(y_pred) + smooth)
17
+
18
+ def dice_coef(y_true, y_pred):
19
+ y_true = tf.keras.layers.Flatten()(y_true)
20
+ y_pred = tf.keras.layers.Flatten()(y_pred)
21
+ intersection = tf.reduce_sum(y_true * y_pred)
22
+ return (2. * intersection + smooth) / (tf.reduce_sum(y_true) + tf.reduce_sum(y_pred) + smooth)
23
+
24
+ model_path = "model.h5"
25
+
26
+ model = tf.keras.models.load_model(model_path,custom_objects={'dice_loss': dice_loss, 'dice_coef': dice_coef})
27
 
28
  st.set_page_config(
29
  page_title="Brain Tumor Segmentation App",
 
44
  }
45
  </style>
46
  """
 
47
  st.markdown(custom_style, unsafe_allow_html=True)
48
 
49
 
 
 
50
  def main():
51
  st.title("Brain Tumor Segmentation App")
52