Mohak Gupta commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import cv2
|
| 4 |
+
from keras.models import model_from_json
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def read_image(image_file):
|
| 8 |
+
image = cv2.imdecode(np.fromstring(image_file.read(), np.uint8), cv2.IMREAD_COLOR)
|
| 9 |
+
image = cv2.resize(image, (512, 512))
|
| 10 |
+
image = image / 255.0
|
| 11 |
+
image = image.astype(np.float32)
|
| 12 |
+
return image
|
| 13 |
+
|
| 14 |
+
with open("model.json", "r") as json_file:
|
| 15 |
+
model_json = json_file.read()
|
| 16 |
+
model = model_from_json(model_json)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
model.load_weights("model.h5")
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
st.title("Image Segmentation App")
|
| 23 |
+
uploaded_file = st.file_uploader("Upload an image for segmentation...", type=["jpg", "jpeg", "png"])
|
| 24 |
+
|
| 25 |
+
if uploaded_file is not None:
|
| 26 |
+
|
| 27 |
+
image = read_image(uploaded_file)
|
| 28 |
+
image = np.expand_dims(image, axis=0)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
y_pred = model.predict(image)[0]
|
| 32 |
+
y_pred = y_pred > 0.5
|
| 33 |
+
y_pred = y_pred.astype(np.uint8) * 255
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
st.image(uploaded_file, caption="Original Image")
|
| 37 |
+
st.image(y_pred, caption="Predicted Segmentation Mask")
|