python人脸识别训练模型生产_深度学习-人脸识别DFACE模型pytorch训练(二)
首先介紹一下MTCNN的網(wǎng)絡(luò)結(jié)構(gòu),MTCNN有三種網(wǎng)絡(luò),訓(xùn)練網(wǎng)絡(luò)的時候需要通過三部分分別進(jìn)行,每一層網(wǎng)絡(luò)都依賴前一層網(wǎng)絡(luò)產(chǎn)生訓(xùn)練數(shù)據(jù)供當(dāng)前訓(xùn)練網(wǎng)絡(luò),這樣也推動了兩個網(wǎng)絡(luò)之間的最小損耗。
Pnet
Rnet
Onet
MTCNN的人臉模型按照以上結(jié)構(gòu)按照三部分進(jìn)行訓(xùn)練。
DFace有兩個主要模塊,即檢測和識別。在這兩個模塊中,我們提供了有關(guān)如何訓(xùn)練模型和運(yùn)行的所有教程。
首先設(shè)置一個pytorch和cv2,版本要求:
* pytorch==0.4.0
* torchvision==0.2.0
* opencv-python==3.4.0.12
pip install torch==0.4.0 torchvision==0.2.0 -i?https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python==3.4.0.12 -i https://pypi.tuna.tsinghua.edu.cn/simple
安裝依賴庫matplotlib:pip install matplotlib
(1)首先將DFace包git到本地用戶目錄,不要放在根目錄:
git clone https://github.com/tuvia0213/DFace.git
(2)添加DFace路徑添加到本地python路徑:
export PYTHONPATH=$PYTHONPATH:{your local DFace root path}/DFace
(3)打開../DFace路徑將WIDER FACE數(shù)據(jù)集下載到../DFace/WIDER_train/下
(WIDER_train下載地址http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/);
將CelebA下載到../DFace/Celeba/路徑下
(CelebA下載地址:http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html)
并將../CelebA/Img/目錄下的img_align_celeba壓縮包解壓到該目錄;其中WIDER FACE用于訓(xùn)練人臉分類器與人臉約束框(Bounding Box,代碼里常見形式為BBox),CelebA用于訓(xùn)練人臉坐標(biāo)點(landmark點,人臉檢測中的標(biāo)點為雙眼、鼻子、兩個嘴角);
(4)進(jìn)入到../DFace路徑下,生成PNet訓(xùn)練數(shù)據(jù)和注釋文件(annotation file):
python dface/prepare_data/gen_Pnet_train_data.py --prefix_path WIDER_train/images/ --dface_traindata_store data/ --anno_file anno_store/wider_origin_anno.txt
(5)組合注釋文件并將其隨機(jī)分布:
python dface/prepare_data/assemble_pnet_imglist.py
(6)訓(xùn)練Pnet模型:
python dface/train_net/train_p_net.py
(7)生成RNet訓(xùn)練數(shù)據(jù)和注釋文件:
python dface/prepare_data/gen_Rnet_train_data.py --prefix_path WIDER_train/images/ --dface_traindata_store data/ --anno_file? anno_store/wider_origin_anno.txt --pmodel_file model_store/pnet_epoch_10.pt
(8)組合注釋文件并將其隨機(jī)分布:
python dface/prepare_data/assemble_rnet_imglist.py
(9)訓(xùn)練Rnet模型:
python dface/train_net/train_r_net.py
(10)生成ONet訓(xùn)練數(shù)據(jù)和注釋文件:
python dface/prepare_data/gen_Onet_train_data.py --prefix_path WIDER_train/images/ --dface_traindata_store data/ --anno_file anno_store/wider_origin_anno.txt --pmodel_file model_store/pnet_epoch_10.pt --rmodel_file model_store/rnet_epoch_10.pt
(11)生成Onet訓(xùn)練landmark點數(shù)據(jù),在此之前,生成testImageList.txt,需先將merge_file.py復(fù)制到celeba/CelebA/Anno路徑下:
python dface/prepare_data/gen_landmark_48.py --dface_traindata_store data/ --anno_file celeba/CelebA/Anno/testImageList.txt --prefix_path celeba/CelebA/Img/img_align_celeba
(12)組合注釋文件并將其隨機(jī)分布:
python dface/prepare_data/assemble_onet_imglist.py
(13)訓(xùn)練Onet模型:
python dface/train_net/train_o_net.py
DFace路徑下提供了測試圖片與測試腳本,可以用于測試訓(xùn)練網(wǎng)絡(luò)的識別效果,回到../DFace路徑下:
python test_image.py
顯示出識別圖片效果:
至此,模型訓(xùn)練完成,可以使用../DFace/model_store下的pnet_epoch_10.pt rnet_epoch_10.pt onet_epoch_10.pt進(jìn)行模型轉(zhuǎn)換,從pytorch轉(zhuǎn)caffe轉(zhuǎn)ncnn。
總結(jié)
以上是生活随笔為你收集整理的python人脸识别训练模型生产_深度学习-人脸识别DFACE模型pytorch训练(二)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vc++ 提取网页上的文字_网页内容不让
- 下一篇: python中sendkeys.send