下载链接:
http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/
该数据集可用于进行人脸检测模型的训练
如果做训练,可以点击网页中的
(国内还是百度吧,会快一些)
这个下载下来是按文件夹分好的,全都是图片。对于训练,还少label的信息,点这个下载:
Label的部分下下来后会发现,测试、训练、验证的信息被分开存放。有mat和txt两个版本。如果txt直接通过windows自带的记事本打开会发现各种数据被拧在了一起。
但是你用MatLab打开txt之后会发现格式不太一样,如下:
类似这种按行分割好的文档。可以在这里全选-复制-新建txt-粘贴。这时候就可以查看readme.txt的说明(在label那个压缩包里,被和数据打包在了一起)
发现数据分别的意义如下:
File name
Number of bounding box
x1, y1, w, h, blur, expression, illumination, invalid, occlusion, pose
Number of bounding box
x1, y1, w, h, blur, expression, illumination, invalid, occlusion, pose
也就是第一行是文件夹,文件名
第二行是图中人脸的数量
再下面是人脸信息的参数。
x1, y1, w, h, 代表人脸框的位置(检测算法一般都要画个框框把人脸圈出来)
blur:是模糊度,分三档:0,清晰;1:一般般;2:人鬼难分
express:表达(什么鬼也没弄明白,反正我训这个用不着)
illumination:曝光,分正常和过曝
occlusion:遮挡,分三档。0,无遮挡;1,小遮挡;2,大遮挡;
invalid:(没弄明白)
pose:(疑似姿态?分典型和非典型姿态)
那么这里我需要的数据就是人脸框的坐标位置,作为我的目标label。我需要知道某张图片里有多少张人脸,每张人脸分别在什么位置。
这就需要写一个脚本来让图片和这些数据配对。然后就坐下码了一个(FILEDIR根据自己实际情况修改啊):
-
import re
-
import linecache
-
import os
-
# 本程序用于将widerface数据集中label部分分离出来并且重新保存
-
FILEDIR =
“E:\Python_Files\TryWiderFace\Dataset\labels\\”
-
file = open(FILEDIR+
‘wider_face_train_bbx_gt.txt’,
‘r’)
-
-
def count_lines(file):
-
lines_quantity =
0
-
while
True:
-
buffer = file.read(
1024 *
8192)
-
if
not buffer:
-
break
-
lines_quantity += buffer.count(
‘\n’)
-
file.close()
-
return lines_quantity
-
-
lines = count_lines(file)
-
-
for i
in range(lines):
-
line = linecache.getline(FILEDIR+
‘wider_face_train_bbx_gt.txt’,i)
-
if re.search(
‘jpg’, line):
-
position = line.index(
‘/’)
-
file_name = line[position +
1:
-5]
-
folder_name = line[:position]
-
print(file_name)
-
i +=
1
-
face_count = int(linecache.getline(FILEDIR+
‘wider_face_train_bbx_gt.txt’, i))
-
for j
in range(face_count):
-
box_line = linecache.getline(FILEDIR +
‘wider_face_train_bbx_gt.txt’, i+j+
1)
#x1, y1, w, h, x1,y1 为人脸框左上角的坐标
-
po_x1 = box_line.index(
’ ‘)
-
x1 = box_line[:po_x1]
-
po_y1 = box_line.index(
’ ‘, po_x1 +
1)
-
y1 = box_line[po_x1:po_y1]
-
po_w = box_line.index(
’ ‘, po_y1 +
1)
-
w = box_line[po_y1:po_w]
-
po_h = box_line.index(
’ ‘, po_w +
1)
-
h = box_line[po_w:po_h]
-
coordinates = x1 + y1 + w + h
-
# print(coordinates)
-
if
not(os.path.exists(FILEDIR +
“wider_face_train\\” + folder_name)):
-
os.makedirs(FILEDIR +
“wider_face_train\\” + folder_name)
-
with open(FILEDIR +
“wider_face_train\\”+ folder_name +
“\\” + file_name +
“.txt”,
‘a’)
as f:
-
f.write(coordinates +
“\n”)
-
i += i + j +
1
-
-
-
-
-
-
-
-
-
-