Github:https://github.com/deepcam-cn/yolov5-face
導(dǎo)讀:居然花了一天時(shí)間把該項(xiàng)目復(fù)現(xiàn),主要是折騰在數(shù)據(jù)集格式上,作者居然在train2yolo中居然把Widerface訓(xùn)練集(12000+張圖)重新一張一張保存,不這么還出bug,原因是無(wú)法讀到數(shù)據(jù)緩存;在評(píng)估階段,val2yolo也沒(méi)用上。搬運(yùn)工,一個(gè)字,肝!
一、設(shè)置
Step by step
克隆倉(cāng)庫(kù),進(jìn)入conda環(huán)境
git clone https://github.com/deepcam-cn/yolov5-face.git
conda activate pytorch-cifar
測(cè)試模型
下載作者預(yù)訓(xùn)練的YOLO5m-face模型,并測(cè)試單張圖片效果。運(yùn)行detectface如下:
"args": [
// // // to run train2yolo:
// "data/widerface/train",
// "data/widerface/train/labels"
// // // to run val2yolo:
// "data/widerface",
// "data/widerface/val/labels"
// // to run detect_face
// "--img-size", "640",
// "--weights", "weights/yolov5m-face.pt",
// to train on widerface
// "CUDA_VISIBLE_DEVICES"," 0, ",
"--data", "data/widerface.yaml",
"--cfg", "models/yolov5s.yaml",
"--weights", "weights/yolov5s.pt"
]
以上是launch.json的配置參數(shù),分別對(duì)應(yīng)幾個(gè)任務(wù)。其中運(yùn)行train2yolo.py,巨慢;val2yolo,可以忽略。
二、訓(xùn)練
2.1 準(zhǔn)備數(shù)據(jù):
推薦去官網(wǎng)http://shuoyang1213.me/WIDERFACE/
下載widerface數(shù)據(jù)集,分別下載train、val、test三個(gè)包。本人參考RetinaFace下載的數(shù)據(jù)集不全面。
由于官網(wǎng)沒(méi)找到人臉關(guān)鍵點(diǎn)的標(biāo)注文本,在開(kāi)頭git鏈接YOLO5face可以下載帶有keypoint的annotation文件。整個(gè)文件結(jié)構(gòu)如下:
(base) wqt@ser2024:NewProjects$ ln -s ~/Datasets/widerface yolov5-face/data/
//
yolov5-face
│ README.md
│ ...
│data
| └─widerface
│ └───test
| └───images
| └───labels
│ └───train
| └───images
| └───labels
| └───0..._1_5.jpg
| └───0..._1_5.txt
│ └───val
目錄畫(huà)得有點(diǎn)丑,但為了說(shuō)明詳細(xì),也是拼了老命。
下載預(yù)訓(xùn)練好的yolo5檢測(cè)模型,由于本工程基于的yolo版本比較舊(最新6.0版)久,下載鏈接參考:
https://github.com/ultralytics/yolov5/releases/tag/v4.0
準(zhǔn)確讀取數(shù)據(jù)路徑,在widerface.yaml修改為:
train: /home/wqt/NewProjects/yolov5-face/data/widerface/train/labels
val: /home/wqt/NewProjects/yolov5-face/data/widerface/val/labels
# number of classes
nc: 1
# class names
names: [ 'face']
運(yùn)行train,沒(méi)報(bào)錯(cuò),佛祖保佑!
autoanchor: Analyzing anchors... anchors/target = 4.02, Best Possible Recall (BPR) = 0.9997
Image sizes 800 train, 800 test
Using 4 dataloader workers
Logging results to runs/train/exp12
Starting training for 250 epochs...
Epoch gpu_mem box obj cls landmark total targets img_size
0/249 4.65G 0.1032 0.03953 0 0.1396 0.2823 25 800: 100%|
Epoch gpu_mem box obj cls landmark total targets img_size
1/249 5.01G 0.08159 0.03674 0 0.02959 0.1479 15 800: 100%|
訓(xùn)練還挺快,一個(gè)epoch才幾分鐘,共250epoch。
有關(guān)YOLO數(shù)據(jù)格式
原始的widerface標(biāo)注如下:
0--Parade/0_Parade_marchingband_1_849.jpg
1
449 330 122 149 0 0 0 0 0 0
轉(zhuǎn)化為YOLO格式,如下:
0--Parade/0_Parade_marchingband_1_849.jpg
449 330 122 149 488.906 373.643 0.0 542.089 376.442 0.0 515.031 412.83 0.0 485.174 425.893 0.0 538.357 431.491 0.0 0.82
即:bbox (xywh) + (xi, yi, flag)
COCO keypoints轉(zhuǎn)化為YOLO格式(17個(gè)人體關(guān)鍵點(diǎn)),以下圖片對(duì)應(yīng)的標(biāo)注如下:
0 0.686445 0.531960 0.082891 0.323967 0.667188 0.399061 1.000000 0.670312 0.396714 2.000000 0.000000 0.000000 0.000000 0.678125 0.394366 2.000000 0.000000 0.000000 0.000000 0.689063 0.415493 2.000000 0.696875 0.415493 2.000000 0.682813 0.469484 2.000000 0.671875 0.483568 2.000000 0.671875 0.516432 2.000000 0.656250 0.504695 2.000000 0.695312 0.530516 2.000000 0.706250 0.523474 2.000000 0.698438 0.610329 2.000000 0.709375 0.603286 2.000000 0.710938 0.680751 2.000000 0.717187 0.671362 2.000000
訓(xùn)練了12h之后,實(shí)測(cè)結(jié)果如下:
Epoch gpu_mem box obj cls landmark total targets img_size
249/249 5.01G 0.03923 0.02193 0 0.00727 0.06844 18 800:
Class Images Targets P R mAP@.5 mAP@.5:.95:
all 3.22e+03 3.96e+04 0.576 0.723 0.715 0.34
即在WiderFace上取得了mAP@0.5=71.5%,mAP@mean=0.34
實(shí)測(cè)1:
實(shí)測(cè)2:
使用縮小五官的效果圖去測(cè)試,發(fā)現(xiàn)有不小誤差,例如嘴角的兩點(diǎn)偏差比較大。
三、評(píng)估
上述模型訓(xùn)練完畢后,需要評(píng)估在Widerface上的性能,運(yùn)行test_widerface,并配置如下。
//to test on the widerface
"--weights", "runs/train/exp12/weights/best.pt",
"--save_folder", "./widerface_evaluate/widerface_txt/",
"--dataset_folder", "data/widerface/val/images/",
"--folder_pict", "data/widerface/val/wider_val.txt"
val2yolo.py跑了那么久,結(jié)果還是用原來(lái)的widerface/val,并且要修改代碼如下:
# for image_path in tqdm(glob.glob(os.path.join(testset_folder, '*'))):
for image_path in tqdm(glob.glob(os.path.join(testset_folder, '*', "*.jpg"))):
(pytorch-cifar) wqt@ser2024:yolov5-face$ cd widerface_evaluate/
(pytorch-cifar) wqt@ser2024:widerface_evaluate$ python evaluation.py
進(jìn)入評(píng)估程序,顯示如下:
Reading Predictions : 100%|
Processing easy: 100%|
Processing medium: 100%|
Processing hard: 100%|
==================== Results ====================
Easy Val AP: 0.9430954074066416
Medium Val AP: 0.9235452692977046
Hard Val AP: 0.8268421552890463
=================================================
與作者訓(xùn)練的性能對(duì)比,在yolov5s情況下,取得:
Easy 94.3% <(94.67%)
Med 92.4% <(92.75%)
Easy 82.7% <(83.03%)
都比作者給出的情況稍微低一些。
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-461820.html
參考:
https://blog.csdn.net/cliu1_16/article/details/120665458文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-461820.html
到了這里,關(guān)于人臉與關(guān)鍵點(diǎn)檢測(cè):YOLO5Face實(shí)戰(zhàn)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!