MTCNN(一)训练与运行

版权声明:转载注明出处:邢翔瑞的技术博客https://blog.csdn.net/weixin_36474809/article/list/1 https://blog.csdn.net/weixin_36474809/article/details/82752199

参考地址: https://github.com/wangbm/MTCNN-Tensorflow/blob/master/README.md

一、相关知识

三个CNN串联

P-Net:(12-Net)Fast proposal Network,找出备选框。

R-Net:(24-Net)Refinement Network,对备选框进行重新选择   

O-Net:(48-Net)Output Network,输出最终的box与最终的landmark position

二、训练与运行 

2.1 背景知识

tfrecords

tfrecords格式文件,tensorflow统一用来存储数据的文件。https://blog.csdn.net/u012222949/article/details/72875281/

扫描二维码关注公众号,回复: 3427930 查看本文章

2.2 程序作用

参考网址:https://github.com/AITTSMD/MTCNN-Tensorflow/blob/master/prepare_data/%E8%AF%B4%E6%98%8E

gen_12net_data.py
    训练PNet的数据的采样代码
gen_hard_example.py
    分别生成RNet和ONet的训练数据
gen_imglist_xxnet.py
    分别将三个网络的三个任务(分类,回归,特征点检测)的数据汇总到一个文件中
gen_xx_tfrecords.py
    分别生成3个网络的tfrecord,在这里需要注意:
        PNet的训练数据(pos,neg,part,landmark)是混在一起的,生成了一个tfrecord
    RNet和ONet的各自需要生成4个tfrecord(pos,neg,part,landmark),因为要控制各部分的样本比例(1:3:1:1)
loader.py
    迭代器,用于读取图片
read_tfrecord_v2.py/tfrecord_utils.py
    用于读取tfrecord数据,并对其解析
utils.py
    用于一些数据处理操作
gen_landmark_tfrecords_aug_xx.py
    用于生成特征点的数据,在这里并没有生成tfreord,只是对进行数据增强(随机镜像、随机旋转)
    此脚本的输入是trainImageList.txt,其中定义了文件的路径,人脸框的位置(x1,x2,y1,y2),特征点的位置(x1,y1,,,,,x5,y5)
BBox_utils.py/landmark_utils.py
    用于特征点处理

2.3 命令行

训练流程:

数据集下载,格式转换。

以下每一步都要转换目录。训练为根目录,生成样本为/prepare_data目录

生成12net的训练数据,把12net的训练数据生成tfrecords文件 cd prepare data/

python gen_shuffle_data.py 12
python gen_tfdata_12net.py 

训练12net(P-Net)根目录

python src/mtcnn_pnet_test.py

根据训练结果生成12net输出的难样本,生成24net随机样本并合并这两个生成的样本cd prepare data/

注意更改hard_example之中的模型路径。

python tf_gen_12net_hard_example.py
python gen_shuffle_data.py 24
python gen_tfdata_24net.py

训练24net(R-Net)根目录

python src/mtcnn_rnet_test.py

根据生成的网络生成24net输出的难样本,生成48net随机样本并合并这两个生成的样本cd prepare data/

python tf_gen_24net_hard_example.py
python gen_shuffle_data.py 48
python gen_tfdata_48net.py

训练48-Net(O-Net)根目录

python src/mtcnn_onet_test.py

2.4 运行程序

python test_img.py (IMAGE_PATH) --model_dir ./save_model/all_in_one
python test_img.py images/0_1_f_36.jpg --model_dir ./save_model/new_saver 

2.5 指定运行的显卡命令行

https://blog.csdn.net/gaoprincess/article/details/78738348

CUDA_VISIBLE_DEVICES=1,3 python test_all.py images --model_dir /save_model/new_saver

三、参数量的查询

3.1 tensorflow的参数量的存储

在save_model/new_saver这个文件夹里面,

https://stackoverflow.com/questions/44516609/tensorflow-what-is-the-relationship-between-ckpt-file-and-ckpt-meta-and-ckp

  • .ckpt-meta contains the metagraph, i.e. the structure of your computation graph, without the values of the variables (basically what you can see in tensorboard/graph).

  • .ckpt-data contains the values for all the variables, without the structure. To restore a model in python, you'll usually use the meta and data files with (but you can also use the .pb file):

    saver = tf.train.import_meta_graph(path_to_ckpt_meta)
    saver.restore(sess, path_to_ckpt_data)
checkpoint  # some information on the name of the files in the checkpoint
my-model.data-00000-of-00001  # the saved weights
my-model.index  # probably definition of data layout in the previous file
my-model.meta  # protobuf of the graph (nodes and topology info)

猜你喜欢

转载自blog.csdn.net/weixin_36474809/article/details/82752199
今日推荐