Added Three files
Browse filesUplaoded SGDNet Model, app.py and Requirements.txt
- README.md +13 -3
- SGDNet.h5 +3 -0
- gradio_app.py +52 -0
- requirements.txt +7 -0
README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SGDNet Gradio Interface
|
| 2 |
+
|
| 3 |
+
This is a Gradio interface for the SGDNet model, which extracts glacier boundaries from multisource remote sensing data.
|
| 4 |
+
|
| 5 |
+
## Setup
|
| 6 |
+
|
| 7 |
+
1. Install the required packages:
|
| 8 |
+
pip install -r requirements.txt
|
| 9 |
+
|
| 10 |
+
2. Run the Gradio app:
|
| 11 |
+
python gradio_app.py
|
| 12 |
+
|
| 13 |
+
3. Open your browser to the provided local URL to interact with the interface.
|
SGDNet.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8db3ec659258f0998d97ad2fa550ba6325b2476b378ff57e0c5c040041fb5235
|
| 3 |
+
size 143376
|
gradio_app.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from pyrsgis import raster, convert
|
| 5 |
+
from sklearn.preprocessing import StandardScaler
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import io
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
model = tf.keras.models.load_model('SGDNet.h5')
|
| 11 |
+
|
| 12 |
+
def predict(image_path):
|
| 13 |
+
# Process the image file
|
| 14 |
+
ds, image_data = raster.read(image_path, bands='all')
|
| 15 |
+
image_data = convert.array_to_table(image_data)
|
| 16 |
+
scaler = StandardScaler()
|
| 17 |
+
image_data = scaler.fit_transform(image_data)
|
| 18 |
+
image_data = image_data.reshape((image_data.shape[0], 1, image_data.shape[1]))
|
| 19 |
+
|
| 20 |
+
# Make prediction
|
| 21 |
+
predicted = model.predict(image_data)
|
| 22 |
+
predicted_prob = predicted[:, 1]
|
| 23 |
+
predicted_prob = np.reshape(predicted_prob, (ds.RasterYSize, ds.RasterXSize))
|
| 24 |
+
|
| 25 |
+
# Convert prediction to image
|
| 26 |
+
im = Image.fromarray((predicted_prob * 255).astype(np.uint8))
|
| 27 |
+
bio = io.BytesIO()
|
| 28 |
+
im.save(bio, format='PNG')
|
| 29 |
+
return bio.getvalue()
|
| 30 |
+
|
| 31 |
+
def save_uploaded_file(uploaded_file):
|
| 32 |
+
with open(uploaded_file.name, "wb") as f:
|
| 33 |
+
f.write(uploaded_file.getbuffer())
|
| 34 |
+
return uploaded_file.name
|
| 35 |
+
|
| 36 |
+
with gr.Blocks() as app:
|
| 37 |
+
with gr.Row():
|
| 38 |
+
with gr.Column():
|
| 39 |
+
file_input = gr.File(label="Upload your satellite image")
|
| 40 |
+
submit_button = gr.Button("Predict")
|
| 41 |
+
with gr.Column():
|
| 42 |
+
image_output = gr.Image(label="Predicted Glacier Boundaries")
|
| 43 |
+
|
| 44 |
+
submit_button.click(
|
| 45 |
+
fn=lambda x: predict(save_uploaded_file(x)),
|
| 46 |
+
inputs=file_input,
|
| 47 |
+
outputs=image_output
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
app.launch()
|
| 52 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
tensorflow
|
| 3 |
+
pyrsgis
|
| 4 |
+
scikit-learn
|
| 5 |
+
matplotlib
|
| 6 |
+
pandas
|
| 7 |
+
|