Spaces:
Build error
Build error
added checkbox for string labels (#12)
Browse files- added checkbox for string labels (14565b293b50b132aff7c6c680731528542bbb6d)
app.py
CHANGED
@@ -45,7 +45,8 @@ gr_dlc_model_input = gr.inputs.Dropdown(choices=['full_cat','full_dog', 'monkey_
|
|
45 |
label='Select DeepLabCut model')
|
46 |
gr_dlc_only_checkbox = gr.inputs.Checkbox(False,
|
47 |
label='Run DLClive only, directly on input image?')
|
48 |
-
|
|
|
49 |
gr_slider_conf_bboxes = gr.inputs.Slider(0,1,.05,0.8,
|
50 |
label='Set confidence threshold for animal detections')
|
51 |
gr_slider_conf_keypoints = gr.inputs.Slider(0,1,.05,0,
|
@@ -67,16 +68,17 @@ gr_mega_model_input = gr.inputs.Dropdown(choices=['md_v5a','md_v5b'],
|
|
67 |
type='value', # Type of value to be returned by component. "value" returns the string of the choice selected, "index" returns the index of the choice selected.
|
68 |
label='Select MegaDetector model')
|
69 |
inputs = [gr_image_input,
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
80 |
|
81 |
#image = gr.inputs.Image(type="pil", label="Input Image")
|
82 |
#chosen_model = gr.inputs.Dropdown(choices = models, value = "model_weights/md_v5a.0.0.pt",type = "value", label="Model Weight")
|
@@ -88,6 +90,7 @@ def draw_keypoints_on_image(image,
|
|
88 |
keypoints,
|
89 |
map_label_id_to_str,
|
90 |
use_normalized_coordinates=True,
|
|
|
91 |
gr_pose_font_input='amiko',
|
92 |
gr_slider_font_size=8,
|
93 |
gr_keypt_color="#ff0000",
|
@@ -125,11 +128,12 @@ def draw_keypoints_on_image(image,
|
|
125 |
outline=gr_keypt_color, fill=gr_keypt_color)
|
126 |
|
127 |
# add string labels around keypoints
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
133 |
|
134 |
############################################
|
135 |
# %%
|
@@ -222,6 +226,7 @@ def predict_dlc(list_np_crops,
|
|
222 |
def predict_pipeline(img_input,
|
223 |
model_input_str,
|
224 |
flag_dlc_only,
|
|
|
225 |
bbox_likelihood_th,
|
226 |
kpts_likelihood_th,
|
227 |
gr_pose_font_input=gr_pose_font_input,
|
@@ -281,6 +286,7 @@ def predict_pipeline(img_input,
|
|
281 |
list_kpts_per_crop[0], # a numpy array with shape [num_keypoints, 2].
|
282 |
map_label_id_to_str,
|
283 |
use_normalized_coordinates=False,
|
|
|
284 |
gr_pose_font_input=gr_pose_font_input,
|
285 |
gr_slider_font_size=gr_slider_font_size,
|
286 |
gr_keypt_color=gr_keypt_color,
|
@@ -306,6 +312,7 @@ def predict_pipeline(img_input,
|
|
306 |
kpts_crop, # a numpy array with shape [num_keypoints, 2].
|
307 |
map_label_id_to_str,
|
308 |
use_normalized_coordinates=False, # if True, then I should use md_results.xyxyn
|
|
|
309 |
gr_pose_font_input=gr_pose_font_input,
|
310 |
gr_slider_font_size=gr_slider_font_size,
|
311 |
gr_keypt_color=gr_keypt_color,
|
|
|
45 |
label='Select DeepLabCut model')
|
46 |
gr_dlc_only_checkbox = gr.inputs.Checkbox(False,
|
47 |
label='Run DLClive only, directly on input image?')
|
48 |
+
gr_str_labels_checkbox = gr.inputs.Checkbox(True,
|
49 |
+
label='Show bodypart labels?')
|
50 |
gr_slider_conf_bboxes = gr.inputs.Slider(0,1,.05,0.8,
|
51 |
label='Set confidence threshold for animal detections')
|
52 |
gr_slider_conf_keypoints = gr.inputs.Slider(0,1,.05,0,
|
|
|
68 |
type='value', # Type of value to be returned by component. "value" returns the string of the choice selected, "index" returns the index of the choice selected.
|
69 |
label='Select MegaDetector model')
|
70 |
inputs = [gr_image_input,
|
71 |
+
gr_dlc_model_input,
|
72 |
+
gr_dlc_only_checkbox,
|
73 |
+
gr_str_labels_checkbox,
|
74 |
+
gr_slider_conf_bboxes,
|
75 |
+
gr_slider_conf_keypoints,
|
76 |
+
gr_pose_font_input,
|
77 |
+
gr_slider_font_size,
|
78 |
+
gr_keypt_color,
|
79 |
+
gr_slider_pose_size,
|
80 |
+
gr_mega_model_input,
|
81 |
+
]
|
82 |
|
83 |
#image = gr.inputs.Image(type="pil", label="Input Image")
|
84 |
#chosen_model = gr.inputs.Dropdown(choices = models, value = "model_weights/md_v5a.0.0.pt",type = "value", label="Model Weight")
|
|
|
90 |
keypoints,
|
91 |
map_label_id_to_str,
|
92 |
use_normalized_coordinates=True,
|
93 |
+
flag_show_str_labels,
|
94 |
gr_pose_font_input='amiko',
|
95 |
gr_slider_font_size=8,
|
96 |
gr_keypt_color="#ff0000",
|
|
|
128 |
outline=gr_keypt_color, fill=gr_keypt_color)
|
129 |
|
130 |
# add string labels around keypoints
|
131 |
+
if flag_show_str_labels:
|
132 |
+
# draw.text((x, y),"Sample Text",(r,g,b))
|
133 |
+
draw.text((keypoint_x + gr_slider_pose_size, keypoint_y + gr_slider_pose_size),#(0.5*im_width, 0.5*im_height), #-------
|
134 |
+
map_label_id_to_str[i],#"Sample Text",
|
135 |
+
(gr_keypt_color), # rgb
|
136 |
+
font=font)
|
137 |
|
138 |
############################################
|
139 |
# %%
|
|
|
226 |
def predict_pipeline(img_input,
|
227 |
model_input_str,
|
228 |
flag_dlc_only,
|
229 |
+
flag_show_str_labels,
|
230 |
bbox_likelihood_th,
|
231 |
kpts_likelihood_th,
|
232 |
gr_pose_font_input=gr_pose_font_input,
|
|
|
286 |
list_kpts_per_crop[0], # a numpy array with shape [num_keypoints, 2].
|
287 |
map_label_id_to_str,
|
288 |
use_normalized_coordinates=False,
|
289 |
+
flag_show_str_labels,
|
290 |
gr_pose_font_input=gr_pose_font_input,
|
291 |
gr_slider_font_size=gr_slider_font_size,
|
292 |
gr_keypt_color=gr_keypt_color,
|
|
|
312 |
kpts_crop, # a numpy array with shape [num_keypoints, 2].
|
313 |
map_label_id_to_str,
|
314 |
use_normalized_coordinates=False, # if True, then I should use md_results.xyxyn
|
315 |
+
flag_show_str_labels,
|
316 |
gr_pose_font_input=gr_pose_font_input,
|
317 |
gr_slider_font_size=gr_slider_font_size,
|
318 |
gr_keypt_color=gr_keypt_color,
|