# 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](https://arxiv.org/abs/1604.02878).
## Why this projects
[mtcnn-pytorch](https://github.com/TropComplique/mtcnn-pytorch) This is the most popular pytorch implementation of mtcnn. There are some disadvantages we found when using it for real-time detection task.
- No training code.
- Mix torch operation and numpy operation together, which resulting in slow inference speed.
- No unified interface for setting computation device. ('cpu' or 'gpu')
- Based on the old version of pytorch (0.2).
So we create this project and add these features:
- Add code for training stage, you can train model by your own datasets.
- Transfer all numpy operation to torch operation, so that it can benefit from gpu acceleration. It's 10 times faster than the original repo [mtcnn-pytorch](https://github.com/TropComplique/mtcnn-pytorch).
- Provide unified interface to assign 'cpu' or 'gpu'.
- Based on the latest version of pytorch (1.0) and we will provide long-term support.
- It's is a component of our [FaceLab](https://github.com/faciallab) ecosystem.
- Real-time face tracking.
- Friendly tutorial for beginner.
## Installation
### Create virtual env use conda (recommend)
```
conda create -n face_detection python=3
source activate face_detection
```
### Installation dependency package
```bash
pip install opencv-python numpy easydict Cython progressbar2 torch tensorboardX
```
If you have gpu on your mechine, you can follow the [official instruction](https://pytorch.org/) and install pytorch gpu version.
### Compile the cython code
Compile with gpu support
```bash
python setup.py build_ext --inplace
```
Compile with cpu only
```bash
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
```bash
python -m unittest tests.test_detection.TestDetection.test_detection
```
#### Detect on video
```bash
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
```python
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, landmarks = detector.detect(img)
# Then we draw bounding boxes and landmarks on image
image = cv2.imread(img)
image = mtcnn.utils.draw.draw_boxes2(image, boxes)
image = mtcnn.utils.draw.batch_draw_landmarks(image, landmarks)
# Show the result
cv2.imshwow("Detected image.", image)
cv2.waitKey(0)
```
## Doc
[Train your own model from scratch](./doc/TRAIN.md)
## Tutorial
[Detect step by step](./tutorial/detect_step_by_step.ipynb).
[face_alignment step by step](./tutorial/face_align.ipynb)
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
FaceDetector-master.zip (80个子文件)
FaceDetector-master
tutorial
detect_step_by_step.ipynb 1.33MB
face_align.ipynb 1.08MB
README.md 0B
setup.py 6KB
doc
TRAIN.md 1KB
tests
test_net_pytorch.py 2KB
__init__.py 0B
test_align.py 1KB
test_landmarks.py 2KB
test_functional.py 3KB
test_tracker.py 2KB
asset
images
roate.jpg 53KB
office5.jpg 65KB
bksomels.jpg 16KB
audrey.jpg 11KB
gpripe.jpg 13KB
video
track.mp4 13.71MB
test_batch_detection.py 3KB
test_gptd.py 3KB
test_data.py 533B
test_net_jit.py 1001B
test_train.py 769B
test_datasets.py 3KB
test_detection.py 3KB
output
caffe_models
det1.prototxt 2KB
det4.prototxt 14KB
det3.prototxt 4KB
det4.caffemodel 3.62MB
det3.caffemodel 1.49MB
det1.caffemodel 28KB
det2.caffemodel 398KB
det2.prototxt 3KB
mtcnn
__init__.py 260B
train
gen_rnet_train.py 6KB
gen_onet_train.py 6KB
__init__.py 0B
gen_pnet_train.py 7KB
gen_landmark.py 4KB
data.py 7KB
train_net.py 8KB
utils
__init__.py 18B
draw.py 2KB
align_trans.py 10KB
nms
__init__.py 0B
gpu_nms.pyx 1KB
gpu_nms.cpp 347KB
nms_kernel.cu 5KB
cpu_nms.c 467KB
gpu_nms.hpp 146B
cpu_nms.pyx 5KB
py_cpu_nms.py 1KB
cp2tform.py 6KB
functional.py 3KB
datasets
__init__.py 424B
FacePoint
.gitignore 13B
celeba.py 3KB
WIDER_FACE
.gitignore 13B
wider_face.py 3KB
CelebA
.gitignore 13B
network
__init__.py 0B
mtcnn_pytorch.py 11KB
deploy
__init__.py 2KB
tracker.py 4KB
batch_detect.py 14KB
align.py 1KB
models
rnet.npy 591KB
pnet.npy 40KB
onet.npy 2.24MB
detect.py 12KB
.gitignore 1KB
README.md 3KB
scripts
gen_rnet_train.py 2KB
gen_onet_train.py 2KB
train_pnet.py 896B
convert_caffe_model.py 3KB
track_on_video.py 2KB
train_onet.py 933B
train_rnet.py 928B
gen_pnet_train.py 2KB
detect_on_video.py 2KB
共 80 条
- 1
资源评论
半个女码农
- 粉丝: 5037
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功