Apply image augmentors on 1 image component.
| 83 | |
| 84 | |
| 85 | class AugmentImageComponent(MapDataComponent): |
| 86 | """ |
| 87 | Apply image augmentors on 1 image component. |
| 88 | """ |
| 89 | |
| 90 | def __init__(self, ds, augmentors, index=0, copy=True, catch_exceptions=False): |
| 91 | """ |
| 92 | Args: |
| 93 | ds (DataFlow): input DataFlow. |
| 94 | augmentors (AugmentorList): a list of :class:`imgaug.ImageAugmentor` to be applied in order. |
| 95 | index (int or str): the index or key of the image component to be augmented in the datapoint. |
| 96 | copy (bool): Some augmentors modify the input images. When copy is |
| 97 | True, a copy will be made before any augmentors are applied, |
| 98 | to keep the original images not modified. |
| 99 | Turn it off to save time when you know it's OK. |
| 100 | catch_exceptions (bool): when set to True, will catch |
| 101 | all exceptions and only warn you when there are too many (>100). |
| 102 | Can be used to ignore occasion errors in data. |
| 103 | """ |
| 104 | if isinstance(augmentors, AugmentorList): |
| 105 | self.augs = augmentors |
| 106 | else: |
| 107 | self.augs = AugmentorList(augmentors) |
| 108 | self._copy = copy |
| 109 | |
| 110 | self._exception_handler = ExceptionHandler(catch_exceptions) |
| 111 | super(AugmentImageComponent, self).__init__(ds, self._aug_mapper, index) |
| 112 | |
| 113 | def reset_state(self): |
| 114 | self.ds.reset_state() |
| 115 | self.augs.reset_state() |
| 116 | |
| 117 | def _aug_mapper(self, x): |
| 118 | check_dtype(x) |
| 119 | with self._exception_handler.catch(): |
| 120 | if self._copy: |
| 121 | x = copy_mod.deepcopy(x) |
| 122 | return self.augs.augment(x) |
| 123 | |
| 124 | |
| 125 | class AugmentImageCoordinates(MapData): |
no outgoing calls
no test coverage detected