AFLW如何获取你想要的21点人脸关键点数据

目前人脸检测和人脸的关键点的数据库根据关键点个数:5,20,21,29,68等。https://blog.csdn.net/XZZPPP/article/details/74939823该网页详细列出了相关数据集的网址。由于项目需要和评估数据集大小。我选择了21点的AFLW数据集。网上也有人将该数据放到百度网盘上,可以直接下载。由于数据放在.sqlite。可以通过可视化工具直接查看数据内容。https://www.jianshu.com/p/dfd6e0193460
也可以通过代码来查看:

import sqlite3

sqlite_path = "*/aflw.sqlite"
conn = sqlite3.connect(sqlite_path)
cur = conn.cursor()
cur.execute("SELECT name FROM sqlite_master WHERE type='table'")
Tables = cur.fetchall()
for table in Tables:
    table_name = table[0]
    print(table_name)
    cur.execute("SELECT * FROM {}".format(table_name))
    col_name_list = [tuple[0] for tuple in cur.description]
    print(col_name_list)

打印出来结果如下:

Faces
['face_id', 'file_id', 'db_id']
sqlite_sequence,FacePose,FaceImages,...,CamPose.
['name', 'seq']
FacePose
['face_id', 'roll', 'pitch', 'yaw', 'annot_type_id']
FaceImages
['image_id', 'db_id', 'file_id', 'filepath', 'bw', 'width', 'height']
Databases
['db_id', 'path', 'description']
FaceMetaData
['face_id', 'sex', 'occluded', 'glasses', 'bw', 'annot_type_id']
sqlite_stat1
['tbl', 'idx', 'stat']
FaceRect
['face_id', 'x', 'y', 'w', 'h', 'annot_type_id']
AnnotationType
['annot_type_id', 'description', 'CODE']
FaceEllipse
['face_id', 'x', 'y', 'ra', 'rb', 'theta', 'annot_type_id', 'upsidedown']
NearDuplicates
['face_id']
FeatureCoords
['face_id', 'feature_id', 'x', 'y', 'annot_type_id']
FeatureCoordTypes
['feature_id', 'descr', 'code', 'x', 'y', 'z']
CamPose
['face_id', 'camRoll', 'camPitch', 'camYaw', 'annot_type_id']

现在你可以发现,其实aflw.sqlite就是将Faces,sqlite_sequence,FacePose,FaceImages,...,CamPose这些表合起来放在一起,再存在一个轻量级的数据库中。既然是表,那很自然的我就想到了用pandas来处理数据。因为这些数据需要按需求按face_id合并。

path = "*/aflw.sqlite"
with sqlite3.connect(path) as con:
    df_Faces = pd.read_sql_query("SELECT face_id,file_id FROM Faces", con)
    df_sqlite_sequence = pd.read_sql_query("SELECT name,seq FROM sqlite_sequence", con)
    df_FacePose = pd.read_sql_query("SELECT face_id,roll,pitch,yaw,annot_type_id FROM FacePose", con)
    df_FaceImages = pd.read_sql_query("SELECT image_id, db_id, file_id, filepath, bw, width, height FROM FaceImages", con)
    df_Database = pd.read_sql_query("SELECT db_id,path,description FROM Databases", con)
    df_FaceMetaData = pd.read_sql_query("SELECT face_id, sex, occluded, glasses, bw, annot_type_id FROM FaceMetaData", con)
    df_sqlite_stat1 = pd.read_sql_query("SELECT tbl,idx,stat FROM sqlite_stat1", con)
    df_FaceRect = pd.read_sql_query("SELECT face_id,x,y,w,h,annot_type_id FROM FaceRect", con)
    df_AnnotationType = pd.read_sql_query("SELECT annot_type_id, description,CODE FROM AnnotationType", con)
    df_FaceEllipse = pd.read_sql_query("SELECT face_id,x,y,ra,rb,theta,annot_type_id,upsidedown FROM FaceEllipse", con)
    df_NearDuplicates = pd.read_sql_query("SELECT face_id FROM NearDuplicates", con)
    df_FeatureCoords = pd.read_sql_query("SELECT face_id,feature_id,x,y,annot_type_id FROM FeatureCoords", con)
    df_FeatureCoordTypes = pd.read_sql_query("SELECT feature_id,descr,code,x,y,z FROM FeatureCoordTypes", con)

就这样,我们可以得到所有的表。其中人脸框坐标在df_FaceRect中,21点人脸关键点坐标在df_FeatureCoords中。具体的数据意义,可以参考该数据集的论文:Annotated Facial Landmarks in the Wild: A Large-scale, Real-world Database for Facial Landmark Localization。
下一步,就可以train自己的人脸关键点检测模型了。

posted @ 2018-10-23 19:41  粗面鱼丸  阅读(3383)  评论(1编辑  收藏  举报