Spaces:
Running
Running
Commit
·
2d64837
1
Parent(s):
2fb58d7
dev(narugo): 2 more
Browse files- app2.py +11 -1
- detection/__init__.py +2 -0
- detection/hand.py +33 -0
- detection/person.py +53 -0
app2.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
from detection import EyesDetection, FaceDetection, HeadDetection
|
| 6 |
|
| 7 |
_GLOBAL_CSS = """
|
| 8 |
.limit-height {
|
|
@@ -17,7 +17,17 @@ if __name__ == '__main__':
|
|
| 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 |
|
| 23 |
demo.queue(os.cpu_count()).launch()
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
from detection import EyesDetection, FaceDetection, HeadDetection, PersonDetection, HandDetection
|
| 6 |
|
| 7 |
_GLOBAL_CSS = """
|
| 8 |
.limit-height {
|
|
|
|
| 17 |
FaceDetection().make_ui()
|
| 18 |
with gr.Tab('Head Detection'):
|
| 19 |
HeadDetection().make_ui()
|
| 20 |
+
with gr.Tab('Person Detection'):
|
| 21 |
+
PersonDetection().make_ui()
|
| 22 |
+
with gr.Tab('Half Body Detection'):
|
| 23 |
+
pass
|
| 24 |
with gr.Tab('Eyes Detection'):
|
| 25 |
EyesDetection().make_ui()
|
| 26 |
+
with gr.Tab('Hand Detection'):
|
| 27 |
+
HandDetection().make_ui()
|
| 28 |
+
with gr.Tab('Censor Point Detection'):
|
| 29 |
+
pass
|
| 30 |
+
with gr.Tab('Manbits Detection\n(Deprecated)'):
|
| 31 |
+
pass
|
| 32 |
|
| 33 |
demo.queue(os.cpu_count()).launch()
|
detection/__init__.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
from .base import ObjectDetection, DeepGHSObjectDetection
|
| 2 |
from .eyes import EyesDetection
|
| 3 |
from .face import FaceDetection
|
|
|
|
| 4 |
from .head import HeadDetection
|
|
|
|
|
|
| 1 |
from .base import ObjectDetection, DeepGHSObjectDetection
|
| 2 |
from .eyes import EyesDetection
|
| 3 |
from .face import FaceDetection
|
| 4 |
+
from .hand import HandDetection
|
| 5 |
from .head import HeadDetection
|
| 6 |
+
from .person import PersonDetection
|
detection/hand.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.hand import detect_hands, _LABELS
|
| 6 |
+
|
| 7 |
+
from .base import DeepGHSObjectDetection
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _parse_model_name(model_name: str):
|
| 11 |
+
matching = re.fullmatch(r'^hand_detect_(?P<version>[\s\S]+?)_(?P<level>[\s\S]+?)$', model_name)
|
| 12 |
+
return matching.group('version'), matching.group('level')
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
class HandDetection(DeepGHSObjectDetection):
|
| 16 |
+
def __init__(self):
|
| 17 |
+
DeepGHSObjectDetection.__init__(self, repo_id='deepghs/anime_hand_detection')
|
| 18 |
+
|
| 19 |
+
def _get_default_model(self) -> str:
|
| 20 |
+
return 'hand_detect_v1.0_s'
|
| 21 |
+
|
| 22 |
+
def _get_default_iou_and_score(self, model_name: str) -> Tuple[float, float]:
|
| 23 |
+
return 0.7, 0.35
|
| 24 |
+
|
| 25 |
+
def _get_labels(self, model_name: str) -> List[str]:
|
| 26 |
+
return _LABELS
|
| 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_hands(image, level=level, version=version,
|
| 33 |
+
conf_threshold=score_threshold, iou_threshold=iou_threshold)
|
detection/person.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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_person
|
| 9 |
+
|
| 10 |
+
from .base import ObjectDetection
|
| 11 |
+
|
| 12 |
+
_VERSIONS = {
|
| 13 |
+
'': 'v0',
|
| 14 |
+
'plus_': 'v1',
|
| 15 |
+
'plus_v1.1_': 'v1.1',
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _parse_model_name(model_name: str):
|
| 20 |
+
matching = re.fullmatch(r'^person_detect_(?P<content>[\s\S]+?)best_(?P<level>[\s\S]+?)$', model_name)
|
| 21 |
+
return _VERSIONS[matching.group('content')], matching.group('level')
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class PersonDetection(ObjectDetection):
|
| 25 |
+
def __init__(self):
|
| 26 |
+
self.repo_id = 'deepghs/imgutils-models'
|
| 27 |
+
|
| 28 |
+
def _get_default_model(self) -> str:
|
| 29 |
+
return 'person_detect_plus_v1.1_best_m'
|
| 30 |
+
|
| 31 |
+
def _list_models(self) -> List[str]:
|
| 32 |
+
hf_fs = get_hf_fs()
|
| 33 |
+
return [
|
| 34 |
+
os.path.splitext(os.path.basename(parse_hf_fs_path(path).filename))[0]
|
| 35 |
+
for path in hf_fs.glob(hf_fs_path(
|
| 36 |
+
repo_id=self.repo_id,
|
| 37 |
+
repo_type='model',
|
| 38 |
+
filename='person_detect/*.onnx',
|
| 39 |
+
))
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
def _get_default_iou_and_score(self, model_name: str) -> Tuple[float, float]:
|
| 43 |
+
return 0.5, 0.3
|
| 44 |
+
|
| 45 |
+
def _get_labels(self, model_name: str) -> List[str]:
|
| 46 |
+
return ['person']
|
| 47 |
+
|
| 48 |
+
def detect(self, image: ImageTyping, model_name: str,
|
| 49 |
+
iou_threshold: float = 0.7, score_threshold: float = 0.25) -> \
|
| 50 |
+
List[Tuple[Tuple[float, float, float, float], str, float]]:
|
| 51 |
+
version, level = _parse_model_name(model_name)
|
| 52 |
+
return detect_person(image=image, level=level, version=version,
|
| 53 |
+
iou_threshold=iou_threshold, conf_threshold=score_threshold)
|