nab.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import numpy as np
  2. from os.path import join
  3. from nabirds.utils import _MetaInfo
  4. from .base import BaseAnnotations
  5. class NAB_Annotations(BaseAnnotations):
  6. name="NABirds"
  7. @property
  8. def meta(self):
  9. info = _MetaInfo(
  10. images_folder="images",
  11. images_file="images.txt",
  12. labels_file="labels.txt",
  13. hierarchy_file="hierarchy.txt",
  14. split_file="train_test_split.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.hierarchy_file, "hierarchy"],
  23. [info.split_file, "_split"],
  24. [info.parts_file, "_part_locs"],
  25. [info.part_names_file, "_part_names"],
  26. ]
  27. return info
  28. def _load_split(self):
  29. assert self._split is not None, "Train-test split was not loaded!"
  30. uuid_to_split = {uuid: int(split) for uuid, split in [i.split() for i in self._split]}
  31. self.train_split = np.array([uuid_to_split[uuid] for uuid in self.uuids], dtype=bool)
  32. self.test_split = np.logical_not(self.train_split)