Skip to content

lauraslopes/mtcnnpp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

185 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MTCNN++

pytorch implementation of inference and training stage of face detection algorithm described in
Joint Face Detection and Alignment using Multi-task Cascaded Convolutional Networks and MTCNN++: A CNN-based face detection algorithm inspired by MTCNN

Why this projects

There isn't an official implementation of MTCNN++, so we create this project forked from mtcnn and adapted these features:

  • Modify PNet, RNet and ONet as described in the MTCNN++ article.
  • Removed facial landmarks detection.

Installation

Create virtual env (recommend)

python -m venv .venv
source .venv/bin/activate

Installation dependency package

pip install  \-r requirements.txt

If you have gpu on your mechine, you can follow the official instruction and install pytorch gpu version.

Compile the cython code

Compile with gpu support

python setup.py build_ext --inplace

Compile with cpu only

python setup.py build_ext --inplace --disable_gpu 

Also, you can install mtcnn as a package

python setup.py install

Test the code by example

We assume all these command running in the $SOURCE_ROOT directory.

Detect on example picture

python -m unittest tests.test_detection.TestDetection.test_detection

Detect on video

python scripts/detect_on_video.py --video_path ./tests/asset/video/school.avi --device cuda:0 --minsize 24

you can set device to 'cpu' if you have no valid gpu on your machine

Basic Usage

import cv2
import mtcnn

# First we create pnet, rnet, onet, and load weights from caffe model.
pnet, rnet, onet = mtcnn.get_net_caffe('output/converted')

# Then we create a detector
detector = mtcnn.FaceDetector(pnet, rnet, onet, device='cuda:0')

# Then we can detect faces from image
img = 'tests/asset/images/office5.jpg'
boxes = detector.detect(img)

# Then we draw bounding boxes and landmarks on image
image = cv2.imread(img)
image = mtcnn.utils.draw.draw_boxes2(image, boxes)

# Show the result
cv2.imshwow("Detected image.", image)
cv2.waitKey(0)

Doc

Train your own model from scratch

Tutorial

Detect step by step.

face_alignment step by step

About

A implementation of mtcnn++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Jupyter Notebook 93.9%
  • Python 5.7%
  • Other 0.4%