Spaces:
Runtime error
Runtime error
Irina Tolstykh
commited on
Commit
·
e752590
1
Parent(s):
e31c3c9
v2 version
Browse files- app.py +57 -14
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -44,14 +44,21 @@ def load_models():
|
|
| 44 |
'yolov8x_person_face.pt',
|
| 45 |
use_auth_token=HF_TOKEN)
|
| 46 |
|
| 47 |
-
|
| 48 |
'checkpoint-377.pth.tar',
|
| 49 |
use_auth_token=HF_TOKEN)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
def detect(
|
|
@@ -88,18 +95,42 @@ def clear():
|
|
| 88 |
return None, 0.4, 0.7, "Use persons and faces", None
|
| 89 |
|
| 90 |
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
|
| 93 |
image_dir = pathlib.Path('images')
|
| 94 |
examples = [[path.as_posix(), 0.4, 0.7, "Use persons and faces"] for path in sorted(image_dir.glob('*.jpg'))]
|
| 95 |
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
with gr.
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
with gr.Row():
|
| 104 |
with gr.Column():
|
| 105 |
image = gr.Image(label='Input', type='numpy')
|
|
@@ -121,9 +152,21 @@ with gr.Blocks(
|
|
| 121 |
gr.Examples(examples=examples,
|
| 122 |
inputs=inputs,
|
| 123 |
outputs=result,
|
| 124 |
-
fn=
|
| 125 |
cache_examples=False)
|
| 126 |
-
run_button.click(fn=
|
| 127 |
clear_button.click(fn=clear, inputs=None, outputs=[image, score_threshold, iou_threshold, mode, result])
|
| 128 |
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
'yolov8x_person_face.pt',
|
| 45 |
use_auth_token=HF_TOKEN)
|
| 46 |
|
| 47 |
+
age_gender_path_v1 = huggingface_hub.hf_hub_download('iitolstykh/demo_xnet_volo_cross',
|
| 48 |
'checkpoint-377.pth.tar',
|
| 49 |
use_auth_token=HF_TOKEN)
|
| 50 |
|
| 51 |
+
age_gender_path_v2 = huggingface_hub.hf_hub_download('iitolstykh/demo_xnet_volo_cross',
|
| 52 |
+
'mivolo_v2_1.tar',
|
| 53 |
+
use_auth_token=HF_TOKEN)
|
| 54 |
|
| 55 |
+
predictor_cfg_v1 = Cfg(detector_path, age_gender_path_v1)
|
| 56 |
+
predictor_cfg_v2 = Cfg(detector_path, age_gender_path_v2)
|
| 57 |
+
|
| 58 |
+
predictor_v1 = Predictor(predictor_cfg_v1)
|
| 59 |
+
predictor_v2 = Predictor(predictor_cfg_v2)
|
| 60 |
+
|
| 61 |
+
return predictor_v1, predictor_v2
|
| 62 |
|
| 63 |
|
| 64 |
def detect(
|
|
|
|
| 95 |
return None, 0.4, 0.7, "Use persons and faces", None
|
| 96 |
|
| 97 |
|
| 98 |
+
predictor_v1, predictor_v2 = load_models()
|
| 99 |
+
prediction_func_v1 = functools.partial(detect, predictor=predictor_v1)
|
| 100 |
+
prediction_func_v2 = functools.partial(detect, predictor=predictor_v2)
|
| 101 |
|
| 102 |
image_dir = pathlib.Path('images')
|
| 103 |
examples = [[path.as_posix(), 0.4, 0.7, "Use persons and faces"] for path in sorted(image_dir.glob('*.jpg'))]
|
| 104 |
|
| 105 |
+
with gr.Blocks(theme=gr.themes.Default(), css="style.css") as demo_v1:
|
| 106 |
+
with gr.Row():
|
| 107 |
+
with gr.Column():
|
| 108 |
+
image = gr.Image(label='Input', type='numpy')
|
| 109 |
+
score_threshold = gr.Slider(0, 1, value=0.4, step=0.05, label='Detector Score Threshold')
|
| 110 |
+
iou_threshold = gr.Slider(0, 1, value=0.7, step=0.05, label='NMS Iou Threshold')
|
| 111 |
+
mode = gr.Radio(["Use persons and faces", "Use persons only", "Use faces only"],
|
| 112 |
+
value="Use persons and faces",
|
| 113 |
+
label="Inference mode",
|
| 114 |
+
info="What to use for gender and age recognition")
|
| 115 |
|
| 116 |
+
with gr.Row():
|
| 117 |
+
clear_button = gr.Button("Clear")
|
| 118 |
+
with gr.Column():
|
| 119 |
+
run_button = gr.Button("Submit", variant="primary")
|
| 120 |
+
with gr.Column():
|
| 121 |
+
result = gr.Image(label='Output', type='numpy')
|
| 122 |
+
|
| 123 |
+
inputs = [image, score_threshold, iou_threshold, mode]
|
| 124 |
+
gr.Examples(examples=examples,
|
| 125 |
+
inputs=inputs,
|
| 126 |
+
outputs=result,
|
| 127 |
+
fn=prediction_func_v1,
|
| 128 |
+
cache_examples=False)
|
| 129 |
+
run_button.click(fn=prediction_func_v1, inputs=inputs, outputs=result, api_name='predict')
|
| 130 |
+
clear_button.click(fn=clear, inputs=None, outputs=[image, score_threshold, iou_threshold, mode, result])
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
with gr.Blocks(theme=gr.themes.Default(), css="style.css") as demo_v2:
|
| 134 |
with gr.Row():
|
| 135 |
with gr.Column():
|
| 136 |
image = gr.Image(label='Input', type='numpy')
|
|
|
|
| 152 |
gr.Examples(examples=examples,
|
| 153 |
inputs=inputs,
|
| 154 |
outputs=result,
|
| 155 |
+
fn=prediction_func_v2,
|
| 156 |
cache_examples=False)
|
| 157 |
+
run_button.click(fn=prediction_func_v2, inputs=inputs, outputs=result, api_name='predict')
|
| 158 |
clear_button.click(fn=clear, inputs=None, outputs=[image, score_threshold, iou_threshold, mode, result])
|
| 159 |
|
| 160 |
+
|
| 161 |
+
with gr.Blocks(theme=gr.themes.Default(), css="style.css") as demo:
|
| 162 |
+
gr.Markdown(DESCRIPTION)
|
| 163 |
+
|
| 164 |
+
with gr.Tabs():
|
| 165 |
+
with gr.Tab(label="MiVOLO_V1"):
|
| 166 |
+
demo_v1.render()
|
| 167 |
+
with gr.Tab(label="MiVOLO_V2"):
|
| 168 |
+
demo_v2.render()
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
if __name__ == "__main__":
|
| 172 |
+
demo.queue(max_size=15).launch()
|
requirements.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
Cython==0.29.28
|
| 2 |
-
ultralytics
|
| 3 |
timm==0.8.13.dev0
|
| 4 |
huggingface_hub
|
| 5 |
gradio
|
|
|
|
| 1 |
Cython==0.29.28
|
| 2 |
+
ultralytics==8.0.124
|
| 3 |
timm==0.8.13.dev0
|
| 4 |
huggingface_hub
|
| 5 |
gradio
|