Spaces:
Sleeping
Sleeping
Guillermo Uribe Vicencio
commited on
Commit
·
b1244a8
1
Parent(s):
faecb58
app.py
CHANGED
@@ -43,22 +43,21 @@ from skimage import exposure
|
|
43 |
import pandas as pd
|
44 |
|
45 |
|
46 |
-
cdl_color_map = [{'value': 1, 'label': 'Natural vegetation', 'rgb': (233,255,190)},
|
47 |
-
{'value': 2, 'label': 'Forest', 'rgb': (149,206,147)},
|
48 |
-
{'value': 3, 'label': 'Corn', 'rgb': (255,212,0)},
|
49 |
-
{'value': 4, 'label': 'Soybeans', 'rgb': (38,115,0)},
|
50 |
-
{'value': 5, 'label': 'Wetlands', 'rgb': (128,179,179)},
|
51 |
-
{'value': 6, 'label': 'Developed/Barren', 'rgb': (156,156,156)},
|
52 |
-
{'value': 7, 'label': 'Open Water', 'rgb': (77,112,163)},
|
53 |
-
{'value': 8, 'label': 'Winter Wheat', 'rgb': (168,112,0)},
|
54 |
-
{'value': 9, 'label': 'Alfalfa', 'rgb': (255,168,227)},
|
55 |
-
{'value': 10, 'label': 'Fallow/Idle cropland', 'rgb': (191,191,122)},
|
56 |
-
{'value': 11, 'label': 'Cotton', 'rgb':(255,38,38)},
|
57 |
-
{'value': 12, 'label': 'Sorghum', 'rgb':(255,158,15)},
|
58 |
-
{'value': 13, 'label': 'Other', 'rgb':(0,175,77)}]
|
59 |
-
|
60 |
-
|
61 |
-
def apply_color_map(rgb, color_map=cdl_color_map):
|
62 |
|
63 |
rgb_mapped = rgb.copy()
|
64 |
|
@@ -69,7 +68,9 @@ def apply_color_map(rgb, color_map=cdl_color_map):
|
|
69 |
cont = np.where((rgb[0] == map_tmp['value']) & (rgb[1] == map_tmp['value']) & (rgb[2] == map_tmp['value']), 1, 0)
|
70 |
|
71 |
print(map_tmp['label'])
|
72 |
-
print(cont)
|
|
|
|
|
73 |
return rgb_mapped
|
74 |
|
75 |
|
@@ -179,7 +180,7 @@ def process_rgb(input, mask, indexes):
|
|
179 |
|
180 |
return rgb
|
181 |
|
182 |
-
def inference_on_file(target_image, model, custom_test_pipeline):
|
183 |
|
184 |
target_image = target_image.name
|
185 |
time_taken=-1
|
@@ -212,8 +213,8 @@ def inference_on_file(target_image, model, custom_test_pipeline):
|
|
212 |
output=result[0][0] + 1
|
213 |
output = np.vstack([output[None], output[None], output[None]]).astype(np.uint8)
|
214 |
|
215 |
-
|
216 |
-
output=apply_color_map(output).transpose((1,2,0))
|
217 |
|
218 |
return rgb1,rgb2,rgb3,output
|
219 |
|
@@ -243,16 +244,10 @@ config.model.backbone.pretrained=None
|
|
243 |
model = init_segmentor(config, ckpt, device='cpu')
|
244 |
custom_test_pipeline=process_test_pipeline(model.cfg.data.test.pipeline, None)
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
|
250 |
-
|
251 |
-
{
|
252 |
-
"a": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
|
253 |
-
"b": [28, 55, 43, 91, 81, 53, 19, 87, 52],
|
254 |
-
}
|
255 |
-
)
|
256 |
|
257 |
with gr.Blocks() as demo:
|
258 |
with gr.Row():
|
@@ -277,15 +272,14 @@ with gr.Blocks() as demo:
|
|
277 |
|
278 |
with gr.Row():
|
279 |
with gr.Column():
|
280 |
-
gr.BarPlot(
|
281 |
-
x="
|
282 |
-
y="
|
283 |
title="Simple Bar Plot with made up data",
|
284 |
-
tooltip=["
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
y='b')
|
289 |
with gr.Column():
|
290 |
out = gr.Image(image_mode='RGB', scale=10, label='Model prediction')
|
291 |
# gr.Image(value='Legend.png', image_mode='RGB', scale=2, show_label=False)
|
|
|
43 |
import pandas as pd
|
44 |
|
45 |
|
46 |
+
cdl_color_map = [{'value': 1, 'label': 'Natural vegetation', 'rgb': (233,255,190), 'qtt': 0},
|
47 |
+
{'value': 2, 'label': 'Forest', 'rgb': (149,206,147), 'qtt': 0},
|
48 |
+
{'value': 3, 'label': 'Corn', 'rgb': (255,212,0), 'qtt': 0},
|
49 |
+
{'value': 4, 'label': 'Soybeans', 'rgb': (38,115,0), 'qtt': 0},
|
50 |
+
{'value': 5, 'label': 'Wetlands', 'rgb': (128,179,179), 'qtt': 0},
|
51 |
+
{'value': 6, 'label': 'Developed/Barren', 'rgb': (156,156,156), 'qtt': 0},
|
52 |
+
{'value': 7, 'label': 'Open Water', 'rgb': (77,112,163), 'qtt': 0},
|
53 |
+
{'value': 8, 'label': 'Winter Wheat', 'rgb': (168,112,0), 'qtt': 0},
|
54 |
+
{'value': 9, 'label': 'Alfalfa', 'rgb': (255,168,227), 'qtt': 0},
|
55 |
+
{'value': 10, 'label': 'Fallow/Idle cropland', 'rgb': (191,191,122), 'qtt': 0},
|
56 |
+
{'value': 11, 'label': 'Cotton', 'rgb':(255,38,38), 'qtt': 0},
|
57 |
+
{'value': 12, 'label': 'Sorghum', 'rgb':(255,158,15), 'qtt': 0},
|
58 |
+
{'value': 13, 'label': 'Other', 'rgb':(0,175,77), 'qtt': 0}]
|
59 |
+
|
60 |
+
def apply_color_map(rgb, color_map=cdl_color_map, map_resume):
|
|
|
61 |
|
62 |
rgb_mapped = rgb.copy()
|
63 |
|
|
|
68 |
cont = np.where((rgb[0] == map_tmp['value']) & (rgb[1] == map_tmp['value']) & (rgb[2] == map_tmp['value']), 1, 0)
|
69 |
|
70 |
print(map_tmp['label'])
|
71 |
+
print("Cantidad total ", sum(cont))
|
72 |
+
map_resume.append({"label": map_tmp['label'],'qtt': sum(cont)})
|
73 |
+
|
74 |
return rgb_mapped
|
75 |
|
76 |
|
|
|
180 |
|
181 |
return rgb
|
182 |
|
183 |
+
def inference_on_file(target_image, model, custom_test_pipeline, map_resume):
|
184 |
|
185 |
target_image = target_image.name
|
186 |
time_taken=-1
|
|
|
213 |
output=result[0][0] + 1
|
214 |
output = np.vstack([output[None], output[None], output[None]]).astype(np.uint8)
|
215 |
|
216 |
+
|
217 |
+
output=apply_color_map(output).transpose((1,2,0),map_resume)
|
218 |
|
219 |
return rgb1,rgb2,rgb3,output
|
220 |
|
|
|
244 |
model = init_segmentor(config, ckpt, device='cpu')
|
245 |
custom_test_pipeline=process_test_pipeline(model.cfg.data.test.pipeline, None)
|
246 |
|
247 |
+
map_resume = []
|
248 |
+
func = partial(inference_on_file, model=model, custom_test_pipeline=custom_test_pipeline, map_resume=map_resume)
|
|
|
249 |
|
250 |
+
bar_data = pd.DataFrame(map_resume)
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
with gr.Blocks() as demo:
|
253 |
with gr.Row():
|
|
|
272 |
|
273 |
with gr.Row():
|
274 |
with gr.Column():
|
275 |
+
gr.BarPlot(bar_data,
|
276 |
+
x="label",
|
277 |
+
y="qtt",
|
278 |
title="Simple Bar Plot with made up data",
|
279 |
+
tooltip=["label", "Qtt"])
|
280 |
+
gr.LinePlot(bar_data,
|
281 |
+
x='label',
|
282 |
+
y='qtt')
|
|
|
283 |
with gr.Column():
|
284 |
out = gr.Image(image_mode='RGB', scale=10, label='Model prediction')
|
285 |
# gr.Image(value='Legend.png', image_mode='RGB', scale=2, show_label=False)
|