alwin00007
commited on
Commit
•
b6cd222
1
Parent(s):
21fe347
uploaded model
Browse files- .gitattributes +1 -0
- app.py +82 -0
- segnet.ipynb +0 -0
- segnet_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 |
+
segnet_model.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
from tensorflow.keras.preprocessing.image import img_to_array
|
5 |
+
from PIL import Image
|
6 |
+
import matplotlib.pyplot as plt
|
7 |
+
from matplotlib.colors import ListedColormap
|
8 |
+
|
9 |
+
# Load the trained model
|
10 |
+
@st.cache_resource
|
11 |
+
def load_trained_model():
|
12 |
+
model_path = "segnet_model.keras"
|
13 |
+
return load_model(model_path)
|
14 |
+
|
15 |
+
def predict_segmentation(model, image, target_size=(256, 256)):
|
16 |
+
image = image.resize(target_size)
|
17 |
+
image_array = img_to_array(image) / 255.0
|
18 |
+
image_array = np.expand_dims(image_array, axis=0)
|
19 |
+
|
20 |
+
prediction = model.predict(image_array)[0]
|
21 |
+
return prediction
|
22 |
+
|
23 |
+
def create_mask_plot(mask, colormap, labels):
|
24 |
+
|
25 |
+
|
26 |
+
fig, ax = plt.subplots(figsize=(5, 5))
|
27 |
+
ax.imshow(mask.squeeze(), cmap=colormap, vmin=0, vmax=len(labels) - 1)
|
28 |
+
ax.axis("off")
|
29 |
+
|
30 |
+
# Add a legend
|
31 |
+
legend_patches = [
|
32 |
+
plt.Line2D([0], [0], color=colormap.colors[i], lw=4, label=label)
|
33 |
+
for i, label in enumerate(labels)
|
34 |
+
]
|
35 |
+
ax.legend(handles=legend_patches, loc="upper right", bbox_to_anchor=(1.2, 1.0))
|
36 |
+
|
37 |
+
# Convert the Matplotlib figure to a PIL Image
|
38 |
+
fig.canvas.draw()
|
39 |
+
image = np.array(fig.canvas.renderer.buffer_rgba())
|
40 |
+
plt.close(fig)
|
41 |
+
return Image.fromarray(image)
|
42 |
+
|
43 |
+
# Streamlit App
|
44 |
+
def main():
|
45 |
+
st.title("Flood Area Segmentation")
|
46 |
+
st.write("Upload an image to predict its segmentation mask.")
|
47 |
+
|
48 |
+
# Load the model (cached)
|
49 |
+
model = load_trained_model()
|
50 |
+
|
51 |
+
# File uploader
|
52 |
+
uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "png", "jpeg"])
|
53 |
+
|
54 |
+
if uploaded_file is not None:
|
55 |
+
# Load and display the uploaded image
|
56 |
+
image = Image.open(uploaded_file)
|
57 |
+
|
58 |
+
# Predict segmentation
|
59 |
+
with st.spinner("Predicting..."):
|
60 |
+
predicted_mask = predict_segmentation(model, image)
|
61 |
+
|
62 |
+
# Define custom colormap and labels
|
63 |
+
colormap = ListedColormap(["green", "blue"]) # Green: Non-Flooded, Blue: Flooded
|
64 |
+
labels = ["Non-Flooded Area", "Flooded Area"]
|
65 |
+
|
66 |
+
# Create the mask visualization
|
67 |
+
mask_image = create_mask_plot(predicted_mask, colormap, labels)
|
68 |
+
|
69 |
+
# Display results side by side
|
70 |
+
st.subheader("Results")
|
71 |
+
col1, col2 = st.columns(2)
|
72 |
+
|
73 |
+
with col1:
|
74 |
+
st.write("### Original Image")
|
75 |
+
st.image(image, caption="Original Image", use_container_width=True)
|
76 |
+
|
77 |
+
with col2:
|
78 |
+
st.write("### Predicted Mask")
|
79 |
+
st.image(mask_image, caption="Predicted Mask", use_container_width=True)
|
80 |
+
|
81 |
+
if __name__ == "__main__":
|
82 |
+
main()
|
segnet.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
segnet_model.keras
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7aef0d401c2621df674127e2801f42e1cd74057abb9089db1c2377fccad7fccd
|
3 |
+
size 211961251
|