Skip to content

cs-giung/face-detection-pytorch

Repository files navigation

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

  • MTCNN
./detectors/mtcnn/weights/pnet.npy
./detectors/mtcnn/weights/rnet.npy
./detectors/mtcnn/weights/onet.npy
  • FaceBoxes
./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:

MTCNN FaceBoxes Tiny face PyramidBox S3FD DSFD
# of boxes 210 28 686 512 475 528
minimum box size 71 1136 138 109 108 113
minimum box size 1046 27901 36912 24059 26711 15814

Demo 02 : crop

python demo_crop.py

Face Size

  • Minimum and maximum lengths of detected boxes are as follows:
MTCNN Tiny face S3FD DSFD
min length (pixel) 000.0 000.0 000.0 000.0
max length (pixel) 000.0 000.0 000.0 000.0

References