[Face Detection] wider_face data set format data transfer voc

wider_face Data Format Description

Download Link: http://shuoyang1213.me/WIDERFACE/index.html
Description: wider_face is selected out of the real scene. Which label only the face region of a rectangular frame , no human face aligned dimension

code

import cv2
import os
xml_head = '''<annotation>
    <folder>VOC2007</folder>
    <!--文件名-->
    <filename>{}</filename>.
    <source>
        <database>The VOC2007 Database</database>
        <annotation>PASCAL VOC2007</annotation>
        <image>flickr</image>
        <flickrid>325991873</flickrid>
    </source>
    <owner>
        <flickrid>null</flickrid>
        <name>null</name>
    </owner>    
    <size>
        <width>{}</width>
        <height>{}</height>
        <depth>{}</depth>
    </size>
    <segmented>0</segmented>
    '''
xml_obj = '''
    <object>        
        <name>{}</name>
        <pose>Rear</pose>
        <!--是否被裁减,0表示完整,1表示不完整-->
        <truncated>0</truncated>
        <!--是否容易识别,0表示容易,1表示困难-->
        <difficult>0</difficult>
        <!--bounding box的四个坐标-->
        <bndbox>
            <xmin>{}</xmin>
            <ymin>{}</ymin>
            <xmax>{}</xmax>
            <ymax>{}</ymax>
        </bndbox>
    </object>
    '''
xml_end = '''
</annotation>'''
 

txt_path = '/home/yangna/data/WIDER_FACE/wider_face_split/wider_face_train_bbx_gt.txt'
imgs_path = '/home/yangna/data/WIDER_FACE/WIDER_train/images/'
labels = 'face'                #label for datasets
 
cnt = 0
cnt_line = 0
with open(txt_path,'r') as train_list:
    lst = train_list.readlines()
    while (cnt_line < len(lst)):
        img_name = lst[cnt_line]
        if '.jpg' in img_name:
            per_nums = int(lst[cnt_line + 1].rstrip())
            per_lines = lst[cnt_line + 2:cnt_line+2+per_nums]
            cnt_line = cnt_line + per_nums + 2

            if per_nums == 0:
                cnt_line += 1
                continue

            # process one image
            img_path = imgs_path + img_name.rstrip()
            img = cv2.imread(img_path)
            img_h,img_w = img.shape[0],img.shape[1]
            head = xml_head.format(str(img_path),str(img_w),str(img_h),3)

            obj = ''

            out_txt_name = './data/wider_face/voc/' + img_path.split('/')[-1].replace('.jpg', '.xml')
            for f in per_lines:
                f = [int(x) for x in f.rstrip().split(' ')]
                if f[2]*f[3] < 10:
                    continue
                xmin = str(f[0])
                ymin = str(f[1])
                xmax = str(f[0] + f[2])
                ymax = str(f[1] + f[3])

                obj += xml_obj.format(labels,xmin,ymin,xmax,ymax)
            
            if obj == '':
                continue

            with open(out_txt_name,'w') as f_xml:
                f_xml.write(head+obj+xml_end)
            cnt += 1
            print(cnt)
            if cnt == 279:
                temp = 1

result
Here Insert Picture Description
post-processing xml Download
Baidu cloud link , extraction code: wrk3


wider_face Annotated five key points

Download Link: https://pan.baidu.com/s/1Laby0EctfuJGgGMgRRgykA
data format:

# 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
# 0--Parade/0_Parade_Parade_0_904.jpg
361 98 263 339 424.143 251.656 0.0 547.134 232.571 0.0 494.121 325.875 0.0 453.83 368.286 0.0 561.978 342.839 0.0 0.89
# 0--Parade/0_Parade_marchingband_1_799.jpg
78 221 7 8 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 0.2

Format Face rectangular frame (4 values), 5 key points (5 × 3 values), a confidence value


reference

  1. https://blog.csdn.net/angelbeats11/article/details/88427359
Published 244 original articles · won praise 147 · views 280 000 +

Guess you like

Origin blog.csdn.net/u011622208/article/details/104038213