Unverified Commit 5c3bc8e6 authored by narugo1992's avatar narugo1992 Committed by GitHub
Browse files

Merge pull request #23 from deepghs/dev/face

dev(narugo): use new models for face detect
parents 3b0b425e 375e0e7e
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ jobs:
          - '3.9'
          - '3.10'
          - '3.11'
        exclude:
          - python-version: '3.11'

    steps:
      - name: Get system version for Linux
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ class FaceDetectBenchmark(BaseBenchmark):
if __name__ == '__main__':
    create_plot_cli(
        [
            ('face v1.3 (yolov8s)', FaceDetectBenchmark('s', 'v1.3')),
            ('face v1.3 (yolov8n)', FaceDetectBenchmark('n', 'v1.3')),
            ('face v1 (yolov8s)', FaceDetectBenchmark('s', 'v1')),
            ('face v1 (yolov8n)', FaceDetectBenchmark('n', 'v1')),
            ('face v0 (yolov8s)', FaceDetectBenchmark('s', 'v0')),
+584 −377

File changed.

Preview size limit exceeded, changes collapsed.

+13 −13

File changed.

Preview size limit exceeded, changes collapsed.

+10 −12
Original line number Diff line number Diff line
@@ -13,6 +13,9 @@ Overview:
    .. image:: face_detect_benchmark.plot.py.svg
        :align: center

    The models are hosted on
    `huggingface - deepghs/anime_face_detection <https://huggingface.co/deepghs/anime_face_detection>`_.

"""
from functools import lru_cache
from typing import List, Tuple
@@ -23,22 +26,17 @@ from ._yolo import _image_preprocess, _data_postprocess
from ..data import ImageTyping, load_image, rgb_encode
from ..utils import open_onnx_model

_VERSIONS = {
    'v0': '',
    'v1': 'v1_',
}


@lru_cache()
def _open_face_detect_model(level: str = 's', version: str = 'v1'):
def _open_face_detect_model(level: str = 's', version: str = 'v1.3'):
    return open_onnx_model(hf_hub_download(
        'deepghs/imgutils-models',
        f'face_detect/face_detect_{_VERSIONS[version]}best_{level}.onnx'
        f'deepghs/anime_face_detection',
        f'face_detect_{version}_{level}/model.onnx'
    ))


def detect_faces(image: ImageTyping, level: str = 's', version: str = 'v1', max_infer_size=640,
                 conf_threshold: float = 0.45, iou_threshold: float = 0.7) \
def detect_faces(image: ImageTyping, level: str = 's', version: str = 'v1.3', max_infer_size=640,
                 conf_threshold: float = 0.25, iou_threshold: float = 0.7) \
        -> List[Tuple[Tuple[int, int, int, int], str, float]]:
    """
    Overview:
@@ -48,11 +46,11 @@ def detect_faces(image: ImageTyping, level: str = 's', version: str = 'v1', max_
    :param level: The model level being used can be either `s` or `n`.
        The `n` model runs faster with smaller system overface, while the `s` model achieves higher accuracy.
        The default value is `s`.
    :param version: Version of model, default is ``v1``. Available versions are ``v0`` and ``v1``.
    :param version: Version of model, default is ``v1.3``. Available versions are ``v0``, ``v1`` and ``v1.3``.
    :param max_infer_size: The maximum image size used for model inference, if the image size exceeds this limit,
        the image will be resized and used for inference. The default value is `640` pixels.
    :param conf_threshold: The confidence threshold, only detection results with confidence scores above
        this threshold will be returned. The default value is `0.45`.
        this threshold will be returned. The default value is `0.25`.
    :param iou_threshold: The detection area coverage overlap threshold, areas with overlaps above this threshold
        will be discarded. The default value is `0.7`.
    :return: The detection results list, each item includes the detected area `(x0, y0, x1, y1)`,
Loading