MMPose 2D 人脸关键点数据集完全指南:从数据准备、标注转换到训练评测全流程
【免费下载链接】mmposeOpenMMLab Pose Estimation Toolbox and Benchmark.项目地址: https://gitcode.com/GitHub_Trending/mm/mmpose
本文为 MMPose 人脸 2D 关键点(2D Face Keypoint)任务的官方数据集指南(Dataset Zoo)配套实战文章。它完整覆盖 MMPose 当前支持的 7 个人脸数据集(300W、300VW、WFLW、AFLW、COFW、COCO-WholeBody-Face、LaPa)的下载渠道、目录结构组织方式与标注转换脚本用法,并结合 mmpose/datasets/datasets/face/ 数据集类源码与 configs/face_2d_keypoint/topdown_heatmap/ 下的训练配置,深入解析人脸数据的坐标归一化、关键点元信息定义与 NME 评测链路,帮助你从零完成一个人脸关键点模型的完整训练与评测流程。
一、数据集总览与目录约定
MMPose 人脸关键点任务官方文档(docs/en/dataset_zoo/2d_face_keypoint.md)推荐将数据集根目录软链接到$MMPOSE/data;如果你的目录结构不同,则需要相应修改配置文件中的路径。当前仓库支持的数据集如下,各自的标注点位数以 configs/base/datasets/ 下的元信息配置为准:
| 数据集 | 标注点数 | 元信息配置(仓库路径) | 对应数据集类 |
|---|---|---|---|
| 300W | 68 | configs/base/datasets/300w.py | Face300WDataset |
| 300VW | 68 | configs/base/datasets/300vw.py | Face300VWDataset |
| WFLW | 98 | configs/base/datasets/wflw.py | WFLWDataset |
| AFLW | 19 | configs/base/datasets/aflw.py | AFLWDataset |
| COFW | 29 | configs/base/datasets/cofw.py | COFWDataset |
| COCO-WholeBody-Face | 106(face-0 ~ face-105) | configs/base/datasets/coco_wholebody_face.py | CocoWholeBodyFaceDataset |
| LaPa | 98 | configs/base/datasets/lapa.py | LapaDataset |
上述 7 个数据集类统一在 mmpose/datasets/datasets/face/init.py 中注册导出,全部继承自BaseCocoStyleDataset,即标注文件均采用 COCO 格式(JSON)组织,这使得各数据集可以复用同一套数据加载、变换与解码逻辑。
从源码结构看,所有人脸数据集类的parse_data_info方法都遵循同一套解析范式,其核心逻辑可概括为三步:
- 图像路径拼接:
img_path = osp.join(self.data_prefix['img'], img['file_name']),因此配置中的data_prefix=dict(img='images/')必须与本文各数据集的目录结构一致; - bbox 归一化还原:标注中的 bbox scale 是以 200 为因子归一化的,源码中以
pixel_std = 200.将其还原为像素尺度,再通过bbox_cs2xyxy(center, scale)由中心+尺度还原出 xyxy 格式框(见 mmpose/datasets/datasets/face/face_300w_dataset.py); - 关键点拆分:将
[1, -1, 3]的 COCO 关键点数组拆成keypoints(前 2 维坐标)与keypoints_visible(可见性标记,np.minimum(1, v)),并保留num_keypoints等字段。
各数据集类的 docstring 还额外说明了标注协议:例如 300W 遵循 68 点标记法、WFLW 遵循 98 点标记法(见 mmpose/datasets/datasets/face/wflw_dataset.py),这是理解各数据集 keypoint_info 中swap字段(用于水平翻转增强时关键点左右配对)的基础。
一个值得注意的细节是 mmpose/datasets/datasets/face/aflw_dataset.py:AFLW 在test_mode下会强制要求标注中包含box_size字段,它被用作 NME 的归一化因子。这说明 AFLW 评测的归一化方式与其他数据集(通常用左右眼瞳距)并不相同,若你自行转换 AFLW 标注,务必保留该字段,否则评测会直接抛出断言错误。
二、300W 数据集
论文出处:300 faces in-the-wild challenge: Database and results(IMAVIS'2016)
@article{sagonas2016300, title={300 faces in-the-wild challenge: Database and results}, author={Sagonas, Christos and Antonakos, Epameinondas and Tzimiropoulos, Georgios and Zafeiriou, Stefanos and Pantic, Maja}, journal={Image and vision computing}, volume={47}, pages={3--18}, year={2016}, publisher={Elsevier} }下载与组织方式:
- 图像:从 300W 官方主页(IBUG 300-W 页面)下载;
- 标注:从 OpenMMLab 官方标注包
300w_annotations.tar(下载地址见 docs/en/dataset_zoo/2d_face_keypoint.md)获取,解压到{MMPose}/data下,目录结构如下:
mmpose ├── mmpose ├── docs ├── tests ├── tools ├── configs `── data │── 300w |── annotations | |── face_landmarks_300w_train.json | |── face_landmarks_300w_valid.json | |── face_landmarks_300w_valid_common.json | |── face_landmarks_300w_valid_challenge.json | |── face_landmarks_300w_test.json `── images |── afw | |── 1051618982_1.jpg | |── 111076519_1.jpg | ... |── helen | |── trainset | | |── 100032540_1.jpg | | |── 100040721_1.jpg | | ... | |── testset | | |── 296814969_3.jpg | | |── 2968560214_1.jpg | | ... |── ibug | |── image_003_1.jpg | |── image_004_1.jpg | ... |── lfpw | |── trainset | | |── image_0001.png | | |── image_0002.png | | ... | |── testset | | |── image_0001.png | | |── image_0002.png | | ... `── Test |── 01_Indoor | |── indoor_001.png | |── indoor_002.png | ... `── 02_Outdoor |── outdoor_001.png |── outdoor_002.png ...训练配置实证:仓库内置了 300W 的完整训练配置 td-hm_hrnetv2-w18_8xb64-60e_300w-256x256.py,其关键参数与上述目录结构一一对应:
dataset_type = 'Face300WDataset' data_mode = 'topdown' data_root = 'data/300w/' train_dataloader = dict( batch_size=64, ... dataset=dict( type=dataset_type, data_root=data_root, data_mode=data_mode, ann_file='annotations/face_landmarks_300w_train.json', data_prefix=dict(img='images/'), pipeline=train_pipeline, )) val_evaluator = dict( type='NME', norm_mode='keypoint_distance', )可以看到:训练/验证标注分别对应目录树中的face_landmarks_300w_train.json与face_landmarks_300w_valid.json;data_prefix=dict(img='images/')则解释了为何图像必须放在data/300w/images/下并按 afw、helen、ibug、lfpw 等子目录组织(COCO 标注中file_name字段已包含子目录前缀)。评测指标使用NME(Normalized Mean Error),norm_mode='keypoint_distance'表示以关键点间距离作为归一化因子。此外该配置中模型头out_channels=68,与 300W 的 68 点协议严格匹配——切换数据集时必须同步修改通道数与 meta info 来源。
三、300VW 数据集
论文出处:The First Facial Landmark Tracking in-the-Wild Challenge: Benchmark and Results(ICCVW'2015)
@inproceedings{shen2015first, title={The first facial landmark tracking in-the-wild challenge: Benchmark and results}, author={Shen, Jie and Zafeiriou, Stefanos and Chrysos, Grigoris G and Kossaifi, Jean and Tzimiropoulos, Georgios and Pantic, Maja}, booktitle={Proceedings of the IEEE international conference on computer vision workshops}, pages={50--58}, year={2015} }下载与转换流程:
- 300VW 为视频序列数据集,需先向 IBUG 官方注册并从其发布页下载视频压缩包;
- 解压后使用仓库内置转换脚本 tools/dataset_converters/300vw2coco.py 处理数据,将视频抽帧并生成 COCO 风格标注;
- 将处理后的 300VW 放到
{MMPose}/data下,组织为:
mmpose ├── mmpose ├── docs ├── tests ├── tools ├── configs `── data │── 300vw |── annotations | |── train.json | |── test_1.json | |── test_2.json | `── test_3.json `── images |── 001 | `── imgs | |── 000001.png | |── 000002.png | ... |── 002 | `── imgs | |── 000001.png | |── 000002.png | ... | ...从源码看,tools/dataset_converters/300vw2coco.py 的extract_frames函数通过 ffmpeg 将每个视频抽取为imgs/%06d.png命名的帧序列(起始编号为 1,质量参数-q:v 0保持无损),这正是目录结构中每个视频编号(如001、002)下都带一个imgs子目录的原因;脚本还内置了完整视频编号清单(001~562 共 100 余段视频)以及损坏帧过滤表(broken_frames.npy),保证生成的train.json/test_1~3.json与帧文件一一对应。由于脚本会调用 ffmpeg,执行前请确保环境中已安装该工具。
四、WFLW 数据集
论文出处:Look at Boundary: A Boundary-Aware Face Alignment Algorithm(CVPR'2018)
@inproceedings{wu2018look, title={Look at boundary: A boundary-aware face alignment algorithm}, author={Wu, Wayne and Qian, Chen and Yang, Shuo and Wang, Quan and Cai, Yici and Zhou, Qiang}, booktitle={Proceedings of the IEEE conference on computer vision and pattern recognition}, pages={2129--2138}, year={2018} }下载与组织方式:
- 图像:从 WFLW 官方页面下载;
- 标注:从 OpenMMLab 官方标注包
wflw_annotations.tar获取,解压到{MMPose}/data,目录结构为:
mmpose ├── mmpose ├── docs ├── tests ├── tools ├── configs `── data │── wflw |── annotations | |── face_landmarks_wflw_train.json | |── face_landmarks_wflw_test.json | |── face_landmarks_wflw_test_blur.json | |── face_landmarks_wflw_test_occlusion.json | |── face_landmarks_wflw_test_expression.json | |── face_landmarks_wflw_test_largepose.json | |── face_landmarks_wflw_test_illumination.json | |── face_landmarks_wflw_test_makeup.json | `── images |── 0--Parade | |── 0_Parade_marchingband_1_1015.jpg | |── 0_Parade_marchingband_1_1031.jpg | ... |── 1--Handshaking | |── 1_Handshaking_Handshaking_1_105.jpg | |── 1_Handshaking_Handshaking_1_107.jpg | ... ...官方文档特别提醒:MMPose 也提供了将原始 WFLW 标注转换为 COCO 风格的脚本,其输出与上述下载包中的标注并非完全一致,但不影响训练与测试——因此优先推荐直接使用下载好的标注包。
WFLW 的一大特点是按测试条件(大姿态 largepose、遮挡 occlusion、模糊 blur、光照 illumination、妆容 makeup、表情 expression)分别切分了测试子集,这正好对应其评测表中的分列指标。官方模型库(configs/face_2d_keypoint/topdown_heatmap/README.md)给出了 HRNetv2-w18 系列在 WFLW 上的 NME 参考结果:
| Model | Input Size | NME(test) | NME(pose) | NME(illumination) | NME(occlusion) | NME(blur) | NME(makeup) | NME(expression) |
|---|---|---|---|---|---|---|---|---|
| HRNetv2-w18+Dark | 256x256 | 3.98 | 6.98 | 3.96 | 4.78 | 4.56 | 3.89 | 4.29 |
| HRNetv2-w18+AWing | 256x256 | 4.02 | 6.94 | 3.97 | 4.78 | 4.59 | 3.87 | 4.28 |
| HRNetv2-w18 | 256x256 | 4.06 | 6.97 | 3.99 | 4.83 | 4.58 | 3.94 | 4.33 |
对应训练配置见 td-hm_hrnetv2-w18_8xb64-60e_wflw-256x256.py 及 Dark / AWing 变体,其 meta info 来源于 configs/base/datasets/wflw.py,其中定义了 98 个关键点及成对swap翻转关系(如 kpt-0 与 kpt-32 互为镜像),供水平翻转数据增强时使用。
五、AFLW 数据集
论文出处:Annotated Facial Landmarks in the Wild: A Large-scale, Real-world Database for Facial Landmark Localization(ICCVW'2011)
@inproceedings{koestinger2011annotated, title={Annotated facial landmarks in the wild: A large-scale, real-world database for facial landmark localization}, author={Koestinger, Martin and Wohlhart, Paul and Roth, Peter M and Bischof, Horst}, booktitle={2011 IEEE international conference on computer vision workshops (ICCV workshops)}, pages={2144--2151}, year={2011}, organization={IEEE} }下载与组织方式:
- 图像:从 AFLW 官方下载页( Graz TU、Bischof 团队 LRS 下载区)获取;
- 标注:从 OpenMMLab 官方标注包
aflw_annotations.tar获取,解压到{MMPose}/data,目录结构:
mmpose ├── mmpose ├── docs ├── tests ├── tools ├── configs `── data │── aflw |── annotations | |── face_landmarks_aflw_train.json | |── face_landmarks_aflw_test_frontal.json | |── face_landmarks_aflw_test.json `── images |── flickr |── 0 | |── image00002.jpg | |── image00013.jpg | ... |── 2 | |── image00004.jpg | |── image00006.jpg | ... `── 3 |── image00032.jpg |── image00035.jpg ...AFLW 提供test_frontal(正脸子集)与完整 test 两个评测集,官方结果表同时报告 NME(full) 与 NME(frontal) 两列。如前文源码分析所述,AFLW 的测试标注必须携带box_size字段用于 NME 归一化(mmpose/datasets/datasets/face/aflw_dataset.py),这是其评测链路区别于其他 6 个人脸数据集的关键点。
六、COFW 数据集
论文出处:Robust Face Landmark Estimation under Occlusion(ICCV'2013)
@inproceedings{burgos2013robust, title={Robust face landmark estimation under occlusion}, author={Burgos-Artizzu, Xavier P and Perona, Pietro and Doll{\'a}r, Piotr}, booktitle={Proceedings of the IEEE international conference on computer vision}, pages={1513--1520}, year={2013} }下载与转换流程:
- 从 COFW 官方页面下载彩色图像版数据包
COFW_color.zip; - 将
COFW_train_color.mat与COFW_test_color.mat两个 MATLAB 标注文件移动到data/cofw/下:
mmpose ├── mmpose ├── docs ├── tests ├── tools ├── configs `── data │── cofw |── COFW_train_color.mat |── COFW_test_color.mat- 在
{MMPose}/data目录下运行转换脚本:
python tools/dataset_converters/parse_cofw_dataset.py脚本执行后会生成如下结构:
mmpose ├── mmpose ├── docs ├── tests ├── tools ├── configs `── data │── cofw |── COFW_train_color.mat |── COFW_test_color.mat |── annotations | |── cofw_train.json | |── cofw_test.json |── images |── 000001.jpg |── 000002.jpg注意官方文档强调脚本必须在{MMPose}/data目录下运行,因为 tools/dataset_converters/parse_cofw_dataset.py 内部以当前工作目录定位cofw子目录,输出的annotations/cofw_train.json、annotations/cofw_test.json与解压出的images/也均相对该目录组织。
七、COCO-WholeBody(Face)数据集
论文出处:Whole-Body Human Pose Estimation in the Wild(ECCV'2020)
@inproceedings{jin2020whole, title={Whole-Body Human Pose Estimation in the Wild}, author={Jin, Sheng and Xu, Lumin and Xu, Jin and Wang, Can and Liu, Wentao and Qian, Chen and Ouyang, Wanli and Luo, Ping}, booktitle={Proceedings of the European Conference on Computer Vision (ECCV)}, year={2020} }这是将人脸关键点放在整身体姿态框架下评测的数据集,官方文档给出了三类资源的下载要求:
- 图像:从 COCO 官方下载页获取 2017 Train/Val(COCO 关键点训练与验证均基于该版本);
- COCO-WholeBody 标注:从官方发布的 Google Drive 链接分别下载 Train 与 Val 标注文件;
- 人体检测结果:COCO val2017 的人体检测先验框(OneDrive / Google Drive 发布),用于 top-down 流程中替代 ground-truth 框。
将上述资源解压到$MMPOSE/data下,目录结构为:
mmpose ├── mmpose ├── docs ├── tests ├── tools ├── configs `── data │── coco │-- annotations │ │-- coco_wholebody_train_v1.0.json │ |-- coco_wholebody_val_v1.0.json |-- person_detection_results | |-- COCO_val2017_detections_AP_H_56_person.json │-- train2017 │ │-- 000000000009.jpg │ │-- 000000000025.jpg │ │-- 000000000030.jpg │ │-- ... `-- val2017 │-- 000000000139.jpg │-- 000000000285.jpg │-- 000000000632.jpg │-- ...此外,官方文档要求安装扩展版 COCO API 以支持 COCO-WholeBody 评测:
pip install xtcocotools从元信息配置看,configs/base/datasets/coco_wholebody_face.py 将 106 个人脸关键点命名为face-0~face-105并定义了成对 swap 关系(如 face-0 ↔ face-16),与独立 300W 数据集的kpt-*命名相区分,避免与身体关键点 ID 冲突。官方结果表中该数据集上的模型覆盖 HRNetv2-w18+Dark(NME 0.0513)、SCNet-50、ResNet-50、HourglassNet、MobileNet-v2 等多个骨干,训练配置均位于 configs/face_2d_keypoint/topdown_heatmap/coco_wholebody_face/。
八、LaPa 数据集
论文出处:A New Dataset and Boundary-Attention Semantic Segmentation for Face Parsing(AAAI'2020)
@inproceedings{liu2020new, title={A New Dataset and Boundary-Attention Semantic Segmentation for Face Parsing.}, author={Liu, Yinglu and Shi, Hailin and Shen, Hao and Si, Yue and Wang, Xiaobo and Mei, Tao}, booktitle={AAAI}, pages={11637--11644}, year={2020} }下载与转换流程:
- 从 LaPa 官方 GitHub 页面(JDAI-CV/lapa-dataset)下载数据集;
- 解压到
$MMPOSE/data下,并使用仓库脚本tools/dataset_converters/lapa2coco.py转换为如下结构:
mmpose ├── mmpose ├── docs ├── tests ├── tools ├── configs `── data │── LaPa │-- annotations │ │-- lapa_train.json │ |-- lapa_val.json │ |-- lapa_test.json │ |-- lapa_trainval.json │-- train │ │-- images │ │-- labels │ │-- landmarks │-- val │ │-- images │ │-- labels │ │-- landmarks `-- test │ │-- images │ │-- labels │ │-- landmarksLaPa 原始包中每个 split(train/val/test)同时包含images(图像)、labels(解析分割标签)、landmarks(98 点关键点)三类资源;tools/dataset_converters/lapa2coco.py 负责把 landmarks 汇总为annotations/下的 4 个 COCO 风格 JSON(train/val/test/trainval)。对应 meta info 见 configs/base/datasets/lapa.py,其 98 点定义与 WFLW 协议一致(含相同结构的 swap 镜像对),因此两者可在数据组织层面互相参照。
九、训练与评测要点小结
完成数据准备后,人脸关键点任务的标准训练入口为(以 300W 为例):
python tools/train.py configs/face_2d_keypoint/topdown_heatmap/300w/td-hm_hrnetv2-w18_8xb64-60e_300w-256x256.py评测则通过tools/test.py指定相同的测试配置,val_evaluator/test_evaluator统一采用NME指标(300W 配置中还以save_best='NME'按验证集 NME 保存最优 checkpoint,见 td-hm_hrnetv2-w18_8xb64-60e_300w-256x256.py)。
结合仓库源码,切换数据集时有三个必须同步修改的位置,这也是全部 7 个人脸数据集类共享同一解析范式所带来的工程约束:
- 标注与目录:
ann_file、data_prefix必须匹配本文各数据集给出的目录树(尤其 AFLW 的test标注需含box_size); - 关键点协议:
HeatmapHead.out_channels必须等于数据集标注点数(300W/300VW 为 68、AFLW 为 19、COFW 为 29、WFLW/LaPa 为 98、COCO-WholeBody-Face 为 106); - meta info 来源:数据集类的
METAINFO通过dict(from_file='configs/_base_/datasets/xxx.py')声明来源(如 face_300w_dataset.py 指向 configs/base/datasets/300w.py),其中定义的 keypoint 颜色、swap 镜像对直接决定了翻转增强的正确性与可视化效果。
各数据集的参考精度与预训练权重下载地址,可进一步查阅 configs/face_2d_keypoint/topdown_heatmap/README.md 中按数据集分节列出的模型表;中文社区文档可参考 docs/zh_cn/dataset_zoo/2d_face_keypoint.md。
【免费下载链接】mmposeOpenMMLab Pose Estimation Toolbox and Benchmark.项目地址: https://gitcode.com/GitHub_Trending/mm/mmpose
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考