Spaces:
Runtime error
Runtime error
xinwei89
commited on
Commit
•
242850e
1
Parent(s):
45a81a5
change gradio
Browse files- app.py +4 -4
- backend.py +3 -3
app.py
CHANGED
@@ -3,11 +3,11 @@ from backend import visualize_image
|
|
3 |
|
4 |
# gradio inputs
|
5 |
image_input = gr.components.Image(type="pil", label="Input Image")
|
6 |
-
color_mode_select = gr.components.Radio(["Black/white", "Random", "Segmentation"], label="Color Mode"
|
7 |
-
mode_dropdown = gr.components.Dropdown(["Trees", "Buildings", "Both"], label="Detection Mode"
|
8 |
|
9 |
-
tree_threshold_slider = gr.components.Slider(0, 1, 0.1, 0.7, label='Set confidence threshold "%" for trees')
|
10 |
-
building_threshold_slider = gr.components.Slider(0, 1, 0.1, 0.7, label='Set confidence threshold "%" for buildings')
|
11 |
|
12 |
# gradio outputs
|
13 |
output_image = gr.components.Image(type="pil", label="Output Image")
|
|
|
3 |
|
4 |
# gradio inputs
|
5 |
image_input = gr.components.Image(type="pil", label="Input Image")
|
6 |
+
color_mode_select = gr.components.Radio(["Black/white", "Random", "Segmentation"], label="Color Mode")
|
7 |
+
mode_dropdown = gr.components.Dropdown(["Trees", "Buildings", "Both"], label="Detection Mode")
|
8 |
|
9 |
+
tree_threshold_slider = gr.components.Slider(minimum=0, maximum=1, step=0.1, default=0.7, label='Set confidence threshold "%" for trees')
|
10 |
+
building_threshold_slider = gr.components.Slider(minimum=0, maximum=1, step=0.1, default=0.7, label='Set confidence threshold "%" for buildings')
|
11 |
|
12 |
# gradio outputs
|
13 |
output_image = gr.components.Image(type="pil", label="Output Image")
|
backend.py
CHANGED
@@ -65,10 +65,10 @@ def map_color_mode(color_mode):
|
|
65 |
return ColorMode.IMAGE_BW
|
66 |
elif color_mode == "Random":
|
67 |
return ColorMode.IMAGE
|
68 |
-
elif color_mode == "Segmentation":
|
69 |
return ColorMode.SEGMENTATION
|
70 |
|
71 |
-
def visualize_image(im, mode
|
72 |
im = np.array(im)
|
73 |
color_mode = map_color_mode(color_mode)
|
74 |
|
@@ -76,7 +76,7 @@ def visualize_image(im, mode="BOTH", tree_threshold=0.7, building_threshold=0.7,
|
|
76 |
instances = segment_tree(im, tree_threshold)
|
77 |
elif mode == "Buildings":
|
78 |
instances = segment_building(im, building_threshold)
|
79 |
-
elif mode == "Both":
|
80 |
tree_instances = segment_tree(im, tree_threshold)
|
81 |
building_instances = segment_building(im, building_threshold)
|
82 |
instances = Instances.cat([tree_instances, building_instances])
|
|
|
65 |
return ColorMode.IMAGE_BW
|
66 |
elif color_mode == "Random":
|
67 |
return ColorMode.IMAGE
|
68 |
+
elif color_mode == "Segmentation" or color_mode == None:
|
69 |
return ColorMode.SEGMENTATION
|
70 |
|
71 |
+
def visualize_image(im, mode, tree_threshold:float, building_threshold:float, color_mode):
|
72 |
im = np.array(im)
|
73 |
color_mode = map_color_mode(color_mode)
|
74 |
|
|
|
76 |
instances = segment_tree(im, tree_threshold)
|
77 |
elif mode == "Buildings":
|
78 |
instances = segment_building(im, building_threshold)
|
79 |
+
elif mode == "Both" or mode == None:
|
80 |
tree_instances = segment_tree(im, tree_threshold)
|
81 |
building_instances = segment_building(im, building_threshold)
|
82 |
instances = Instances.cat([tree_instances, building_instances])
|