flowers.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import numpy as np
  2. from os.path import join
  3. from nabirds.utils import _MetaInfo
  4. from .base import BaseAnnotations, BBoxMixin
  5. class FLOWERS_Annotations(BaseAnnotations, BBoxMixin):
  6. name="FLOWERS"
  7. @property
  8. def meta(self):
  9. info = _MetaInfo(
  10. images_folder="images",
  11. images_file="images.txt",
  12. labels_file="labels.txt",
  13. split_file="tr_ID.txt",
  14. bounding_boxes="bounding_boxes.txt",
  15. bounding_box_dtype=np.dtype([(v, np.int32) for v in "xywh"]),
  16. parts_file=join("parts", "part_locs.txt"),
  17. part_names_file=join("parts", "parts.txt"),
  18. )
  19. info.structure = [
  20. [info.images_file, "_images"],
  21. [info.labels_file, "labels"],
  22. [info.split_file, "_split"],
  23. [info.bounding_boxes, "_bounding_boxes"],
  24. [info.parts_file, "_part_locs"],
  25. [info.part_names_file, "_part_names"],
  26. ]
  27. return info
  28. def __init__(self, *args, **kwargs):
  29. super(FLOWERS_Annotations, self).__init__(*args, **kwargs)
  30. # set labels from [1..200] to [0..199]
  31. self.labels -= 1
  32. def _load_parts(self):
  33. self.part_names = {}
  34. # load only if present
  35. if self.has_parts:
  36. super(FLOWERS_Annotations, self)._load_parts()
  37. self._load_bounding_boxes()
  38. def parts(self, *args, **kwargs):
  39. if self.has_parts:
  40. return super(FLOWERS_Annotations, self).parts(*args, **kwargs)
  41. return None