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 using 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[0]]

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