Spaces:
Runtime error
Runtime error
Guillermo Uribe Vicencio
commited on
Commit
·
e6bf424
1
Parent(s):
fffc2dc
app.py
CHANGED
|
@@ -57,7 +57,7 @@ cdl_color_map = [{'value': 1, 'label': 'Natural vegetation', 'rgb': (233,255,190
|
|
| 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):
|
| 61 |
|
| 62 |
rgb_mapped = rgb.copy()
|
| 63 |
|
|
@@ -68,8 +68,8 @@ def apply_color_map(rgb, color_map=cdl_color_map):
|
|
| 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 |
-
|
| 72 |
-
map_resume.append({"label": map_tmp['label'],'qtt': sum(
|
| 73 |
|
| 74 |
return rgb_mapped
|
| 75 |
|
|
@@ -180,7 +180,7 @@ def process_rgb(input, mask, indexes):
|
|
| 180 |
|
| 181 |
return rgb
|
| 182 |
|
| 183 |
-
def inference_on_file(target_image, model, custom_test_pipeline):
|
| 184 |
|
| 185 |
target_image = target_image.name
|
| 186 |
time_taken=-1
|
|
@@ -214,7 +214,7 @@ def inference_on_file(target_image, model, custom_test_pipeline):
|
|
| 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))
|
| 218 |
|
| 219 |
return rgb1,rgb2,rgb3,output
|
| 220 |
|
|
@@ -245,7 +245,7 @@ model = init_segmentor(config, ckpt, device='cpu')
|
|
| 245 |
custom_test_pipeline=process_test_pipeline(model.cfg.data.test.pipeline, None)
|
| 246 |
|
| 247 |
|
| 248 |
-
func = partial(inference_on_file, model=model, custom_test_pipeline=custom_test_pipeline)
|
| 249 |
print("")
|
| 250 |
bar_data = pd.DataFrame(map_resume)
|
| 251 |
|
|
@@ -271,16 +271,15 @@ with gr.Blocks() as demo:
|
|
| 271 |
inp3=gr.Image(image_mode='RGB', scale=10, label='T3')
|
| 272 |
|
| 273 |
with gr.Row():
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
y='qtt')
|
| 284 |
with gr.Column():
|
| 285 |
out = gr.Image(image_mode='RGB', scale=10, label='Model prediction')
|
| 286 |
# gr.Image(value='Legend.png', image_mode='RGB', scale=2, show_label=False)
|
|
|
|
| 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=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 |
|
|
|
|
| 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
|
|
|
|
| 214 |
output = np.vstack([output[None], output[None], output[None]]).astype(np.uint8)
|
| 215 |
|
| 216 |
|
| 217 |
+
output=apply_color_map(output,map_resume).transpose((1,2,0))
|
| 218 |
|
| 219 |
return rgb1,rgb2,rgb3,output
|
| 220 |
|
|
|
|
| 245 |
custom_test_pipeline=process_test_pipeline(model.cfg.data.test.pipeline, None)
|
| 246 |
|
| 247 |
|
| 248 |
+
func = partial(inference_on_file, model=model, custom_test_pipeline=custom_test_pipeline, map_resume=map_resume)
|
| 249 |
print("")
|
| 250 |
bar_data = pd.DataFrame(map_resume)
|
| 251 |
|
|
|
|
| 271 |
inp3=gr.Image(image_mode='RGB', scale=10, label='T3')
|
| 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)
|