mtcnn算法实现总结

源码地址:https://github.com/Seanlinx/mtcnn
stage 1: Proposal Net,提供大量候选窗口,计算bounding box回归向量并用NMS减少窗口
stage 2: Refining Net,拒绝一些非人脸窗口,计算bounding box回归向量并用NMS减少窗口
stage 3: Outputting Net,输出脸上的5个地标点

git clone https://github.com/Seanlinx/mtcnn.git #下载mtcnn工程

  1. this repository is the implementation of MTCNN in MXnet:
    core: core routines for MTCNN training and testing.
    tools: utilities for training and testing
    data: Refer to Data Folder Structure for dataset reference. Usually dataset contains images and imglists
    model: Folder to save training symbol and model
    prepare_data: scripts for generating training data for pnet, rnet and onet

  2. 程序实现框架:mxnet
    使用pip安装最新版的mxnet,在运行train_P_net.py的时候回报错“Cannot find argument ‘out_grad’”
    解决措施:
    删除core/symbol.py中所有的“out_grad=True”
    或者, 下载mxnet的编译文件,根据mxnet_diff.patch修改 mxnet/src/regression_output-inl.h ,然后编译安装 mxnet,

  3. 数据准备
    下载 Wider Face data
    cd prepare_data/wider_annotations/
    vim transform.py #修改数据存放路径
    python transform.py # 生成anno.txt

4.训练 p-net:
1)vim gen_pnet_data.py # 修改数据集路径
然后再修改 img = cv2.imread(os.path.join(im_dir, im_path + ‘.jpg’))
Is img = cv2.imread(os.path.join(im_path))
运行gen_pnet_data.py # 生成 12x12 数据集和pnet文件夹

  1. python gen_imglist.py # size = 12 net=pnet #produce train_12.txt把12x12的数据集文件放在images文件夹中,train_12.txt放在和images同级的imglists文件夹中
    3)运行example/train_P_net.py
    parser.add_argument(’–dataset_path’, dest=‘dataset_path’, help=‘dataset folder’,default='pnet 数据路径 ', type=str)

如果出现 logloss = nan 修改 example/train.py的optimizer_params参数
optimizer_params = {‘momentum’: 0.9,
‘wd’: 0.00001,
‘learning_rate’: lr,
‘lr_scheduler’: lr_scheduler,
‘rescale_grad’: 1.0
cip_gradient: 5}#添加 cip_gradient: 5
如果loss值比较大 修改 lr = 0.001

5.训练 Rnet
Run gen_hard_data.py # test_mode=“pnet” test.txt 是 anno.txt
Run gen_imglist_rnet.py
Run train_O_net.py

  1. 训练Onet
    Run gen_hard_data.py # test_mode=“rnet” test.txt 是 anno.txt
    Run gen_imglist_onet.py
    Run train_O_net.py

你可能感兴趣的:(mtcnn算法实现总结)