Duplicate from Paushigaa/semantic-segmentation-of-aerial-imagery
Browse filesCo-authored-by: Paushigaa S <[email protected]>
- .gitattributes +35 -0
- README.md +14 -0
- app.py +68 -0
- model/model.txt +1 -0
- model/satellite-segmentation-full.h5 +3 -0
- requirements.txt +5 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz 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
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Semantic Segmentation Of Aerial Imagery
|
3 |
+
emoji: 🌖
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.36.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: mit
|
11 |
+
duplicated_from: Paushigaa/semantic-segmentation-of-aerial-imagery
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.environ["SM_FRAMEWORK"] = "tf.keras"
|
3 |
+
from tensorflow import keras
|
4 |
+
import cv2
|
5 |
+
from PIL import Image
|
6 |
+
import numpy as np
|
7 |
+
import segmentation_models as sm
|
8 |
+
from matplotlib import pyplot as plt
|
9 |
+
import random
|
10 |
+
|
11 |
+
from keras import backend as K
|
12 |
+
from keras.models import load_model
|
13 |
+
import gradio as gr
|
14 |
+
|
15 |
+
def jaccard_coef(y_true, y_pred):
|
16 |
+
y_true_flatten = K.flatten(y_true)
|
17 |
+
y_pred_flatten = K.flatten(y_pred)
|
18 |
+
intersection = K.sum(y_true_flatten * y_pred_flatten)
|
19 |
+
final_coef_value = (intersection + 1.0) / (K.sum(y_true_flatten) + K.sum(y_pred_flatten) - intersection + 1.0)
|
20 |
+
return final_coef_value
|
21 |
+
|
22 |
+
weights = [0.1666, 0.1666, 0.1666, 0.1666, 0.1666, 0.1666]
|
23 |
+
dice_loss = sm.losses.DiceLoss(class_weights = weights)
|
24 |
+
focal_loss = sm.losses.CategoricalFocalLoss()
|
25 |
+
total_loss = dice_loss + (1 * focal_loss)
|
26 |
+
|
27 |
+
satellite_model = load_model('model/satellite-segmentation-full.h5',
|
28 |
+
custom_objects=({'dice_loss_plus_1focal_loss': total_loss,
|
29 |
+
'jaccard_coef': jaccard_coef}))
|
30 |
+
|
31 |
+
|
32 |
+
def process_input_image(image_source):
|
33 |
+
image = np.expand_dims(image_source, 0)
|
34 |
+
|
35 |
+
prediction = satellite_model.predict(image)
|
36 |
+
predicted_image = np.argmax(prediction, axis=3)
|
37 |
+
|
38 |
+
predicted_image = predicted_image[0,:,:]
|
39 |
+
predicted_image = predicted_image * 50
|
40 |
+
return 'Predicted Masked Image', predicted_image
|
41 |
+
|
42 |
+
my_app = gr.Blocks()
|
43 |
+
|
44 |
+
with my_app:
|
45 |
+
gr.Markdown("Statellite Image Segmentation Application UI with Gradio")
|
46 |
+
with gr.Tabs():
|
47 |
+
with gr.TabItem("Select your image"):
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column():
|
50 |
+
img_source = gr.Image(label="Please select source Image", shape=(256, 256))
|
51 |
+
source_image_loader = gr.Button("Load above Image")
|
52 |
+
with gr.Column():
|
53 |
+
output_label = gr.Label(label="Image Info")
|
54 |
+
img_output = gr.Image(label="Image Output")
|
55 |
+
source_image_loader.click(
|
56 |
+
process_input_image,
|
57 |
+
[
|
58 |
+
img_source
|
59 |
+
],
|
60 |
+
[
|
61 |
+
output_label,
|
62 |
+
img_output
|
63 |
+
]
|
64 |
+
)
|
65 |
+
|
66 |
+
my_app.launch(debug=True)
|
67 |
+
|
68 |
+
my_app.close()
|
model/model.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
This project detects various segmentations of satellite images using the U-Net model.
|
model/satellite-segmentation-full.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ea13be9dd68c5edb9072c85815e9be3db29650f5f327c9b4a31c6ae973511254
|
3 |
+
size 23503352
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
segmentation-models
|
2 |
+
gradio
|
3 |
+
opencv-python
|
4 |
+
keras
|
5 |
+
tensorflow
|