Spaces:
Running
Running
narugo1992
commited on
Commit
·
3648b1e
1
Parent(s):
1352f33
dev(narugo): add eyes detection
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import os
|
|
3 |
import gradio as gr
|
4 |
|
5 |
from censor import _CENSOR_MODELS, _DEFAULT_CENSOR_MODEL, _gr_detect_censors
|
|
|
6 |
from face import _FACE_MODELS, _DEFAULT_FACE_MODEL, _gr_detect_faces
|
7 |
from halfbody import _HALFBODY_MODELS, _DEFAULT_HALFBODY_MODEL, _gr_detect_halfbodies
|
8 |
from hand import _gr_detect_hands, _HAND_MODELS, _DEFAULT_HAND_MODEL
|
@@ -109,6 +110,30 @@ if __name__ == '__main__':
|
|
109 |
outputs=[gr_halfbody_output_image],
|
110 |
)
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
with gr.Tab('Hand Detection'):
|
113 |
with gr.Row():
|
114 |
with gr.Column():
|
|
|
3 |
import gradio as gr
|
4 |
|
5 |
from censor import _CENSOR_MODELS, _DEFAULT_CENSOR_MODEL, _gr_detect_censors
|
6 |
+
from eye import _EYE_MODELS, _DEFAULT_EYE_MODEL, _gr_detect_eyes
|
7 |
from face import _FACE_MODELS, _DEFAULT_FACE_MODEL, _gr_detect_faces
|
8 |
from halfbody import _HALFBODY_MODELS, _DEFAULT_HALFBODY_MODEL, _gr_detect_halfbodies
|
9 |
from hand import _gr_detect_hands, _HAND_MODELS, _DEFAULT_HAND_MODEL
|
|
|
110 |
outputs=[gr_halfbody_output_image],
|
111 |
)
|
112 |
|
113 |
+
with gr.Tab('Eyes Detection'):
|
114 |
+
with gr.Row():
|
115 |
+
with gr.Column():
|
116 |
+
gr_eye_input_image = gr.Image(type='pil', label='Original Image')
|
117 |
+
gr_eye_model = gr.Dropdown(_EYE_MODELS, value=_DEFAULT_EYE_MODEL, label='Model')
|
118 |
+
gr_eye_infer_size = gr.Slider(480, 960, value=640, step=32, label='Max Infer Size')
|
119 |
+
with gr.Row():
|
120 |
+
gr_eye_iou_threshold = gr.Slider(0.0, 1.0, 0.3, label='IOU Threshold')
|
121 |
+
gr_eye_score_threshold = gr.Slider(0.0, 1.0, 0.3, label='Score Threshold')
|
122 |
+
|
123 |
+
gr_eye_submit = gr.Button(value='Submit', variant='primary')
|
124 |
+
|
125 |
+
with gr.Column():
|
126 |
+
gr_eye_output_image = gr.Image(type='pil', label="Labeled")
|
127 |
+
|
128 |
+
gr_eye_submit.click(
|
129 |
+
_gr_detect_eyes,
|
130 |
+
inputs=[
|
131 |
+
gr_eye_input_image, gr_eye_model,
|
132 |
+
gr_eye_infer_size, gr_eye_score_threshold, gr_eye_iou_threshold,
|
133 |
+
],
|
134 |
+
outputs=[gr_eye_output_image],
|
135 |
+
)
|
136 |
+
|
137 |
with gr.Tab('Hand Detection'):
|
138 |
with gr.Row():
|
139 |
with gr.Column():
|
eye.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from functools import lru_cache
|
2 |
+
from typing import List, Tuple
|
3 |
+
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
from imgutils.data import ImageTyping, load_image, rgb_encode
|
6 |
+
|
7 |
+
from onnx_ import _open_onnx_model
|
8 |
+
from plot import detection_visualize
|
9 |
+
from yolo_ import _image_preprocess, _data_postprocess
|
10 |
+
|
11 |
+
_EYE_MODELS = [
|
12 |
+
'eye_detect_v0.4_s',
|
13 |
+
'eye_detect_v0.3_s',
|
14 |
+
'eye_detect_v0.2_s',
|
15 |
+
]
|
16 |
+
_DEFAULT_EYE_MODEL = _EYE_MODELS[0]
|
17 |
+
|
18 |
+
|
19 |
+
@lru_cache()
|
20 |
+
def _open_eye_detect_model(model_name):
|
21 |
+
return _open_onnx_model(hf_hub_download(
|
22 |
+
f'deepghs/anime_eye_detection',
|
23 |
+
f'{model_name}/model.onnx'
|
24 |
+
))
|
25 |
+
|
26 |
+
|
27 |
+
_LABELS = ['eye']
|
28 |
+
|
29 |
+
|
30 |
+
def detect_eyes(image: ImageTyping, model_name: str, max_infer_size=640,
|
31 |
+
conf_threshold: float = 0.3, iou_threshold: float = 0.3) \
|
32 |
+
-> List[Tuple[Tuple[int, int, int, int], str, float]]:
|
33 |
+
image = load_image(image, mode='RGB')
|
34 |
+
new_image, old_size, new_size = _image_preprocess(image, max_infer_size)
|
35 |
+
|
36 |
+
data = rgb_encode(new_image)[None, ...]
|
37 |
+
output, = _open_eye_detect_model(model_name).run(['output0'], {'images': data})
|
38 |
+
return _data_postprocess(output[0], conf_threshold, iou_threshold, old_size, new_size, _LABELS)
|
39 |
+
|
40 |
+
|
41 |
+
def _gr_detect_eyes(image: ImageTyping, model_name: str, max_infer_size=640,
|
42 |
+
conf_threshold: float = 0.3, iou_threshold: float = 0.3):
|
43 |
+
ret = detect_eyes(image, model_name, max_infer_size, conf_threshold, iou_threshold)
|
44 |
+
return detection_visualize(image, ret, _LABELS)
|