Update demo/UI.py
Browse files- demo/UI.py +59 -9
demo/UI.py
CHANGED
|
@@ -11,8 +11,6 @@ class Main_ui():
|
|
| 11 |
|
| 12 |
self.example_list = self.load_example()
|
| 13 |
self.sam = SAM_Inference()
|
| 14 |
-
# self.sam_predictor = get_sam_predictor()
|
| 15 |
-
# self.mask_generator = get_mask_generator()
|
| 16 |
|
| 17 |
def load_example(self):
|
| 18 |
examples = []
|
|
@@ -60,7 +58,7 @@ class Main_ui():
|
|
| 60 |
|
| 61 |
with gr.TabItem("Mask-based ROIs (BBox)"):
|
| 62 |
with gr.Row():
|
| 63 |
-
input_image_BBOX =
|
| 64 |
output_mask_BBOX = gr.Image(label='Mask-based ROI', height=512)
|
| 65 |
|
| 66 |
with gr.Row():
|
|
@@ -74,17 +72,33 @@ class Main_ui():
|
|
| 74 |
|
| 75 |
BBOX_example = gr.Dataset(label='Examples', components=[input_image_BBOX], samples=self.example_list)
|
| 76 |
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
input_image_ponit.upload(
|
| 79 |
self.seagull.init_image,
|
| 80 |
[input_image_ponit],
|
| 81 |
-
[preprocessed_img, input_image_ponit, input_image_BBOX]
|
| 82 |
)
|
| 83 |
|
| 84 |
point_example.click(
|
| 85 |
self.seagull.init_image,
|
| 86 |
[point_example],
|
| 87 |
-
[preprocessed_img, input_image_ponit, input_image_BBOX]
|
| 88 |
)
|
| 89 |
|
| 90 |
# after clicking on the image
|
|
@@ -104,17 +118,17 @@ class Main_ui():
|
|
| 104 |
[output_text_point]
|
| 105 |
)
|
| 106 |
|
| 107 |
-
# draw frame
|
| 108 |
input_image_BBOX.upload(
|
| 109 |
self.seagull.init_image,
|
| 110 |
[input_image_BBOX],
|
| 111 |
-
[preprocessed_img, input_image_ponit, input_image_BBOX]
|
| 112 |
)
|
| 113 |
|
| 114 |
BBOX_example.click(
|
| 115 |
self.seagull.init_image,
|
| 116 |
[BBOX_example],
|
| 117 |
-
[preprocessed_img, input_image_ponit, input_image_BBOX]
|
| 118 |
)
|
| 119 |
|
| 120 |
# after drawing a frame on the image
|
|
@@ -139,5 +153,41 @@ class Main_ui():
|
|
| 139 |
[preprocessed_img, binary_mask, radio_BBOX],
|
| 140 |
[output_text_BBOX]
|
| 141 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
return demo
|
|
|
|
| 11 |
|
| 12 |
self.example_list = self.load_example()
|
| 13 |
self.sam = SAM_Inference()
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def load_example(self):
|
| 16 |
examples = []
|
|
|
|
| 58 |
|
| 59 |
with gr.TabItem("Mask-based ROIs (BBox)"):
|
| 60 |
with gr.Row():
|
| 61 |
+
input_image_BBOX = gr.Image(tool='boxes', type="numpy", label='Input image', height=512)
|
| 62 |
output_mask_BBOX = gr.Image(label='Mask-based ROI', height=512)
|
| 63 |
|
| 64 |
with gr.Row():
|
|
|
|
| 72 |
|
| 73 |
BBOX_example = gr.Dataset(label='Examples', components=[input_image_BBOX], samples=self.example_list)
|
| 74 |
|
| 75 |
+
with gr.TabItem("Mask-based ROIs (BBox with Points)"):
|
| 76 |
+
with gr.Row():
|
| 77 |
+
input_image_BBOX_Points = gr.Image(tool='boxes', type="numpy", label='Input image', height=512)
|
| 78 |
+
output_mask_BBOX_Points = gr.Image(label='Mask-based ROI', height=512)
|
| 79 |
+
|
| 80 |
+
with gr.Row():
|
| 81 |
+
output_BBOX_Points_mask_on_img = gr.Image(label='Mask on image', height=512)
|
| 82 |
+
|
| 83 |
+
with gr.Column():
|
| 84 |
+
radio_BBOX_Points = gr.Radio(label='Analysis type', choices=['Quality Score', 'Importance Score', 'Distortion Analysis'], value='Quality Score')
|
| 85 |
+
output_text_BBOX_Points = gr.Textbox(label='ROI Quality Analysis')
|
| 86 |
+
box_seg_button_with_point = gr.Button('Generate mask and analysis')
|
| 87 |
+
box_analyse_button_with_point = gr.Button('Analysis')
|
| 88 |
+
|
| 89 |
+
BBOX_Points_example = gr.Dataset(label='Examples', components=[input_image_BBOX_Points], samples=self.example_list)
|
| 90 |
+
|
| 91 |
+
# 1. click point
|
| 92 |
input_image_ponit.upload(
|
| 93 |
self.seagull.init_image,
|
| 94 |
[input_image_ponit],
|
| 95 |
+
[preprocessed_img, input_image_ponit, input_image_BBOX, input_image_BBOX_Points]
|
| 96 |
)
|
| 97 |
|
| 98 |
point_example.click(
|
| 99 |
self.seagull.init_image,
|
| 100 |
[point_example],
|
| 101 |
+
[preprocessed_img, input_image_ponit, input_image_BBOX, input_image_BBOX_Points]
|
| 102 |
)
|
| 103 |
|
| 104 |
# after clicking on the image
|
|
|
|
| 118 |
[output_text_point]
|
| 119 |
)
|
| 120 |
|
| 121 |
+
# 2. draw frame and use SAM to indicate the rois
|
| 122 |
input_image_BBOX.upload(
|
| 123 |
self.seagull.init_image,
|
| 124 |
[input_image_BBOX],
|
| 125 |
+
[preprocessed_img, input_image_ponit, input_image_BBOX, input_image_BBOX_Points]
|
| 126 |
)
|
| 127 |
|
| 128 |
BBOX_example.click(
|
| 129 |
self.seagull.init_image,
|
| 130 |
[BBOX_example],
|
| 131 |
+
[preprocessed_img, input_image_ponit, input_image_BBOX, input_image_BBOX_Points]
|
| 132 |
)
|
| 133 |
|
| 134 |
# after drawing a frame on the image
|
|
|
|
| 153 |
[preprocessed_img, binary_mask, radio_BBOX],
|
| 154 |
[output_text_BBOX]
|
| 155 |
)
|
| 156 |
+
|
| 157 |
+
# 3. draw frame and use the points
|
| 158 |
+
input_image_BBOX.upload(
|
| 159 |
+
self.seagull.init_image,
|
| 160 |
+
[input_image_BBOX],
|
| 161 |
+
[preprocessed_img, input_image_ponit, input_image_BBOX, input_image_BBOX_Points]
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
BBOX_Points_example.click(
|
| 165 |
+
self.seagull.init_image,
|
| 166 |
+
[BBOX_Points_example],
|
| 167 |
+
[preprocessed_img, input_image_ponit, input_image_BBOX, input_image_BBOX_Points]
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
# after drawing a frame on the image
|
| 171 |
+
input_image_BBOX_Points.select(
|
| 172 |
+
self.sam.gen_box_point,
|
| 173 |
+
[input_image_BBOX_Points],
|
| 174 |
+
[output_mask_BBOX_Points, output_BBOX_Points_mask_on_img, binary_mask]
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
box_seg_button_with_point.click(
|
| 178 |
+
self.sam.gen_box_point,
|
| 179 |
+
[input_image_BBOX_Points],
|
| 180 |
+
[output_mask_BBOX_Points, output_BBOX_Points_mask_on_img, binary_mask]
|
| 181 |
+
).then(
|
| 182 |
+
self.seagull.seagull_predict,
|
| 183 |
+
[preprocessed_img, binary_mask, radio_BBOX_Points],
|
| 184 |
+
[output_text_BBOX_Points]
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
box_analyse_button_with_point.click(
|
| 188 |
+
self.seagull.seagull_predict,
|
| 189 |
+
[preprocessed_img, binary_mask, radio_BBOX_Points],
|
| 190 |
+
[output_text_BBOX_Points]
|
| 191 |
+
)
|
| 192 |
|
| 193 |
return demo
|