wider_face.py 1.27 KB
Newer Older
1
2
3
4
5
import os.path as osp
import xml.etree.ElementTree as ET

import mmcv

6
from .registry import DATASETS
7
8
9
from .xml_style import XMLDataset


10
@DATASETS.register_module
11
12
13
14
15
16
class WIDERFaceDataset(XMLDataset):
    """
    Reader for the WIDER Face dataset in PASCAL VOC format.
    Conversion scripts can be found in
    https://github.com/sovrasov/wider-face-pascal-voc-annotations
    """
17
    CLASSES = ('face', )
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

    def __init__(self, **kwargs):
        super(WIDERFaceDataset, self).__init__(**kwargs)

    def load_annotations(self, ann_file):
        img_infos = []
        img_ids = mmcv.list_from_file(ann_file)
        for img_id in img_ids:
            filename = '{}.jpg'.format(img_id)
            xml_path = osp.join(self.img_prefix, 'Annotations',
                                '{}.xml'.format(img_id))
            tree = ET.parse(xml_path)
            root = tree.getroot()
            size = root.find('size')
            width = int(size.find('width').text)
            height = int(size.find('height').text)
            folder = root.find('folder').text
            img_infos.append(
36
37
38
39
40
                dict(
                    id=img_id,
                    filename=osp.join(folder, filename),
                    width=width,
                    height=height))
41
42

        return img_infos