imgutils.detect.censor

Overview:

Detect human censor points (including female’s nipples and genitals of both male and female) in anime images.

Trained on dataset deepghs/anime_censor_detection with YOLOv8.

Overview of Censor Detect (NSFW Warning!!!)../../_images/censor_detect_demo.plot.py.svg

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

../../_images/censor_detect_benchmark.plot.py.svg

detect_censors

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

Detect human censor points 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 overhead, while the s model achieves higher accuracy. The default value is s.

  • version – Version of model, default is v1.0.

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

  • 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 (one of nipple_f, penis and pussy) and the target confidence score.

Examples::
>>> from imgutils.detect import detect_censors, detection_visualize
>>>
>>> image = 'nude_girl.png'
>>> result = detect_censors(image)  # detect it
>>> result
[
    ((365, 264, 399, 289), 'nipple_f', 0.7473511695861816),
    ((224, 260, 252, 285), 'nipple_f', 0.6830288171768188),
    ((206, 523, 240, 608), 'pussy', 0.6799028515815735)
]
>>>
>>> # visualize it
>>> from matplotlib import pyplot as plt
>>> plt.imshow(detection_visualize(image, result))
>>> plt.show()