Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,25 @@ import numpy as np
|
|
5 |
from PIL import Image
|
6 |
import base64
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|