Update ui_utils.py
#8
by C-Achard - opened
- ui_utils.py +113 -61
ui_utils.py
CHANGED
|
@@ -1,74 +1,126 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
##############################
|
| 4 |
-
def gradio_inputs_for_MD_DLC(md_models_list, # list(MD_models_dict.keys())
|
| 5 |
-
dlc_models_list, # list(DLC_models_dict.keys())
|
| 6 |
-
):
|
| 7 |
-
# Input image
|
| 8 |
-
gr_image_input = gr.inputs.Image(type="pil", label="Input Image")
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Models
|
| 12 |
-
gr_mega_model_input = gr.
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
# Other inputs
|
| 22 |
-
gr_dlc_only_checkbox = gr.
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def gradio_outputs_for_MD_DLC():
|
| 59 |
-
|
| 60 |
-
gr_image_output = gr.outputs.Image(type="pil", label="Output Image")
|
| 61 |
gr_file_download = gr.File(label="Download JSON file")
|
| 62 |
-
return [gr_image_output,
|
| 63 |
-
|
| 64 |
|
| 65 |
-
##############################################
|
| 66 |
-
# User interace: description
|
| 67 |
def gradio_description_and_examples():
|
| 68 |
title = "DeepLabCut Model Zoo SuperAnimals"
|
| 69 |
-
description =
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
examples = [[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
return [title,description,examples]
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
def gradio_inputs_for_MD_DLC(md_models_list, dlc_models_list):
|
| 5 |
+
# Input image
|
| 6 |
+
gr_image_input = gr.Image(type="pil", label="Input Image")
|
| 7 |
|
| 8 |
# Models
|
| 9 |
+
gr_mega_model_input = gr.Dropdown(
|
| 10 |
+
choices=md_models_list,
|
| 11 |
+
value="md_v5a",
|
| 12 |
+
type="value",
|
| 13 |
+
label="Select Detector model",
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
gr_dlc_model_input = gr.Dropdown(
|
| 17 |
+
choices=dlc_models_list,
|
| 18 |
+
value="superanimal_quadruped_dlcrnet",
|
| 19 |
+
type="value",
|
| 20 |
+
label="Select DeepLabCut model",
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
# Other inputs
|
| 24 |
+
gr_dlc_only_checkbox = gr.Checkbox(
|
| 25 |
+
value=False,
|
| 26 |
+
label="Run DLClive only, directly on input image?",
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
gr_str_labels_checkbox = gr.Checkbox(
|
| 30 |
+
value=True,
|
| 31 |
+
label="Show bodypart labels?",
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
# Gradio Slider signature is (minimum, maximum, value, step, ...)
|
| 35 |
+
gr_slider_conf_bboxes = gr.Slider(
|
| 36 |
+
minimum=0,
|
| 37 |
+
maximum=1,
|
| 38 |
+
value=0.2,
|
| 39 |
+
step=0.05,
|
| 40 |
+
label="Set confidence threshold for animal detections",
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
gr_slider_conf_keypoints = gr.Slider(
|
| 44 |
+
minimum=0,
|
| 45 |
+
maximum=1,
|
| 46 |
+
value=0.4,
|
| 47 |
+
step=0.05,
|
| 48 |
+
label="Set confidence threshold for keypoints",
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Data viz
|
| 52 |
+
gr_keypt_color = gr.ColorPicker(
|
| 53 |
+
value="#862db7",
|
| 54 |
+
label="Choose color for keypoint label",
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
gr_labels_font_style = gr.Dropdown(
|
| 58 |
+
choices=["amiko", "animals", "nature", "painter", "zen"],
|
| 59 |
+
value="amiko",
|
| 60 |
+
type="value",
|
| 61 |
+
label="Select keypoint label font",
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
gr_slider_font_size = gr.Slider(
|
| 65 |
+
minimum=5,
|
| 66 |
+
maximum=30,
|
| 67 |
+
value=8,
|
| 68 |
+
step=1,
|
| 69 |
+
label="Set font size",
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
gr_slider_marker_size = gr.Slider(
|
| 73 |
+
minimum=1,
|
| 74 |
+
maximum=20,
|
| 75 |
+
value=9,
|
| 76 |
+
step=1,
|
| 77 |
+
label="Set marker size",
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
return [
|
| 81 |
+
gr_image_input,
|
| 82 |
+
gr_mega_model_input,
|
| 83 |
+
gr_dlc_model_input,
|
| 84 |
+
gr_dlc_only_checkbox,
|
| 85 |
+
gr_str_labels_checkbox,
|
| 86 |
+
gr_slider_conf_bboxes,
|
| 87 |
+
gr_slider_conf_keypoints,
|
| 88 |
+
gr_labels_font_style,
|
| 89 |
+
gr_slider_font_size,
|
| 90 |
+
gr_keypt_color,
|
| 91 |
+
gr_slider_marker_size,
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
|
| 95 |
def gradio_outputs_for_MD_DLC():
|
| 96 |
+
gr_image_output = gr.Image(type="pil", label="Output Image")
|
|
|
|
| 97 |
gr_file_download = gr.File(label="Download JSON file")
|
| 98 |
+
return [gr_image_output, gr_file_download]
|
| 99 |
+
|
| 100 |
|
|
|
|
|
|
|
| 101 |
def gradio_description_and_examples():
|
| 102 |
title = "DeepLabCut Model Zoo SuperAnimals"
|
| 103 |
+
description = (
|
| 104 |
+
"Test the SuperAnimal models from the "
|
| 105 |
+
"<a href='http://www.mackenziemathislab.org/dlc-modelzoo'>"
|
| 106 |
+
"DeepLabCut ModelZoo Project</a>, and read more on arXiv: "
|
| 107 |
+
"https://arxiv.org/abs/2203.07436! Simply upload an image and see how it does. "
|
| 108 |
+
"Want to run on videos on the cloud or locally? See the "
|
| 109 |
+
"<a href='http://www.mackenziemathislab.org/dlc-modelzoo'>DeepLabCut ModelZoo</a>."
|
| 110 |
+
)
|
| 111 |
|
| 112 |
+
examples = [[
|
| 113 |
+
"examples/dog.jpeg",
|
| 114 |
+
"md_v5a",
|
| 115 |
+
"superanimal_quadruped_dlcrnet",
|
| 116 |
+
False,
|
| 117 |
+
True,
|
| 118 |
+
0.5,
|
| 119 |
+
0.0,
|
| 120 |
+
"amiko",
|
| 121 |
+
9,
|
| 122 |
+
"#ff0000",
|
| 123 |
+
3,
|
| 124 |
+
]]
|
| 125 |
|
| 126 |
+
return [title, description, examples]
|