dbuscombe commited on
Commit
e62aad4
1 Parent(s): ab9b897
.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

  • SHA256: f20898237bc0f524e62cf16c831595e3defe1db5732130d042394ac2acdbab87
  • Pointer size: 129 Bytes
  • Size of remote file: 2.96 kB
examples/2017-09-02-18-46-11_RGB_L8.jpg ADDED

Git LFS Details

  • SHA256: 43c1011f64c73eb73e9bfc27335173ec8f4ddd98320e13a5c1ace23b3c6d2fe8
  • Pointer size: 130 Bytes
  • Size of remote file: 49.9 kB
examples/2019-03-05-10-47-51_L8_TRUCVERT_SDS_BENCHMARK_rgb_pan.jpg ADDED

Git LFS Details

  • SHA256: 22353865a29e1fcf388e8ecefab74c81d32c5638e11f4f0da4d1db08939213da
  • Pointer size: 129 Bytes
  • Size of remote file: 6.28 kB
examples/20190715T154911_N0213_R054_T18TWL_20190715T200600_010646.jpg ADDED

Git LFS Details

  • SHA256: 8e832ea7da572ac916f324b2bbe7d6c237083c975c666c7105bc4059b1d2b808
  • Pointer size: 129 Bytes
  • Size of remote file: 5.67 kB
examples/20190730T154819_20190730T155818_T18SVF_lrr_db.jpg ADDED

Git LFS Details

  • SHA256: 7949b1ab22d080a615a9d38cb29fb50d3f4c3406b5aa0058f1fda6b1c8b44628
  • Pointer size: 130 Bytes
  • Size of remote file: 57.2 kB
examples/20190804T154911_20190804T160118_T18SVF_lrr_ID1.jpg ADDED

Git LFS Details

  • SHA256: 9c140d3d29759bd47e5e4357bb81ce58d5daea5420ad02d8a41bace8041ecf11
  • Pointer size: 130 Bytes
  • Size of remote file: 88.4 kB
examples/20191124T154549_20191124T154739_T18SVF_lrr_db.jpg ADDED

Git LFS Details

  • SHA256: 6a32bc82f32e221a95613b9ef354a7071f3aaaf9bfd2f530098d964f7e7778c4
  • Pointer size: 130 Bytes
  • Size of remote file: 38.7 kB
examples/20191128T144731_N0213_R139_T20PLS_20191128T171514_013769.jpg ADDED

Git LFS Details

  • SHA256: ee702a073076aa488e9c3d9df8689c473cb3204bc3ea00f246e958119f2c5b73
  • Pointer size: 130 Bytes
  • Size of remote file: 12.1 kB
examples/20191222T125301_N0213_R052_T24MXV_20191222T144240_016520.jpg ADDED

Git LFS Details

  • SHA256: 4732063efda1ef472786cb6f0e11dd1b732327ace69089ae7869e0533be26a96
  • Pointer size: 129 Bytes
  • Size of remote file: 9.21 kB
examples/20200207T113309_N0214_R080_T28PCA_20200207T132518_020527.jpg ADDED

Git LFS Details

  • SHA256: bc8e1d913d187596f9daa7cae9104ec0fb66c5cc91544728944c97546a3458ae
  • Pointer size: 130 Bytes
  • Size of remote file: 12.2 kB
examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_022656.jpg ADDED

Git LFS Details

  • SHA256: 9ca7d8748c7cdb1bb4afcdb01829b78b737cb907cf6baad908488f5efc351edf
  • Pointer size: 129 Bytes
  • Size of remote file: 5.63 kB
examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_023215.jpg ADDED

Git LFS Details

  • SHA256: 915b60f0e5a9395a0a51526eb100682a287c21b9d0b20dd9f6a1316e7c96ee63
  • Pointer size: 129 Bytes
  • Size of remote file: 8.36 kB
examples/20200207T163439_N0214_R083_T16RBU_20200207T201114_023538.jpg ADDED

Git LFS Details

  • SHA256: 88813c1408984ccdc750143a9a42cdc454e00e2eed2e43353f9f005f6a7e3a9b
  • Pointer size: 129 Bytes
  • Size of remote file: 7.14 kB
examples/2021-09-17-18-22-50_L8_TORREYPINES_SDS_BENCHMARK_rgb_pan.jpg ADDED

Git LFS Details

  • SHA256: 98ea025d076aa9abd7dce32f9308b66ce1e2f39614aef2bfbd48d04fb151c505
  • Pointer size: 130 Bytes
  • Size of remote file: 13.7 kB
examples/2021-10-26-23-44-09_L8_NARRABEEN_SDS_BENCHMARK_rgb_pan.jpg ADDED

Git LFS Details

  • SHA256: d6951f770654ea6d5dd662a29e8046d75320248bcca70c3700c9d59a3033ca64
  • Pointer size: 129 Bytes
  • Size of remote file: 5.17 kB
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