Spaces:
Running
Running
Goodnight7
commited on
Commit
•
250a4d7
1
Parent(s):
410eed3
Upload 2 files
Browse files- .gitattributes +1 -0
- app.py +45 -0
- best_unet_model.keras +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
best_unet_model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import cv2
|
4 |
+
from PIL import Image
|
5 |
+
import tensorflow as tf
|
6 |
+
from tensorflow.keras.models import load_model
|
7 |
+
|
8 |
+
@st.cache_resource
|
9 |
+
def load_unet_model():
|
10 |
+
return load_model('unet_model_epoch_29_val_loss_0.5760.keras')
|
11 |
+
|
12 |
+
model = load_unet_model()
|
13 |
+
|
14 |
+
def preprocess_image(image):
|
15 |
+
image = image.resize((256, 256))
|
16 |
+
image = np.array(image) / 255.0
|
17 |
+
image = np.expand_dims(image, axis=0)
|
18 |
+
return image
|
19 |
+
|
20 |
+
def predict_mask(image):
|
21 |
+
processed_image = preprocess_image(image)
|
22 |
+
predicted_mask = model.predict(processed_image)
|
23 |
+
predicted_mask = (predicted_mask > 0.5).astype(np.uint8)
|
24 |
+
return predicted_mask[0, :, :, 0]
|
25 |
+
|
26 |
+
st.title('Medical Image Segmentation with U-Net (Mohamed Arbi Nsibi)')
|
27 |
+
st.subheader("Note: The model's segmentation accuracy is not that accurate because of the small training dataset. Larger and more diverse data could improve performance ")
|
28 |
+
|
29 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
30 |
+
|
31 |
+
if uploaded_file is not None:
|
32 |
+
image = Image.open(uploaded_file)
|
33 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
34 |
+
|
35 |
+
if st.button('Segment Image'):
|
36 |
+
mask = predict_mask(image)
|
37 |
+
|
38 |
+
st.image(mask * 255, caption='Segmentation Mask', use_column_width=True)
|
39 |
+
|
40 |
+
overlay = np.zeros((256, 256, 3), dtype=np.uint8)
|
41 |
+
overlay[:,:,1] = mask * 255
|
42 |
+
original_resized = np.array(image.resize((256, 256)))
|
43 |
+
overlayed_image = cv2.addWeighted(original_resized, 0.7, overlay, 0.3, 0)
|
44 |
+
|
45 |
+
st.image(overlayed_image, caption='Segmentation Overlay', use_column_width=True)
|
best_unet_model.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c6e89b9e8b7a652cc12ee64f869523d4612ab736ea206600669e2505c4f4bf26
|
3 |
+
size 23890326
|