imgutils.detect.face
- Overview:
Detect human faces in anime images.
Trained on dataset Anime Face CreateML with YOLOv8.
This is an overall benchmark of all the face detect models:
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', model_name: str | None = None, conf_threshold: float = 0.25, iou_threshold: float = 0.7) List[Tuple[Tuple[int, int, int, int], str, float]] [source]
Detect human faces in anime images using YOLOv8 models.
This function applies a pre-trained YOLOv8 model to detect faces in the given anime image. It supports different model levels and versions, allowing users to balance between detection speed and accuracy.
- Parameters:
image (ImageTyping) – The input image for face detection. Can be various image types supported by ImageTyping.
level (str) – The model level to use. Can be either ‘s’ (standard) or ‘n’ (nano). The ‘n’ model is faster with less system overhead, while ‘s’ offers higher accuracy. Default is ‘s’.
version (str) – The version of the model to use. Available versions are ‘v0’, ‘v1’, ‘v1.3’, and ‘v1.4’. Default is ‘v1.4’.
model_name (Optional[str]) – Optional custom model name. If provided, it overrides the auto-generated model name.
conf_threshold (float) – The confidence threshold for detections. Only detections with confidence scores above this threshold will be returned. Default is 0.25.
iou_threshold (float) – The Intersection over Union (IoU) threshold for non-maximum suppression. Detections with IoU above this threshold will be merged. Default is 0.7.
- Returns:
A list of detected faces. Each face is represented by a tuple containing: - Bounding box coordinates as (x0, y0, x1, y1) - The string ‘face’ (as this function only detects faces) - The confidence score of the detection
- Return type:
List[Tuple[Tuple[int, int, int, int], str, float]]
- 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()