hed.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import numpy as np
  2. import simplejson as json
  3. from os.path import join
  4. from nabirds.utils import _MetaInfo
  5. from .base import BaseAnnotations, BBoxMixin
  6. class HED_Annotations(BaseAnnotations, BBoxMixin):
  7. name="HED"
  8. @property
  9. def meta(self):
  10. info = _MetaInfo(
  11. images_folder="images",
  12. images_file="images.txt",
  13. labels_file="labels.txt",
  14. split_file="tr_ID.txt",
  15. # fake bounding boxes: the whole image
  16. bounding_box_dtype=np.dtype([(v, np.int32) for v in "xywh"]),
  17. parts_file=join("parts", "part_locs.txt"),
  18. part_names_file=join("parts", "parts.txt"),
  19. )
  20. info.structure = [
  21. [info.images_file, "_images"],
  22. [info.labels_file, "labels"],
  23. [info.split_file, "_split"],
  24. ]
  25. return info
  26. def parts(self, *args, **kwargs):
  27. if self.has_parts:
  28. return super(HED_Annotations, self).parts(*args, **kwargs)
  29. return None
  30. def _load_bounding_boxes(self):
  31. self.bounding_boxes = np.zeros(len(self.uuids),
  32. dtype=self.meta.bounding_box_dtype)
  33. for i in range(len(self.uuids)):
  34. self.bounding_boxes[i]["w"] = 224
  35. self.bounding_boxes[i]["h"] = 224
  36. def _load_parts(self):
  37. self.part_names = {}
  38. # load only if present
  39. if self.has_parts:
  40. super(HED_Annotations, self)._load_parts()
  41. self._load_bounding_boxes()