imgutils.detect.face

Overview:

Detect human faces in anime images.

Trained on dataset Anime Face CreateML with YOLOv8.

../../_images/face_detect_demo.plot.py.svg

This is an overall benchmark of all the face detect models:

../../_images/face_detect_benchmark.plot.py.svg

The models are hosted on huggingface - deepghs/anime_face_detection.

detect_faces

imgutils.detect.face.detect_faces(image: str | PathLike | bytes | bytearray | BinaryIO | Image, level: str = 's', version: str = 'v1.4', max_infer_size=640, conf_threshold: float = 0.25, iou_threshold: float = 0.7) List[Tuple[Tuple[int, int, int, int], str, float]][source]
Overview:

Detect human faces in anime images.

Parameters:
  • image – Image to detect.

  • 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.

  • version – Version of model, default is v1.4. Available versions are v0, v1, v1.3 and v1.4.

  • 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.

  • conf_threshold – The confidence threshold, only detection results with confidence scores above this threshold will be returned. The default value is 0.25.

  • iou_threshold – The detection area coverage overlap threshold, areas with overlaps above this threshold will be discarded. The default value is 0.7.

Returns:

The detection results list, each item includes the detected area (x0, y0, x1, y1), the target type (always face) and the target confidence score.

Examples::
>>> from imgutils.detect import detect_faces, detection_visualize
>>>
>>> image = 'mostima_post.jpg'
>>> result = detect_faces(image)  # detect it
>>> result
[
    ((29, 441, 204, 584), 'face', 0.7874319553375244),
    ((346, 59, 529, 275), 'face', 0.7510495185852051),
    ((606, 51, 895, 336), 'face', 0.6986488103866577)
]
>>>
>>> # visualize it
>>> from matplotlib import pyplot as plt
>>> plt.imshow(detection_visualize(image, result))
>>> plt.show()