Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ import shutil
|
|
| 10 |
import rasterio
|
| 11 |
import cv2
|
| 12 |
import tensorflow as tf
|
|
|
|
| 13 |
|
| 14 |
# Configuration
|
| 15 |
HEIGHT = WIDTH = 256
|
|
@@ -106,7 +107,14 @@ def normalizeImages(images, typeData):
|
|
| 106 |
print("(INFO..) Normalization Image Done")
|
| 107 |
return np.array(normalized_images)
|
| 108 |
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
# Streamlit App Title
|
| 111 |
st.title("Satellite Mining Segmentation: SAR + Optic Image Inference")
|
| 112 |
|
|
@@ -120,19 +128,28 @@ num_samples = st.slider("Number of test samples to visualize", 1, 10, 3)
|
|
| 120 |
if sar_file is not None and optic_file is not None and mask_file is not None:
|
| 121 |
st.success("All files uploaded successfully!")
|
| 122 |
st.write(f"Number of samples selected for visualization: {num_samples}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
else:
|
| 124 |
st.warning("Please upload all three .tiff files to proceed.")
|
| 125 |
|
| 126 |
-
sarImages = [
|
| 127 |
-
opticImages = [
|
| 128 |
-
masks = [
|
| 129 |
model_path = "Residual_UNET_Bilinear.keras"
|
| 130 |
|
| 131 |
|
| 132 |
if st.button("Run Inference"):
|
| 133 |
with st.spinner("Loading data and model..."):
|
| 134 |
|
| 135 |
-
|
| 136 |
sar_images = readImages(sarImages, typeData='s', width=WIDTH, height=HEIGHT)
|
| 137 |
optic_images = readImages(opticImages, typeData='o', width=WIDTH, height=HEIGHT)
|
| 138 |
masks = readImages(masks, typeData='m', width=WIDTH, height=HEIGHT)
|
|
|
|
| 10 |
import rasterio
|
| 11 |
import cv2
|
| 12 |
import tensorflow as tf
|
| 13 |
+
import tempfile
|
| 14 |
|
| 15 |
# Configuration
|
| 16 |
HEIGHT = WIDTH = 256
|
|
|
|
| 107 |
print("(INFO..) Normalization Image Done")
|
| 108 |
return np.array(normalized_images)
|
| 109 |
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def save_uploaded_file(uploaded_file, suffix=".tif"):
|
| 113 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as tmp:
|
| 114 |
+
tmp.write(uploaded_file.read())
|
| 115 |
+
return tmp.name
|
| 116 |
+
|
| 117 |
+
|
| 118 |
# Streamlit App Title
|
| 119 |
st.title("Satellite Mining Segmentation: SAR + Optic Image Inference")
|
| 120 |
|
|
|
|
| 128 |
if sar_file is not None and optic_file is not None and mask_file is not None:
|
| 129 |
st.success("All files uploaded successfully!")
|
| 130 |
st.write(f"Number of samples selected for visualization: {num_samples}")
|
| 131 |
+
sar_path = save_uploaded_file(sar_file, suffix=".tif")
|
| 132 |
+
optic_path = save_uploaded_file(optic_file, suffix=".tif")
|
| 133 |
+
mask_path = save_uploaded_file(mask_file, suffix=".tif")
|
| 134 |
+
|
| 135 |
+
st.write("Temporary paths created for inference:")
|
| 136 |
+
st.code(f"SAR Path: {sar_path}")
|
| 137 |
+
st.code(f"Optic Path: {optic_path}")
|
| 138 |
+
st.code(f"Mask Path: {mask_path}")
|
| 139 |
+
|
| 140 |
+
|
| 141 |
else:
|
| 142 |
st.warning("Please upload all three .tiff files to proceed.")
|
| 143 |
|
| 144 |
+
sarImages = [sar_path]
|
| 145 |
+
opticImages = [optic_path]
|
| 146 |
+
masks = [mask_path]
|
| 147 |
model_path = "Residual_UNET_Bilinear.keras"
|
| 148 |
|
| 149 |
|
| 150 |
if st.button("Run Inference"):
|
| 151 |
with st.spinner("Loading data and model..."):
|
| 152 |
|
|
|
|
| 153 |
sar_images = readImages(sarImages, typeData='s', width=WIDTH, height=HEIGHT)
|
| 154 |
optic_images = readImages(opticImages, typeData='o', width=WIDTH, height=HEIGHT)
|
| 155 |
masks = readImages(masks, typeData='m', width=WIDTH, height=HEIGHT)
|