Home

Awesome

Face Detection

PyTorch implementations of various face detection algorithms (last updated on 2019-08-03).

Usage Example

import cv2, random
from detectors import DSFD
from utils import draw_bboxes, crop_thumbnail, draw_bbox

# load detector with device(cpu or cuda)
DET = DSFD(device='cpu')

# load image in RGB
img = cv2.imread('bts.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# get bboxes with some confidence in scales for image pyramid
bboxes = DET.detect_faces(img, conf_th=0.9, scales=[0.5, 1])

# and draw bboxes on your image
img_bboxed = draw_bboxes(img, bboxes, fill=0.2, thickness=3)

# or crop thumbnail of someone
i = random.randrange(0, len(bboxes))
img_thumb, bbox_thumb = crop_thumbnail(img, bboxes[i], padding=1, size=100)

# you can use 'bbox_thumb' as bbox in thumbnail-coordinate system.
img_thumb_bboxed = draw_bbox(img_thumb, bbox_thumb)

Weight Files

./detectors/mtcnn/weights/pnet.npy
./detectors/mtcnn/weights/rnet.npy
./detectors/mtcnn/weights/onet.npy
./detectors/faceboxes/weights/FaceBoxes.pth
./detectors/tinyface/weights/checkpoint_50.pth
./detectors/pyramidbox/weights/pyramidbox_120000_99.02.pth
./detectors/s3fd/weights/sfd_face.pth
./detectors/dsfd/weights/dsfd_vgg_0.880.pth

Demo 01 : detect

python demo_detect.py

Note that it shows bounding boxes only for default scale image without image pyramid. Number of bounding boxes ─ not detected faces ─ and minimum box sizes are as follows:

MTCNNFaceBoxesTiny facePyramidBoxS3FDDSFD
# of boxes21028686512475528
minimum box size711136138109108113
minimum box size10462790136912240592671115814

Demo 02 : crop

python demo_crop.py

Face Size

MTCNNTiny faceS3FDDSFD
min length (pixel)000.0000.0000.0000.0
max length (pixel)000.0000.0000.0000.0

References