Unverified Commit 9e05ed38 authored by narugo1992's avatar narugo1992 Committed by GitHub
Browse files

Merge pull request #18 from deepghs/dev/head

dev(narugo): rename face detection to head detection
parents fe4548b7 fa809d69
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -69,17 +69,17 @@ print(lpips_clustering(images)) # -1 means noises, the same as that in sklearn

### Object Detection

Currently, object detection is supported for anime faces and person, as shown below
Currently, object detection is supported for anime heads and person, as shown below

* Face Detection
* Head Detection

![face detection](https://github.com/deepghs/imgutils/blob/gh-pages/main/_images/face_detect.dat.svg)
![head detection](https://github.com/deepghs/imgutils/blob/gh-pages/main/_images/head_detect.dat.svg)

* Person Detection

![person detection](https://github.com/deepghs/imgutils/blob/gh-pages/main/_images/person_detect.dat.svg)

Based on practical tests, face detection currently has a very stable performance and can be used for automation tasks.
Based on practical tests, head detection currently has a very stable performance and can be used for automation tasks.
However, person detection is still being further iterated and will focus on enhancing detection capabilities for
artistic illustrations in the future.

+14 −0
Original line number Diff line number Diff line
imgutils.detect.face
imgutils.detect.head
==========================

.. currentmodule:: imgutils.detect.face
.. currentmodule:: imgutils.detect.head

.. automodule:: imgutils.detect.face
.. automodule:: imgutils.detect.head


detect_faces
detect_heads
------------------------------

.. autofunction:: detect_faces
.. autofunction:: detect_heads

+34 −0
Original line number Diff line number Diff line
import random

from benchmark import BaseBenchmark, create_plot_cli
from imgutils.detect import detect_faces
from imgutils.detect import detect_heads


class FaceDetectBenchmark(BaseBenchmark):
class HeadDetectBenchmark(BaseBenchmark):
    def __init__(self, level):
        BaseBenchmark.__init__(self)
        self.level = level

    def load(self):
        from imgutils.detect.face import _open_face_detect_model
        _ = _open_face_detect_model(level=self.level)
        from imgutils.detect.head import _open_head_detect_model
        _ = _open_head_detect_model(level=self.level)

    def unload(self):
        from imgutils.detect.face import _open_face_detect_model
        _open_face_detect_model.cache_clear()
        from imgutils.detect.head import _open_head_detect_model
        _open_head_detect_model.cache_clear()

    def run(self):
        image_file = random.choice(self.all_images)
        _ = detect_faces(image_file, level=self.level)
        _ = detect_heads(image_file, level=self.level)


if __name__ == '__main__':
    create_plot_cli(
        [
            ('face (yolov8s)', FaceDetectBenchmark('s')),
            ('face (yolov8n)', FaceDetectBenchmark('n')),
            ('head (yolov8s)', HeadDetectBenchmark('s')),
            ('head (yolov8n)', HeadDetectBenchmark('n')),
        ],
        title='Benchmark for Anime Face Detections',
        title='Benchmark for Anime Head Detections',
        run_times=10,
        try_times=20,
        try_times=5,
    )()
+4 −4
Original line number Diff line number Diff line
from imgutils.detect import detect_faces
from imgutils.detect import detect_heads
from imgutils.detect.visual import detection_visualize
from plot import image_plot


def _detect(img, **kwargs):
    return detection_visualize(img, detect_faces(img, **kwargs))
    return detection_visualize(img, detect_heads(img, **kwargs))


if __name__ == '__main__':
    image_plot(
        (_detect('nian.png'), 'large scale'),
        (_detect('two_bikini_girls.png'), 'closed faces'),
        (_detect('two_bikini_girls.png'), 'closed heads'),
        (_detect('genshin_post.jpg'), 'multiple'),
        (_detect('mostima_post.jpg'), 'anime style'),
        save_as='face_detect.dat.svg',
        save_as='head_detect.dat.svg',
        columns=2,
        figsize=(12, 9),
    )
Loading