Augment an image by a list of augmentors
| 217 | |
| 218 | |
| 219 | class AugmentorList(ImageAugmentor): |
| 220 | """ |
| 221 | Augment an image by a list of augmentors |
| 222 | """ |
| 223 | |
| 224 | def __init__(self, augmentors): |
| 225 | """ |
| 226 | Args: |
| 227 | augmentors (list): list of :class:`ImageAugmentor` instance to be applied. |
| 228 | """ |
| 229 | assert isinstance(augmentors, (list, tuple)), augmentors |
| 230 | self.augmentors = augmentors |
| 231 | super(AugmentorList, self).__init__() |
| 232 | |
| 233 | def reset_state(self): |
| 234 | """ Will reset state of each augmentor """ |
| 235 | super(AugmentorList, self).reset_state() |
| 236 | for a in self.augmentors: |
| 237 | a.reset_state() |
| 238 | |
| 239 | def get_transform(self, img): |
| 240 | check_dtype(img) |
| 241 | assert img.ndim in [2, 3], img.ndim |
| 242 | |
| 243 | from .transform import LazyTransform, TransformList |
| 244 | # The next augmentor requires the previous one to finish. |
| 245 | # So we have to use LazyTransform |
| 246 | tfms = [] |
| 247 | for idx, a in enumerate(self.augmentors): |
| 248 | if idx == 0: |
| 249 | t = a.get_transform(img) |
| 250 | else: |
| 251 | t = LazyTransform(a.get_transform) |
| 252 | |
| 253 | if isinstance(t, TransformList): |
| 254 | tfms.extend(t.tfms) |
| 255 | else: |
| 256 | tfms.append(t) |
| 257 | return TransformList(tfms) |
| 258 | |
| 259 | def __str__(self): |
| 260 | repr_each_aug = ",\n".join([" " + repr(x) for x in self.augmentors]) |
| 261 | return "imgaug.AugmentorList([\n{}])".format(repr_each_aug) |
| 262 | |
| 263 | __repr__ = __str__ |
| 264 | |
| 265 | |
| 266 | Augmentor = ImageAugmentor |
no outgoing calls