-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yangyun1
committed
Jul 30, 2020
1 parent
68890e7
commit 120bfad
Showing
145 changed files
with
6,761 additions
and
9,393 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,51 @@ | ||
In this repository you will learn to build your own neural-network from scratch. To get started make sure you have `git`, a C/C++ compiler, and `make` installed. Then run: | ||
## 人脸识别 | ||
-------------------- | ||
这个仓库是基于 arcface 论文上完成的,其中主要分为四大块:人脸检测、人脸矫正、提取特征和特征比对。各个模块的大小和在 17 款 macbook-pro 的 CPU 上跑耗时如下: | ||
|
||
- 人脸检测:使用的是 mtcnn 网络,模型大小约 1.9MB,耗时约 70ms; | ||
- 人脸矫正:OpenCV 的仿射变换,耗时约 0.83ms; | ||
- 提取特征:使用 MobileFaceNet 和 IResNet 网络; | ||
- 特征比对:使用曼哈顿距离,单次搜索和完成比对耗时约 0.011 ms; | ||
|
||
⏳ Contents | ||
-------------------- | ||
|
||
- [x] support to load image,more details see [example01.cpp](https://github.com/YunYang1994/yynet/blob/master/examples/example01.cpp) | ||
- [x] support to resize, copy and gray in image processing,more details see [example02.cpp](https://github.com/YunYang1994/yynet/blob/master/examples/example02.cpp) | ||
- [x] implement a fully connected layer to classify mnist data | ||
## 注册人脸 | ||
|
||
⚙️ Useage | ||
-------------------- | ||
注册人脸的方式有两种,分别是: | ||
|
||
1. 打开相机注册: | ||
|
||
- download mnist data | ||
```bashrc | ||
$ wget https://pjreddie.com/media/files/mnist.tar.gz | ||
$ tar xvzf mnist.tar.gz | ||
$ python register_face.py -person Sam -camera | ||
``` | ||
- make your example | ||
|
||
按 `s` 键保存图片,需要在不同距离和角度拍摄 10 张图片或者按 `q` 退出。 | ||
|
||
2. 导入人脸图片: | ||
|
||
保证文件的名字与注册人名相同,并且每张图片只能出现一张这个 ID 的人脸。 | ||
|
||
|
||
```bashrc | ||
$ make example01 | ||
$ ./example01 images/sample.png 3 | ||
$ python register_face.py -person Jay | ||
``` | ||
|
||
## 识别人脸 | ||
|
||
|Method | LFW(%) | CFP-FP(%) | AgeDB-30(%) | MegaFace(%)| TensorFlow | 权重链接 | | ||
|:---:|:---:|:---:|:---:|:---:|:---:|:---:| | ||
| MobileFaceNet | 99.50 | 88.94 | 95.91 | --- | 35ms | [提取码: xgmo](https://pan.baidu.com/s/1QIYpHYazaPMTI0E15WRGug) | ||
| MobileFaceNet | 99.77 | 98.27 | 98.28 | 98.47 | 435ms | -- | ||
|
||
|
||
|
||
识别模型用的是 `MobileFaceNet` 网络,这里直接使用了 [insightface](https://github.com/deepinsight/insightface) 在 ms1m-refine-v1 三百万多万张人脸数据集上训练的模型。这部分工作在 `mxnet` 分支上,你可以通过 `git checkout mxnet` 进行切换。 | ||
|
||
由于该模型是 mxnet 格式,因此使用了 [mmdnn](https://github.com/microsoft/MMdnn) 导出了其模型权重 `mobilefacenet.npy`。接着使用了 `TF2` 自己手写了一个 `MobileFaceNet` 网络并导入权重,预测精度没有任何损失。这部分工作在 `master` 分支上。 | ||
|
||
最后,如果你要识别人脸,可以执行: | ||
|
||
```bashrc | ||
$ python main.py | ||
``` | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /bin/bash | ||
|
||
#================================================================ | ||
# Copyright (C) 2020 * Ltd. All rights reserved. | ||
# | ||
# Editor : VIM | ||
# File name : convert_to_ir.sh | ||
# Author : YunYang1994 | ||
# Created date: 2020-02-28 16:06:54 | ||
# Description : | ||
# | ||
#================================================================ | ||
|
||
python3 -m mmdnn.conversion._script.convertToIR -f mxnet -n model-symbol.json -w model-0000.params --inputShape 3,112,112 -o mobilefacenet | ||
python3 -m mmdnn.conversion._script.IRToCode -f tensorflow --IRModelPath mobilefacenet.pb --IRWeightPath mobilefacenet.npy --dstModelPath tf_mobilefacenet.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#! /usr/bin/env python | ||
# coding=utf-8 | ||
#================================================================ | ||
# Copyright (C) 2020 * Ltd. All rights reserved. | ||
# | ||
# Editor : VIM | ||
# File name : convert_to_tflite.py | ||
# Author : YunYang1994 | ||
# Created date: 2020-02-15 14:47:28 | ||
# Description : | ||
# | ||
#================================================================ | ||
|
||
import sys | ||
sys.path.append("../") | ||
|
||
import numpy as np | ||
import tensorflow as tf | ||
from mtcnn import PNet, RNet, ONet | ||
|
||
def load_weights(model, weights_file): | ||
weights_dict = np.load(weights_file, encoding='latin1').item() | ||
for layer_name in weights_dict.keys(): | ||
layer = model.get_layer(layer_name) | ||
if "conv" in layer_name: | ||
layer.set_weights([weights_dict[layer_name]["weights"], weights_dict[layer_name]["biases"]]) | ||
else: | ||
prelu_weight = weights_dict[layer_name]['alpha'] | ||
try: | ||
layer.set_weights([prelu_weight]) | ||
except: | ||
layer.set_weights([prelu_weight[np.newaxis, np.newaxis, :]]) | ||
return True | ||
|
||
pnet, rnet, onet = PNet(), RNet(), ONet() | ||
pnet(tf.ones(shape=[1, 12, 12, 3])) | ||
rnet(tf.ones(shape=[1, 24, 24 ,3])) | ||
onet(tf.ones(shape=[1, 48, 48, 3])) | ||
load_weights(pnet, "./det1.npy"), load_weights(rnet, "./det2.npy"), load_weights(onet, "./det3.npy") | ||
|
||
pnet.predict(tf.ones(shape=[1, 12, 12, 3])) | ||
pnet_converter = tf.lite.TFLiteConverter.from_keras_model(pnet) | ||
pnet_converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE] | ||
with open("pnet.tflite", "wb") as f: | ||
pnet_tflite_model = pnet_converter.convert() | ||
f.write(pnet_tflite_model) | ||
|
||
rnet.predict(tf.ones(shape=[1, 24, 24, 3])) | ||
rnet_converter = tf.lite.TFLiteConverter.from_keras_model(rnet) | ||
rnet_converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE] | ||
with open("rnet.tflite", "wb") as f: | ||
rnet_tflite_model = rnet_converter.convert() | ||
f.write(rnet_tflite_model) | ||
|
||
onet.predict(tf.ones(shape=[1, 48, 48, 3])) | ||
onet_converter = tf.lite.TFLiteConverter.from_keras_model(onet) | ||
onet_converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE] | ||
with open("onet.tflite", "wb") as f: | ||
onet_tflite_model = onet_converter.convert() | ||
f.write(onet_tflite_model) | ||
|
Binary file not shown.
Oops, something went wrong.