narugo commited on
Commit
312aecc
1 Parent(s): 92125df

dev(narugo): add 2 new models

Browse files
app.py CHANGED
@@ -3,7 +3,7 @@ import os
3
  import gradio as gr
4
 
5
  from detection import EyesDetection, FaceDetection, HeadDetection, PersonDetection, HandDetection, CensorDetection, \
6
- HalfBodyDetection
7
 
8
  _GLOBAL_CSS = """
9
  .limit-height {
@@ -36,5 +36,9 @@ if __name__ == '__main__':
36
  HandDetection().make_ui()
37
  with gr.Tab('Censor Point Detection'):
38
  CensorDetection().make_ui()
 
 
 
 
39
 
40
  demo.queue(os.cpu_count()).launch()
 
3
  import gradio as gr
4
 
5
  from detection import EyesDetection, FaceDetection, HeadDetection, PersonDetection, HandDetection, CensorDetection, \
6
+ HalfBodyDetection, NudeNetDetection, BooruYOLODetection
7
 
8
  _GLOBAL_CSS = """
9
  .limit-height {
 
36
  HandDetection().make_ui()
37
  with gr.Tab('Censor Point Detection'):
38
  CensorDetection().make_ui()
39
+ with gr.Tab('NudeNet'):
40
+ NudeNetDetection().make_ui()
41
+ with gr.Tab('BooruYOLO'):
42
+ BooruYOLODetection().make_ui()
43
 
44
  demo.queue(os.cpu_count()).launch()
detection/__init__.py CHANGED
@@ -1,8 +1,10 @@
1
  from .base import ObjectDetection, DeepGHSObjectDetection
 
2
  from .censor import CensorDetection
3
  from .eyes import EyesDetection
4
  from .face import FaceDetection
5
  from .halfbody import HalfBodyDetection
6
  from .hand import HandDetection
7
  from .head import HeadDetection
 
8
  from .person import PersonDetection
 
1
  from .base import ObjectDetection, DeepGHSObjectDetection
2
+ from .booru_yolo import BooruYOLODetection
3
  from .censor import CensorDetection
4
  from .eyes import EyesDetection
5
  from .face import FaceDetection
6
  from .halfbody import HalfBodyDetection
7
  from .hand import HandDetection
8
  from .head import HeadDetection
9
+ from .nudenet import NudeNetDetection
10
  from .person import PersonDetection
detection/base.py CHANGED
@@ -9,6 +9,14 @@ from hfutils.utils import hf_fs_path, parse_hf_fs_path
9
  from imgutils.data import ImageTyping
10
 
11
 
 
 
 
 
 
 
 
 
12
  class ObjectDetection:
13
  @lru_cache()
14
  def get_default_model(self) -> str:
@@ -51,7 +59,7 @@ class ObjectDetection:
51
  _color_map = dict(zip(labels, _colors))
52
  return gr.AnnotatedImage(
53
  value=(image, [
54
- (bbox, label) for bbox, label, _ in
55
  self.detect(image, model_name, iou_threshold, score_threshold)
56
  ]),
57
  color_map=_color_map,
 
9
  from imgutils.data import ImageTyping
10
 
11
 
12
+ def _v_fix(v):
13
+ return int(round(v))
14
+
15
+
16
+ def _bbox_fix(bbox):
17
+ return tuple(map(_v_fix, bbox))
18
+
19
+
20
  class ObjectDetection:
21
  @lru_cache()
22
  def get_default_model(self) -> str:
 
59
  _color_map = dict(zip(labels, _colors))
60
  return gr.AnnotatedImage(
61
  value=(image, [
62
+ (_bbox_fix(bbox), label) for bbox, label, _ in
63
  self.detect(image, model_name, iou_threshold, score_threshold)
64
  ]),
65
  color_map=_color_map,
detection/booru_yolo.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List, Tuple
2
+
3
+ from imgutils.data import ImageTyping
4
+ from imgutils.detect.booru_yolo import detect_with_booru_yolo, _get_booru_yolo_labels, _DEFAULT_MODEL
5
+
6
+ from .base import DeepGHSObjectDetection
7
+
8
+
9
+ class BooruYOLODetection(DeepGHSObjectDetection):
10
+ def __init__(self):
11
+ DeepGHSObjectDetection.__init__(self, repo_id='deepghs/booru_yolo')
12
+
13
+ def _get_default_model(self) -> str:
14
+ return _DEFAULT_MODEL
15
+
16
+ def _get_default_iou_and_score(self, model_name: str) -> Tuple[float, float]:
17
+ return 0.7, 0.25
18
+
19
+ def _get_labels(self, model_name: str) -> List[str]:
20
+ return _get_booru_yolo_labels(model_name)
21
+
22
+ def detect(self, image: ImageTyping, model_name: str,
23
+ iou_threshold: float = 0.7, score_threshold: float = 0.25) -> \
24
+ List[Tuple[Tuple[float, float, float, float], str, float]]:
25
+ return detect_with_booru_yolo(image=image, model_name=model_name,
26
+ iou_threshold=iou_threshold, conf_threshold=score_threshold)
detection/nudenet.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List, Tuple
2
+
3
+ from imgutils.data import ImageTyping
4
+ from imgutils.detect.nudenet import detect_with_nudenet, _LABELS
5
+
6
+ from .base import ObjectDetection
7
+
8
+
9
+ class NudeNetDetection(ObjectDetection):
10
+ def _get_default_model(self) -> str:
11
+ return 'Default'
12
+
13
+ def _list_models(self) -> List[str]:
14
+ return ['Default']
15
+
16
+ def _get_default_iou_and_score(self, model_name: str) -> Tuple[float, float]:
17
+ return 0.45, 0.25
18
+
19
+ def _get_labels(self, model_name: str) -> List[str]:
20
+ return _LABELS
21
+
22
+ def detect(self, image: ImageTyping, model_name: str,
23
+ iou_threshold: float = 0.7, score_threshold: float = 0.25) -> \
24
+ List[Tuple[Tuple[float, float, float, float], str, float]]:
25
+ return detect_with_nudenet(image=image, iou_threshold=iou_threshold, score_threshold=score_threshold)