dataset.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import numpy as np
  2. import abc
  3. from chainer_addons.dataset import AugmentationMixin
  4. from chainer_addons.dataset import PreprocessMixin
  5. from cvdatasets.dataset import AnnotationsReadMixin
  6. from cvdatasets.dataset import RevealedPartMixin
  7. from cvdatasets.dataset import IteratorMixin
  8. class _pre_augmentation_mixin(abc.ABC):
  9. """ This mixin discards the parts from the ImageWrapper object
  10. and shifts the labels
  11. """
  12. label_shift = 1
  13. def get_example(self, i):
  14. im_obj = super(_pre_augmentation_mixin, self).get_example(i)
  15. im, parts, lab = im_obj.as_tuple()
  16. return im, lab + self.label_shift
  17. class _base_mixin(abc.ABC):
  18. """ This mixin converts images,that are in range
  19. [0..1] to the range [-1..1]
  20. """
  21. def get_example(self, i):
  22. im, lab = super(_base_mixin, self).get_example(i)
  23. if isinstance(im, list):
  24. im = np.array(im)
  25. return im * 2 - 1, lab
  26. class BaseDataset(_base_mixin,
  27. # augmentation and preprocessing
  28. AugmentationMixin, PreprocessMixin,
  29. _pre_augmentation_mixin,
  30. # random uniform region selection
  31. RevealedPartMixin,
  32. # reads image
  33. AnnotationsReadMixin,
  34. IteratorMixin):
  35. """Commonly used dataset constellation"""