Spaces:
Sleeping
Sleeping
v1
Browse files- .gitattributes +2 -0
- app.py +158 -0
- article.html +3 -0
- color_download_me.png +0 -0
- examples/2013-04-14-15-42-53_L8_DUCK_SDS_BENCHMARK_rgb_pan.jpg +3 -0
- examples/2017-09-02-18-46-11_RGB_L8.jpg +3 -0
- examples/2019-03-05-10-47-51_L8_TRUCVERT_SDS_BENCHMARK_rgb_pan.jpg +3 -0
- examples/20190715T154911_N0213_R054_T18TWL_20190715T200600_010646.jpg +3 -0
- examples/20190730T154819_20190730T155818_T18SVF_lrr_db.jpg +3 -0
- examples/20190804T154911_20190804T160118_T18SVF_lrr_ID1.jpg +3 -0
- examples/20191124T154549_20191124T154739_T18SVF_lrr_db.jpg +3 -0
- examples/20191128T144731_N0213_R139_T20PLS_20191128T171514_013769.jpg +3 -0
- examples/20191222T125301_N0213_R052_T24MXV_20191222T144240_016520.jpg +3 -0
- examples/20200207T113309_N0214_R080_T28PCA_20200207T132518_020527.jpg +3 -0
- examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_022656.jpg +3 -0
- examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_023215.jpg +3 -0
- examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_023538.jpg +3 -0
- examples/2021-09-17-18-22-50_L8_TORREYPINES_SDS_BENCHMARK_rgb_pan.jpg +3 -0
- examples/2021-10-26-23-44-09_L8_NARRABEEN_SDS_BENCHMARK_rgb_pan.jpg +3 -0
- greyscale_download_me.png +0 -0
- overlay_download_me.png +0 -0
- requirements.txt +5 -0
- saved_model/keras_metadata.pb +3 -0
- saved_model/saved_model.pb +3 -0
- saved_model/variables/variables.data-00000-of-00001 +3 -0
- saved_model/variables/variables.index +3 -0
.gitattributes
CHANGED
@@ -32,3 +32,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
32 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
35 |
+
examples/*.* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
saved_model/*.* filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import os
|
4 |
+
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
|
5 |
+
from glob import glob
|
6 |
+
|
7 |
+
import tensorflow as tf
|
8 |
+
import matplotlib.pyplot as plt
|
9 |
+
from skimage.transform import resize
|
10 |
+
from skimage.io import imsave
|
11 |
+
from skimage.filters import threshold_otsu
|
12 |
+
|
13 |
+
from doodleverse_utils.prediction_imports import *
|
14 |
+
from doodleverse_utils.imports import *
|
15 |
+
|
16 |
+
|
17 |
+
#load model
|
18 |
+
filepath = './saved_model'
|
19 |
+
model = tf.keras.models.load_model(filepath, compile = True)
|
20 |
+
model.compile
|
21 |
+
|
22 |
+
#segmentation
|
23 |
+
def segment(input_img, use_tta, use_otsu, dims=(512, 512)):
|
24 |
+
|
25 |
+
N = 4
|
26 |
+
|
27 |
+
if use_otsu:
|
28 |
+
print("Use Otsu threshold")
|
29 |
+
else:
|
30 |
+
print("No Otsu threshold")
|
31 |
+
|
32 |
+
if use_tta:
|
33 |
+
print("Use TTA")
|
34 |
+
else:
|
35 |
+
print("Do not use TTA")
|
36 |
+
|
37 |
+
|
38 |
+
worig, horig, channels = input_img.shape
|
39 |
+
|
40 |
+
w, h = dims[0], dims[1]
|
41 |
+
|
42 |
+
print("Original dimensions {}x{}".format(worig,horig))
|
43 |
+
print("New dimensions {}x{}".format(w,h))
|
44 |
+
|
45 |
+
img = standardize(input_img)
|
46 |
+
|
47 |
+
img = resize(img, dims, preserve_range=True, clip=True)
|
48 |
+
|
49 |
+
img = np.expand_dims(img,axis=0)
|
50 |
+
|
51 |
+
est_label = model.predict(img)
|
52 |
+
|
53 |
+
if use_tta:
|
54 |
+
#Test Time Augmentation
|
55 |
+
est_label2 = np.flipud(model.predict((np.flipud(img)), batch_size=1))
|
56 |
+
est_label3 = np.fliplr(model.predict((np.fliplr(img)), batch_size=1))
|
57 |
+
est_label4 = np.flipud(np.fliplr(model.predict((np.flipud(np.fliplr(img))))))
|
58 |
+
|
59 |
+
#soft voting - sum the softmax scores to return the new TTA estimated softmax scores
|
60 |
+
est_label = est_label + est_label2 + est_label3 + est_label4
|
61 |
+
est_label /= 4
|
62 |
+
|
63 |
+
pred = np.squeeze(est_label, axis=0)
|
64 |
+
pred = resize(pred, (worig, horig), preserve_range=True, clip=True)
|
65 |
+
|
66 |
+
mask = np.argmax(pred,-1)
|
67 |
+
|
68 |
+
imsave("greyscale_download_me.png", mask.astype('uint8'))
|
69 |
+
|
70 |
+
class_label_colormap = [
|
71 |
+
"#3366CC",
|
72 |
+
"#DC3912",
|
73 |
+
"#FF9900",
|
74 |
+
"#109618",
|
75 |
+
"#990099",
|
76 |
+
"#0099C6",
|
77 |
+
"#DD4477",
|
78 |
+
"#66AA00",
|
79 |
+
"#B82E2E",
|
80 |
+
"#316395",
|
81 |
+
]
|
82 |
+
|
83 |
+
# add classes
|
84 |
+
class_label_colormap = class_label_colormap[:N]
|
85 |
+
|
86 |
+
color_label = label_to_colors(
|
87 |
+
mask,
|
88 |
+
input_img[:, :, 0] == 0,
|
89 |
+
alpha=128,
|
90 |
+
colormap=class_label_colormap,
|
91 |
+
color_class_offset=0,
|
92 |
+
do_alpha=False,
|
93 |
+
)
|
94 |
+
|
95 |
+
imsave("color_download_me.png", color_label)
|
96 |
+
|
97 |
+
|
98 |
+
if use_otsu:
|
99 |
+
c1 = pred[:,:,0]
|
100 |
+
c2 = pred[:,:,1]
|
101 |
+
water = c1+c2
|
102 |
+
water /= water.max()
|
103 |
+
thres = threshold_otsu(water)
|
104 |
+
print("Otsu threshold is {}".format(thres))
|
105 |
+
water_nowater = (water>thres).astype('uint8')
|
106 |
+
else:
|
107 |
+
water_nowater = (mask>1).astype('uint8')
|
108 |
+
|
109 |
+
|
110 |
+
#overlay plot
|
111 |
+
plt.clf()
|
112 |
+
plt.subplot(121)
|
113 |
+
plt.imshow(input_img[:,:,-1],cmap='gray')
|
114 |
+
plt.imshow(color_label, alpha=0.4)
|
115 |
+
plt.axis("off")
|
116 |
+
plt.margins(x=0, y=0)
|
117 |
+
|
118 |
+
plt.subplot(122)
|
119 |
+
plt.imshow(input_img[:,:,-1],cmap='gray')
|
120 |
+
plt.contour(water_nowater, levels=[0], colors='r')
|
121 |
+
plt.axis("off")
|
122 |
+
plt.margins(x=0, y=0)
|
123 |
+
|
124 |
+
plt.savefig("overlay_download_me.png", dpi=300, bbox_inches="tight")
|
125 |
+
|
126 |
+
return color_label, plt , "greyscale_download_me.png", "color_download_me.png", "overlay_download_me.png"
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
with open("article.html", "r", encoding='utf-8') as f:
|
131 |
+
article= f.read()
|
132 |
+
|
133 |
+
title = "Segment Satellite imagery"
|
134 |
+
description = "This simple model demonstration segments 15-m Landsat-7/8 or 10-m Sentinel-2 RGB (visible spectrum) imagery into the following classes: 1. water (unbroken water); 2. whitewater (surf, active wave breaking); 3. sediment (natural deposits of sand. gravel, mud, etc), and 4. other (development, bare terrain, vegetated terrain, etc). Please note that, ordinarily, ensemble models are used in predictive mode. Here, we are using just one model, i.e. without ensembling. Allows upload of 3-band imagery in jpg format and download of label imagery only one at a time. "
|
135 |
+
|
136 |
+
examples= [[l] for l in glob('examples/*.jpg')]
|
137 |
+
|
138 |
+
inp = gr.Image()
|
139 |
+
out1 = gr.Image(type='numpy')
|
140 |
+
out2 = gr.Plot(type='matplotlib')
|
141 |
+
out3 = gr.File()
|
142 |
+
out4 = gr.File()
|
143 |
+
out5 = gr.File()
|
144 |
+
|
145 |
+
inp2 = gr.inputs.Checkbox(default=False, label="Use TTA")
|
146 |
+
inp3 = gr.inputs.Checkbox(default=False, label="Use Otsu")
|
147 |
+
|
148 |
+
Segapp = gr.Interface(segment, [inp, inp2, inp3],
|
149 |
+
[out1, out2, out3, out4, out5],
|
150 |
+
title = title, description = description, examples=examples, article=article,
|
151 |
+
theme="grass")
|
152 |
+
|
153 |
+
Segapp.launch(enable_queue=True)
|
154 |
+
|
155 |
+
|
156 |
+
|
157 |
+
|
158 |
+
|
article.html
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
<p style='text-align: center'>
|
2 |
+
<a href='https://github.com/Doodleverse' target='_blank'>Part of the Doodleverse</a> | <a href='https://github.com/MARDAScience' target='_blank'>MARDAScience Github Repo</a> | <a href='https://zenodo.org/record/6950472#.Y4knOjPMLRY' target='_blank'>Zenodo model repository</a>
|
3 |
+
</p>
|
color_download_me.png
ADDED
![]() |
examples/2013-04-14-15-42-53_L8_DUCK_SDS_BENCHMARK_rgb_pan.jpg
ADDED
![]() |
Git LFS Details
|
examples/2017-09-02-18-46-11_RGB_L8.jpg
ADDED
![]() |
Git LFS Details
|
examples/2019-03-05-10-47-51_L8_TRUCVERT_SDS_BENCHMARK_rgb_pan.jpg
ADDED
![]() |
Git LFS Details
|
examples/20190715T154911_N0213_R054_T18TWL_20190715T200600_010646.jpg
ADDED
![]() |
Git LFS Details
|
examples/20190730T154819_20190730T155818_T18SVF_lrr_db.jpg
ADDED
![]() |
Git LFS Details
|
examples/20190804T154911_20190804T160118_T18SVF_lrr_ID1.jpg
ADDED
![]() |
Git LFS Details
|
examples/20191124T154549_20191124T154739_T18SVF_lrr_db.jpg
ADDED
![]() |
Git LFS Details
|
examples/20191128T144731_N0213_R139_T20PLS_20191128T171514_013769.jpg
ADDED
![]() |
Git LFS Details
|
examples/20191222T125301_N0213_R052_T24MXV_20191222T144240_016520.jpg
ADDED
![]() |
Git LFS Details
|
examples/20200207T113309_N0214_R080_T28PCA_20200207T132518_020527.jpg
ADDED
![]() |
Git LFS Details
|
examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_022656.jpg
ADDED
![]() |
Git LFS Details
|
examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_023215.jpg
ADDED
![]() |
Git LFS Details
|
examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_023538.jpg
ADDED
![]() |
Git LFS Details
|
examples/2021-09-17-18-22-50_L8_TORREYPINES_SDS_BENCHMARK_rgb_pan.jpg
ADDED
![]() |
Git LFS Details
|
examples/2021-10-26-23-44-09_L8_NARRABEEN_SDS_BENCHMARK_rgb_pan.jpg
ADDED
![]() |
Git LFS Details
|
greyscale_download_me.png
ADDED
![]() |
overlay_download_me.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
numpy
|
3 |
+
matplotlib
|
4 |
+
scikit-image
|
5 |
+
doodleverse_utils
|
saved_model/keras_metadata.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:85135a528821c1bd582d4ed6cbcf6cda9b055a58f70ad2fc38ed5ea28e4363b0
|
3 |
+
size 223371
|
saved_model/saved_model.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1e7714d1bc2b86a45a5453c557b420b348e171342cf2037980ffa4e42a7e8515
|
3 |
+
size 1859619
|
saved_model/variables/variables.data-00000-of-00001
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0f4fbb0f9e7dd8b763cc1f9734e523909be5df7add79a42a3aad1cddf73a3801
|
3 |
+
size 23047241
|
saved_model/variables/variables.index
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6d3fd28a3ea93e3f43de0da8610bdca2f3482a74ae1ba684498886ad609b91ad
|
3 |
+
size 10735
|