You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

wider_face.py 1.5 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import os.path as osp
  3. import xml.etree.ElementTree as ET
  4. import mmcv
  5. from .builder import DATASETS
  6. from .xml_style import XMLDataset
  7. @DATASETS.register_module()
  8. class WIDERFaceDataset(XMLDataset):
  9. """Reader for the WIDER Face dataset in PASCAL VOC format.
  10. Conversion scripts can be found in
  11. https://github.com/sovrasov/wider-face-pascal-voc-annotations
  12. """
  13. CLASSES = ('face', )
  14. def __init__(self, **kwargs):
  15. super(WIDERFaceDataset, self).__init__(**kwargs)
  16. def load_annotations(self, ann_file):
  17. """Load annotation from WIDERFace XML style annotation file.
  18. Args:
  19. ann_file (str): Path of XML file.
  20. Returns:
  21. list[dict]: Annotation info from XML file.
  22. """
  23. data_infos = []
  24. img_ids = mmcv.list_from_file(ann_file)
  25. for img_id in img_ids:
  26. filename = f'{img_id}.jpg'
  27. xml_path = osp.join(self.img_prefix, 'Annotations',
  28. f'{img_id}.xml')
  29. tree = ET.parse(xml_path)
  30. root = tree.getroot()
  31. size = root.find('size')
  32. width = int(size.find('width').text)
  33. height = int(size.find('height').text)
  34. folder = root.find('folder').text
  35. data_infos.append(
  36. dict(
  37. id=img_id,
  38. filename=osp.join(folder, filename),
  39. width=width,
  40. height=height))
  41. return data_infos

No Description

Contributors (3)