Spaces:
Running
Running
dev(narugo): 2 more
Browse files- app2.py +5 -1
- detection/__init__.py +3 -1
- detection/face.py +33 -0
- detection/head.py +47 -0
app2.py
CHANGED
@@ -2,7 +2,7 @@ import os
|
|
2 |
|
3 |
import gradio as gr
|
4 |
|
5 |
-
from detection import EyesDetection
|
6 |
|
7 |
_GLOBAL_CSS = """
|
8 |
.limit-height {
|
@@ -13,6 +13,10 @@ _GLOBAL_CSS = """
|
|
13 |
if __name__ == '__main__':
|
14 |
with gr.Blocks(css=_GLOBAL_CSS) as demo:
|
15 |
with gr.Tabs():
|
|
|
|
|
|
|
|
|
16 |
with gr.Tab('Eyes Detection'):
|
17 |
EyesDetection().make_ui()
|
18 |
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
|
5 |
+
from detection import EyesDetection, FaceDetection, HeadDetection
|
6 |
|
7 |
_GLOBAL_CSS = """
|
8 |
.limit-height {
|
|
|
13 |
if __name__ == '__main__':
|
14 |
with gr.Blocks(css=_GLOBAL_CSS) as demo:
|
15 |
with gr.Tabs():
|
16 |
+
with gr.Tab('Face Detection'):
|
17 |
+
FaceDetection().make_ui()
|
18 |
+
with gr.Tab('Head Detection'):
|
19 |
+
HeadDetection().make_ui()
|
20 |
with gr.Tab('Eyes Detection'):
|
21 |
EyesDetection().make_ui()
|
22 |
|
detection/__init__.py
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
from .base import ObjectDetection, DeepGHSObjectDetection
|
2 |
-
from .eyes import EyesDetection
|
|
|
|
|
|
1 |
from .base import ObjectDetection, DeepGHSObjectDetection
|
2 |
+
from .eyes import EyesDetection
|
3 |
+
from .face import FaceDetection
|
4 |
+
from .head import HeadDetection
|
detection/face.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
from typing import List, Tuple
|
3 |
+
|
4 |
+
from imgutils.data import ImageTyping
|
5 |
+
from imgutils.detect.face import detect_faces
|
6 |
+
|
7 |
+
from .base import DeepGHSObjectDetection
|
8 |
+
|
9 |
+
|
10 |
+
def _parse_model_name(model_name: str):
|
11 |
+
matching = re.fullmatch(r'^face_detect_(?P<version>[\s\S]+?)_(?P<level>[\s\S]+?)$', model_name)
|
12 |
+
return matching.group('version'), matching.group('level')
|
13 |
+
|
14 |
+
|
15 |
+
class FaceDetection(DeepGHSObjectDetection):
|
16 |
+
def __init__(self):
|
17 |
+
DeepGHSObjectDetection.__init__(self, 'deepghs/anime_face_detection')
|
18 |
+
|
19 |
+
def _get_default_model(self) -> str:
|
20 |
+
return 'face_detect_v1.4_s'
|
21 |
+
|
22 |
+
def _get_default_iou_and_score(self, model_name: str) -> Tuple[float, float]:
|
23 |
+
return 0.7, 0.25
|
24 |
+
|
25 |
+
def _get_labels(self, model_name: str) -> List[str]:
|
26 |
+
return ['face']
|
27 |
+
|
28 |
+
def detect(self, image: ImageTyping, model_name: str,
|
29 |
+
iou_threshold: float = 0.7, score_threshold: float = 0.25) -> \
|
30 |
+
List[Tuple[Tuple[float, float, float, float], str, float]]:
|
31 |
+
version, level = _parse_model_name(model_name)
|
32 |
+
return detect_faces(image, level=level, version=version,
|
33 |
+
conf_threshold=score_threshold, iou_threshold=iou_threshold)
|
detection/head.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os.path
|
2 |
+
import re
|
3 |
+
from typing import List, Tuple
|
4 |
+
|
5 |
+
from hfutils.operate import get_hf_fs
|
6 |
+
from hfutils.utils import hf_fs_path, parse_hf_fs_path
|
7 |
+
from imgutils.data import ImageTyping
|
8 |
+
from imgutils.detect import detect_heads
|
9 |
+
|
10 |
+
from .base import ObjectDetection
|
11 |
+
|
12 |
+
|
13 |
+
def _parse_model_name(model_name: str):
|
14 |
+
matching = re.fullmatch(r'^head_detect_best_(?P<level>[\s\S]+?)$', model_name)
|
15 |
+
return matching.group('level')
|
16 |
+
|
17 |
+
|
18 |
+
class HeadDetection(ObjectDetection):
|
19 |
+
def __init__(self):
|
20 |
+
self.repo_id = 'deepghs/imgutils-models'
|
21 |
+
|
22 |
+
def _get_default_model(self) -> str:
|
23 |
+
return 'head_detect_best_s'
|
24 |
+
|
25 |
+
def _list_models(self) -> List[str]:
|
26 |
+
hf_fs = get_hf_fs()
|
27 |
+
return [
|
28 |
+
os.path.splitext(os.path.basename(parse_hf_fs_path(path).filename))[0]
|
29 |
+
for path in hf_fs.glob(hf_fs_path(
|
30 |
+
repo_id=self.repo_id,
|
31 |
+
repo_type='model',
|
32 |
+
filename='head_detect/*.onnx',
|
33 |
+
))
|
34 |
+
]
|
35 |
+
|
36 |
+
def _get_default_iou_and_score(self, model_name: str) -> Tuple[float, float]:
|
37 |
+
return 0.7, 0.3
|
38 |
+
|
39 |
+
def _get_labels(self, model_name: str) -> List[str]:
|
40 |
+
return ['head']
|
41 |
+
|
42 |
+
def detect(self, image: ImageTyping, model_name: str,
|
43 |
+
iou_threshold: float = 0.7, score_threshold: float = 0.25) -> \
|
44 |
+
List[Tuple[Tuple[float, float, float, float], str, float]]:
|
45 |
+
level = _parse_model_name(model_name)
|
46 |
+
return detect_heads(image=image, level=level,
|
47 |
+
iou_threshold=iou_threshold, conf_threshold=score_threshold)
|