|
@@ -1,11 +1,21 @@
|
|
|
+import abc
|
|
|
import numpy as np
|
|
|
|
|
|
from os.path import join
|
|
|
|
|
|
-from cvdatasets.dataset.mixins.base import BaseMixin
|
|
|
from cvdatasets.dataset.image import ImageWrapper
|
|
|
+from cvdatasets.dataset.mixins.base import BaseMixin
|
|
|
+
|
|
|
+class BaseReadMixin(BaseMixin):
|
|
|
+
|
|
|
+ def get_example(self, i):
|
|
|
+ return self.image_wrapped(i)
|
|
|
+
|
|
|
+ @abc.abstractmethod
|
|
|
+ def image_wrapped(self, i) -> ImageWrapper:
|
|
|
+ pass
|
|
|
|
|
|
-class AnnotationsReadMixin(BaseMixin):
|
|
|
+class AnnotationsReadMixin(BaseReadMixin):
|
|
|
|
|
|
def __init__(self, *, uuids, annotations, part_rescale_size=None, center_cropped=True, mode="RGB"):
|
|
|
super(AnnotationsReadMixin, self).__init__()
|
|
@@ -21,10 +31,7 @@ class AnnotationsReadMixin(BaseMixin):
|
|
|
def _get(self, method, i):
|
|
|
return getattr(self._annot, method)(self.uuids[i])
|
|
|
|
|
|
- def get_example(self, i):
|
|
|
- # res = super(AnnotationsReadMixin, self).get_example(i)
|
|
|
- # # if the super class returns something, then the class inheritance is wrong
|
|
|
- # assert res is None, "AnnotationsReadMixin should be the last class in the hierarchy!"
|
|
|
+ def image_wrapped(self, i):
|
|
|
|
|
|
methods = ["image", "parts", "label"]
|
|
|
im_path, parts, label = [self._get(m, i) for m in methods]
|
|
@@ -44,7 +51,7 @@ class AnnotationsReadMixin(BaseMixin):
|
|
|
return np.array([self._get("label", i) for i in range(len(self))])
|
|
|
|
|
|
|
|
|
-class ImageListReadingMixin(BaseMixin):
|
|
|
+class ImageListReadingMixin(BaseReadMixin):
|
|
|
|
|
|
def __init__(self, *, pairs, root="."):
|
|
|
super(ImageListReadingMixin, self).__init__()
|
|
@@ -59,7 +66,7 @@ class ImageListReadingMixin(BaseMixin):
|
|
|
def __len__(self):
|
|
|
return len(self._pairs)
|
|
|
|
|
|
- def get_example(self, i):
|
|
|
+ def image_wrapped(self, i):
|
|
|
im_file, label = self._pairs[i]
|
|
|
im_path = join(self._root, im_file)
|
|
|
|