Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,20 +6,17 @@ import segmentation_models as sm
|
|
| 6 |
from matplotlib import pyplot as plt
|
| 7 |
import random
|
| 8 |
|
| 9 |
-
|
| 10 |
from keras import backend as K
|
| 11 |
-
from keras.models import load_model
|
| 12 |
-
|
| 13 |
|
| 14 |
import gradio as gr
|
| 15 |
|
| 16 |
-
|
| 17 |
def jaccard_coef(y_true, y_pred):
|
| 18 |
y_true_flatten = K.flatten(y_true)
|
| 19 |
y_pred_flatten = K.flatten(y_pred)
|
| 20 |
intersection = K.sum(y_true_flatten * y_pred_flatten)
|
| 21 |
final_coef_value = (intersection + 1.0) / (K.sum(y_true_flatten) + K.sum(y_pred_flatten) - intersection + 1.0)
|
| 22 |
-
return final_coef_value
|
| 23 |
|
| 24 |
weights = [0.2,0.2,0.2,0.2,0.2]
|
| 25 |
dice_loss = sm.losses.DiceLoss(class_weights = weights)
|
|
@@ -29,6 +26,7 @@ total_loss = dice_loss + (1 * focal_loss)
|
|
| 29 |
satellite_model = load_model('model/C:/Users/sa/Desktop/Model_Training/satellite_segmentation_full.h5',
|
| 30 |
custom_objects=({'dice_loss_plus_1focal_loss': total_loss,|'jaccard_coef': jaccard_coef}))
|
| 31 |
|
|
|
|
| 32 |
def process_input_image(image_source):
|
| 33 |
image = np.expand_dims(image_source, 0)
|
| 34 |
|
|
@@ -39,10 +37,8 @@ def process_input_image(image_source):
|
|
| 39 |
predicted_colored = predicted_colored * 50
|
| 40 |
return 'Predicted Masked Image', predicted_colored
|
| 41 |
|
| 42 |
-
|
| 43 |
my_app = gr.Blocks()
|
| 44 |
|
| 45 |
-
|
| 46 |
with my_app:
|
| 47 |
gr.Markdown("Statellite Image Segmentation Application UI with Gradio")
|
| 48 |
with gr.Tabs():
|
|
@@ -55,15 +51,14 @@ with my_app:
|
|
| 55 |
output_label = gr.Label(label="Image Info")
|
| 56 |
img_output = gr.Image(label="Image Output")
|
| 57 |
source_image_loader.click(
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
my_app.launch(debug=True)
|
|
|
|
| 6 |
from matplotlib import pyplot as plt
|
| 7 |
import random
|
| 8 |
|
|
|
|
| 9 |
from keras import backend as K
|
| 10 |
+
from keras.models import load_model
|
|
|
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
|
|
|
|
| 14 |
def jaccard_coef(y_true, y_pred):
|
| 15 |
y_true_flatten = K.flatten(y_true)
|
| 16 |
y_pred_flatten = K.flatten(y_pred)
|
| 17 |
intersection = K.sum(y_true_flatten * y_pred_flatten)
|
| 18 |
final_coef_value = (intersection + 1.0) / (K.sum(y_true_flatten) + K.sum(y_pred_flatten) - intersection + 1.0)
|
| 19 |
+
return final_coef_value
|
| 20 |
|
| 21 |
weights = [0.2,0.2,0.2,0.2,0.2]
|
| 22 |
dice_loss = sm.losses.DiceLoss(class_weights = weights)
|
|
|
|
| 26 |
satellite_model = load_model('model/C:/Users/sa/Desktop/Model_Training/satellite_segmentation_full.h5',
|
| 27 |
custom_objects=({'dice_loss_plus_1focal_loss': total_loss,|'jaccard_coef': jaccard_coef}))
|
| 28 |
|
| 29 |
+
|
| 30 |
def process_input_image(image_source):
|
| 31 |
image = np.expand_dims(image_source, 0)
|
| 32 |
|
|
|
|
| 37 |
predicted_colored = predicted_colored * 50
|
| 38 |
return 'Predicted Masked Image', predicted_colored
|
| 39 |
|
|
|
|
| 40 |
my_app = gr.Blocks()
|
| 41 |
|
|
|
|
| 42 |
with my_app:
|
| 43 |
gr.Markdown("Statellite Image Segmentation Application UI with Gradio")
|
| 44 |
with gr.Tabs():
|
|
|
|
| 51 |
output_label = gr.Label(label="Image Info")
|
| 52 |
img_output = gr.Image(label="Image Output")
|
| 53 |
source_image_loader.click(
|
| 54 |
+
process_input_image,
|
| 55 |
+
[
|
| 56 |
+
img_source
|
| 57 |
+
],
|
| 58 |
+
[
|
| 59 |
+
output_label,
|
| 60 |
+
img_output
|
| 61 |
+
]
|
| 62 |
+
)
|
|
|
|
| 63 |
|
| 64 |
my_app.launch(debug=True)
|