Skip to main content

Batch Face Preprocessing for Modern Research

Project description

Batch Face for Modern Research

🚧Documentation under construction, check tests folder for more details. 🚧

This repo provides the out-of-box face detection and face alignment with batch input support and enables real-time application on CPU.

Features

  1. Batch input support for faster data processing.
  2. Smart API.
  3. Ultrafast with inference runtime acceleration.
  4. Automatically download pre-trained weights.
  5. Minimal dependencies.

Requirements

  • Linux, Windows or macOS
  • Python 3.5+ (it may work with other versions too)
  • opencv-python
  • PyTorch (>=1.0)
  • ONNX (optional)

While not required, for optimal performance it is highly recommended to run the code using a CUDA enabled GPU.

Install

The easiest way to install it is using pip:

pip install git+https://github.com/elliottzheng/batch-face.git@master

No extra setup needs, most of the pretrained weights will be downloaded automatically.

Usage

You can clone the repo and run tests like this

python -m tests.camera

Face Detection

Detect face and five landmarks on single image
import cv2
from batch_face import RetinaFace

detector = RetinaFace(gpu_id=0)
img = cv2.imread("examples/obama.jpg")
faces = detector(img, cv=True) # set cv to False for rgb input, the default value of cv is False
box, landmarks, score = faces[0]
Running on CPU/GPU

In order to specify the device (GPU or CPU) on which the code will run one can explicitly pass the device id.

from batch_face import RetinaFace
# 0 means using GPU with id 0 for inference
# default -1: means using cpu for inference
detector = RetinaFace(gpu_id=0) 
GPU(GTX 1080TI,batch size=1) GPU(GTX 1080TI,batch size=750) CPU(Intel(R) Core(TM) i7-7800X CPU @ 3.50GHz)
FPS 44.02405810720893 96.64058005582535 15.452635835550483
SPF 0.022714852809906007 0.010347620010375976 0.0647138786315918
Batch input for faster detection

Detector with CUDA process batch input faster than the same amount of single input.

import cv2
from batch_face import RetinaFace

detector = RetinaFace()
img= cv2.imread('examples/obama.jpg')[...,::-1]
all_faces = detector([img,img]) # return faces list of all images
box, landmarks, score = all_faces[0][0]

Note: All the input images must of the same size, for input images with different size, please use detector.pseudo_batch_detect.

Face Alignment

face alignment on single image
from batch_face import drawLandmark_multiple, LandmarkPredictor, RetinaFace

predictor = LandmarkPredictor(0)
detector = RetinaFace(0)

imgname = "examples/obama.jpg"
img = cv2.imread(imgname)

faces = detector(img, cv=True)

if len(faces) == 0:
    print("NO face is detected!")
    exit(-1)

# the first input for the predictor is a list of face boxes. [[x1,y1,x2,y2]]
results = predictor(faces, img, from_fd=True) # from_fd=True to convert results from our detection results to simple boxes

for face, landmarks in zip(faces, results):
    img = drawLandmark_multiple(img, face[0], landmarks)

References

@inproceedings{deng2019retinaface,
title={RetinaFace: Single-stage Dense Face Localisation in the Wild},
author={Deng, Jiankang and Guo, Jia and Yuxiang, Zhou and Jinke Yu and Irene Kotsia and Zafeiriou, Stefanos},
booktitle={arxiv},
year={2019}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

batch_face-1.0.0-py3.8.egg (39.1 kB view details)

Uploaded Source

batch_face-1.0.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file batch_face-1.0.0-py3.8.egg.

File metadata

  • Download URL: batch_face-1.0.0-py3.8.egg
  • Upload date:
  • Size: 39.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for batch_face-1.0.0-py3.8.egg
Algorithm Hash digest
SHA256 f36e7e69b4be46b7b6ffdc11ce8ec3009065cee9d041d740030840c484820ac5
MD5 a60071e4a4c3d25b6dae8deef47a29bf
BLAKE2b-256 5ebd03bdab2ae4ba30d190a47e608a1502daaadb6261a467abf5f182375f1ee7

See more details on using hashes here.

Provenance

File details

Details for the file batch_face-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: batch_face-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for batch_face-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0aea7452cacd729b2c9404a172fd00b243043d630cdb81b9e66eb98a38795e7
MD5 ae8d23005c9cfe5a2f0beef79fa5cff1
BLAKE2b-256 d560699cb5200a13f56a92127bcbd9467d805308c9dbff8f4f63b22d9d6423b6

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page