Face Detection#

https://github.com/ShiqiYu/libfacedetection/raw/master/images/cnnresult.png

Face detection is the task of detecting faces in a photo or video (and distinguishing them from other objects). We provide the kornia.contrib.FaceDetector to perform multi-face detection in real-time uding the YuNet model.

Learn more: https://paperswithcode.com/task/face-detection

Using our API you easily detect faces in images as shown below:

    # select the device
    device = torch.device('cpu')
    if args.cuda and torch.cuda.is_available():
        device = torch.device('cuda:0')

    # load the image and scale
    img_raw = cv2.imread(args.image_file, cv2.IMREAD_COLOR)
    img_raw = scale_image(img_raw, args.image_size)

    # preprocess
    img = K.image_to_tensor(img_raw, keepdim=False).to(device)
    img = K.color.bgr_to_rgb(img.float())

    # create the detector and find the faces !
    face_detection = FaceDetector().to(device)

    with torch.no_grad():
        dets = face_detection(img)
    dets = [FaceDetectorResult(o) for o in dets]

Check the full example here or run a real-time application using the camera with this example.

The Kornia AI Game#

https://kornia-tutorials.readthedocs.io/en/latest/_images/face_detection_7_1.png https://kornia-tutorials.readthedocs.io/en/latest/_images/face_detection_13_1.png

Tip

Play yourself with the detector and generate new images with this tutorial.